ORACLE 流程控制语句

一、选择语句

1、if...then 语句

示例:

if temp1.order_type='NORMAL_ASN' then
      insert into baan.twhinh905201@erp(t$sorn,t$spon,t$orno,t$pono,t$qrcr,t$cwar,t$item,
      t$stat,t$whid,t$prdt,t$refcntd,t$refcntu) values
      (temp1.shdh,temp1.line_no,temp1.order_code,temp1.order_line_no,temp1.rec_qty,temp1.inv_loc,
      temp1.itemcode,' ',temp1.id-4500000000,sysdate-1/3,0,0);
      commit;    
      end if;

2、if...then...else 语句

示例:

if order_rec_01.t5 like '8%'
      then m1 := 'Y';
        else m1 := 'N';
          end if;

3、if...then...elsif 语句

示例:

if re_task_01.t2='A-01020101' then
    m1 := '10001';
    elsif re_task_01.t2='A-01020201' then
    m1 := '10004';
    elsif re_task_01.t2='A-01020102' then
    m1 := '10005';
    else 
      m1 := '10003';
      end if;

4、case 语句

示例:

case when re_m_1.m3  in ( 'FINISHED','WORKING') then
     m15 := m15+1;
     when re_m_1.m3 ='OPEN'then 
       m11 := m11+1;
       if re_m_1.m2 <= 3 then
         m12 := m12+1;
         elsif re_m_1.m2 >= 3 and re_m_1.m2 <= 5 then
           m13 := m13+1;
           else  
             m14 := m14+1;
         end if;
     end case;

二、循环语句

1、loop 语句

示例:

declare
sum_i int:=0;
i int :=0;
begin
 loop
  i:=i+1;
  sum_i:=sum_i+i;
  exit when i=100;
 end loop;
dbms_output.put_line('1~100的和为:'||sum_i);
end;

2、while语句

示例:

declare
sum_i int:=0;
i int :=0;
begin
 while i<=99 loop
  i:=i+1;
  sum_i:=sum_i+i;
 end loop;
dbms_output.put_line('1~100的和为:'||sum_i);
end;

3、for 语句

示例:

declare
sum_i int:=0;
begin
 for i reverse 1..100 loop
   if mod(i,2)=0 then
   sum_i:=sum_i+i;
   end if;
 end loop;
dbms_output.put_line('1~100的偶数之和为:'||sum_i);
end;

4、goto 语句

goto 语句的语法是:

goto label;

这是个无条件转向语句。当执行GOTO语句时,控制程序会立即转到由标签标识的语句。其中,label是在PL/SQL中定义的符号。标签使用双箭头括号(<<>>)括起来的。

示例:

...--程序其他部分
<<goto_mark>>  --定义了一个转向标签
...--程序其他部分
if i>100 then
   goto goto_mark; --如果条件成立则转向标签继续执行
...--程序其他部分


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值