------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 撤销有关问题
- win7x64上安装oraclex64版本后,plsql Developer无法登录的有关问题
- vfp6.0 do while 循环 loop 如何一下退出了就
- 有人知道while loop 和 do-while loop的区别么?
- 为什么出现break outside switch or loop?
- 出现break outside switch or loop
- [求助] loop 语句怎样用啊?请指点
- html <loop name="list_destination"> 啥意思解决思路
- Why won't my HTML5 audio loop
- {dede:loop}的有关问题
- 不要忽略任何一个异常提示,更要找到原因linked websocket controlling loop crashed with reason: kille
- Extjs4-退出store.each() unlabelled break must be inside loop or switch
- while loop, checking 問題,该如何处理
- 如何用 PLSQL Developer 创建新的oracle数据库
- PLSQL 批量安插更新
- plsql Developer工具使用异常
- eclipse 错误Unhandled event loop exception 源头解决方法
- myeclipse点击部署旋钮时候 Unhandled event loop exception,
- 关于eclipse的 Unhandled event loop exception PermGen space 有关问题
- Eclipse发生错误Unhandled event loop exception No more handles
- Eclipse编辑java文件报Unhandled event loop exception异常的解决方法
- Eclipse中按crtl键卡死后报Unhandled event loop exception Java heap space解决办法
- Eclipse 出现”unhandled event loop exception permgen space“异常
- Eclipse CDT 解决 "for loop initial declaration used outside C99 mode" 异常
- plsql 与 sqlplus 查询结果不一致,该怎么处理
- plsql oracle脚本,导出数据条目不一样?解决思路
- plsql 是不是有辦法將 Schema 的 Table 清單 拉出來成一個視窗