• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
thankgoodness
博客园    首页    新随笔    联系   管理    订阅  订阅

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.循环控制 
--loopexitend 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.whileloopend loop
while 条件 loop
   执行语句段;
end loop;   

--5.forinloopend
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;
posted @ 2008-04-30 09:43  宇晨  阅读(220)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3