一、选择语句
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; --如果条件成立则转向标签继续执行
...--程序其他部分