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;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)