Oracle使用手册(二)---流程控制
--1. if..then..end if

set serveroutput on
declare
i integer:=60;
j integer:=30;
begin
if i>=j then
dbms_output.put_line(j);
end if;
end;

--2.if嵌套条件控制

if 条件1 then
if 条件2 then
语句段1;
else
语句段2;
end if;
else
语句段3;
end if;

--3.循环控制
--loop
exit
end loop

set serveroutput on
declare
i integer:=10;
j integer:=20;
w integer:=10;
begin
loop
i:=i+1;
if(j=i)then
begin
dbms_output.put_line('我哥俩现在一样多了.'|| to_char(j)) ;
exit;
end;
else
w:=w-1;
end if;
end loop;
dbms_output.put_line('w还剩多少: '|| to_char(w)) ;
end;
--4.while
loop
end loop
while 条件 loop
执行语句段;
end loop;

--5.for
in
loop
end
for 循环变量 in[reverse] 循环下界
循环上界 loop
循环处理语句;
end loop;

set serveroutput on
declare
i int:=0;
j int:=100;
begin
for j in 1..6 loop
i:=i+1;
end loop;
dbms_output.put_line('循环次数: '|| to_char(i)) ;
end;

--5.事务处理
--在pl/sql中,可以使用三个事务处理控制命令.
--在PL/SQL程序打开自动提交功能。这样每次执行PL/SQL程序都会自动进行事务提交。
--语句: set auto on;
--相应的,取消自动提交功能的PL/SQL程序为:
--set auto off;

--commit,rollback,savepoint
--select * from student;
--commit;
--delete from student;
--rollback; --回滚刚才的delete 操作.
--select * from student;

savepoint insertpoint;
insert into student(sid,sname) values(900,'mrfu');
--创建保存点 : savepoint 保存点名;
select sid,sname from student where sid=900;
rollback to insertpoint; --回滚保存点: rollbacd to 保存点名;
--dbms_output.put_line('回滚保存点') ;
select sid,sname from student where sid=900;
































































































【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 如何使用 Uni-app 实现视频聊天(源码,支持安卓、iOS)
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)