------example 1: loops with IF statement-----------set serveroutput ondeclare v_counter binary_integer := 0; begin loop --increment loop counter by one v_counter := v_counter + 1; DBMS_OUTPUT.put_line('v_counter = '||v_counter); --if exit condition yields true exit the loop if v_counter = 5 then -- the same as : exit when v_counter = 5; exit; end if; end loop; --control resumes here dbms_output.put_line('Done...'); end; ------example 2: loops with EXIT WHEN conditions-----------set serveroutput ondeclare v_course course.courser_no%type :430; v_instructor_id instructor.instructor_id%type :102; v_sec_num section.section_no%type :=0;begin loop --increment section number by one v_sec_num := v_sec_num + 1; insert into section (section_no,course_no,section_no,instructor_id, created_date, created_by,modified_date, modified_by) values (section_id_seq.nextval,v_course,v_sec_num, v_instructor_id,SYSDATE,USER,sysdate,user); --if number of section added is four exit the loop exit when v_sec_num = 4; end loop; --control resumes here commit;end;--------exiample 3: loops with WHILE Loops condition---------set serveroutput on declare c_counter binary_integer := 1; v_sum number :=0; begin while v_counter <= 10 loop v_sum := v_sum + v_counter; dbms_output.put_line('current sum is: '||v_sum); -- increment loop counter by one v_counter := v_counter + 1; end loop; -- control resumes here dbms_output.put_line('the sum of integers between 1 '|| 'and 10 is: '||v_sum);end;---------example 4: loop with For Loops----------set serveroutput ondeclare v_factorial number := 1;begin --the loop counter is defined implicitly by the loop --Therefore,before the loop ,the loop counter is undefined and has no value; for v_counter in 1..10 loop v_factorial := v_factorial * v_counter; end loop; --countrol resume here dbms_output.put_line('factorial of ten is :'||v_factorial);end;
详细解决方案
plsql学习:loop施用
热度:93 发布时间:2016-05-05 14:34:12.0
相关解决方案
- plsql 里怎么判断密码长度大于等于6
- java-plsql 有关问题
- PlSql 如何查询一张表使得orderID相同就合并那几行数据的某一行数据
- PLSQL 撤销有关问题
- html <loop name="list_destination"> 啥意思解决思路
- {dede:loop}的有关问题
- 不要忽略任何一个异常提示,更要找到原因linked websocket controlling loop crashed with reason: kille
- Extjs4-退出store.each() unlabelled break must be inside loop or switch
- 如何用 PLSQL Developer 创建新的oracle数据库
- PLSQL 批量安插更新
- eclipse 错误Unhandled event loop exception 源头解决方法
- myeclipse点击部署旋钮时候 Unhandled event loop exception,
- 关于eclipse的 Unhandled event loop exception PermGen space 有关问题
- Eclipse CDT 解决 "for loop initial declaration used outside C99 mode" 异常
- plsql 与 sqlplus 查询结果不一致,该怎么处理
- plsql oracle脚本,导出数据条目不一样?解决思路
- plsql 是不是有辦法將 Schema 的 Table 清單 拉出來成一個視窗
- PLSQL 新计算机装了 11g, 开启后找不到可以连接的资料库清单><
- 为啥监听没有启动,plsql dev客户端依然可以连接数据库呢
- 为何监听没有启动,plsql dev客户端依然可以连接数据库呢
- PLSQL 登录oracle数据库出现 “无法解析指定的连接标识符”异常
- plsql 客户端连接远程 oracle 服务查询卡住,该怎么处理
- plsql,该如何处理
- Win7 64 安装oracle11g plsql 配置完后查询数据中文显示乱码,该怎么处理
- 求大神 PLSQL 使用,该怎么处理
- plsql developer 到底如何显示dbms_output
- plsql 8.0怎么在windows server 2008下连64bit 的Oracle 11g client
- plsql 联接本地oracle连接不上 昨天还好使
- PLSQL 查询乱码有关问题
- plsql 没法弹出数据表对应的字段