oracle for in 学习

oracle for  in 是对于进行循环的数据处理时比较方便的

因为我们平时的操作经常会碰到进行循环的数据操作

以下为建立的例子

1.

begin

for item in 2..10 loop

 dbms_output.put_line('the reuslt is '||item);
end loop;

end;

输出的结果如下:

the reuslt is 2
the reuslt is 3
the reuslt is 4
the reuslt is 5
the reuslt is 6
the reuslt is 7
the reuslt is 8
the reuslt is 9
the reuslt is 10

2. 进行数据库相关的操作

创建的表如下:

 CREATE TABLE "APPSERVERUSER"."FIRSTCLASS"
   ( "ID" VARCHAR2(20 BYTE),
 "NAME" VARCHAR2(20 BYTE),
 "USERID" VARCHAR2(20 BYTE)
   )

进行的for loop 循环的操作如下:

begin

begin
for i in (select id from firstclass) loop 
    dbms_output.put_line(i.id);
end loop;
end;

注意此时的i 类似于oracle 的record 即一条记录

所以我们在使用的时候应该是:i.id

操作的输出结果如下:

the firstclass id is :1
the firstclass id is :2
the firstclass id is :3
the firstclass id is :4
the firstclass id is :5

灵活的使用操作语句对于我们的日常操作可以提供很多便捷的方式。

 

 

 

end; 

posted on   荣锋亮  阅读(2264)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示