博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Oracle/PLSQL: FOR Loop 循环语句
阅读量:4197 次
发布时间:2019-05-26

本文共 1265 字,大约阅读时间需要 4 分钟。

Oracle/PLSQL: FOR Loop: 
 

Loops with PL/SQL: 
 


The syntax for the FOR Loop is: 

Sql代码  
  1. FOR loop_counter IN [REVERSE] lowest_number..highest_number  
  2. LOOP  
  3.      {.statements.}  
  4. END LOOP;  


You would use a FOR Loop when you want to execute the loop body a fixed number of times.




Let's take a look at an example.



Sql代码  
  1. FOR Lcntr IN 1..20  
  2. LOOP  
  3.      LCalc := Lcntr * 31;  
  4. END LOOP;  


This example will loop 20 times. The counter will start at 1 and end at 20.




The FOR Loop can also loop in reverse. For example:



Sql代码  
  1. FOR Lcntr IN REVERSE 1..15  
  2. LOOP  
  3.      LCalc := Lcntr * 31;  
  4. END LOOP;  


This example will loop 15 times. The counter will start at 15 and end at 1. (loops backwards)





oracle学习--循环语句:


 



On Cursor FOR Loops:


 





A Example:


Sql代码  
  1. CREATE OR REPLACE   
  2. procedure TEST_p(eq_id varchar,eq_id_new varchar,etp_no number) is  
  3.        v_eq_id varchar2(20) :=eq_id;  
  4.        v_eq_id_new varchar2(20) := eq_id_new;  
  5.        v_etp_no number:=etp_no;  
  6. begin  
  7.     for  vRows in (select AQD_SEQ_MD_ET_PROCEDURES.nextval as id,certify_yn,required_yn,tpr_no from AQD_MD_ET_PROCEDURES  where rownum <5)  
  8.     LOOP  
  9.         dbms_output.put_line(vRows.id);  
  10.         insert into test(id,col2,col3,col4) values(vRows.id,vRows.certify_yn,vRows.required_yn,vRows.tpr_no);  
  11.     END LOOP;  
  12. end TEST_p;  
  13.   
  14. create table TEst(  
  15. id  number(38),  
  16. col2 varchar2(1),  
  17. col3 varchar2(1),  
  18. col4 number(38)  
  19. )  

转载地址:http://xgzli.baihongyu.com/

你可能感兴趣的文章
ffmpeg 视频截图
查看>>
docker 服务器启动失败
查看>>
docker 拷贝文件失败
查看>>
ffmpeg 图片转视频
查看>>
docker 常用命令 (详细)
查看>>
ttc格式字体转化为ttf格式字体
查看>>
汇编库yasm安装与nasm安装
查看>>
x264编译错误
查看>>
ELKStack简介
查看>>
OpenGL各版本库的区别 glut glfw glew glad
查看>>
python 编程规范
查看>>
ffmpeg 带alpha透明层的视频编码
查看>>
error: ‘M_PI’ undeclared
查看>>
GLFW编译
查看>>
GLEW编译
查看>>
NVIDIA视频编码器 ffmpeg -h encoder=h264_nvenc
查看>>
emacsclient在命令行模式下不能输入中文
查看>>
无名师的GUI论 的解释
查看>>
添加定制的Edit Menu
查看>>
在UIMenuController出现的时候取得选中的数据
查看>>