oracle中的控制語句
1.條件語句
if *** then
else
***;
end if;
---------------------
if *** then
elsif *** then
***;
else
***;
end if;
---------------------
case
when *** then
***;
when *** then
***;
else
end case;
---------------------
case ***
when *** then
***;
when *** then
***;
else
end case;
---------------------
select student_name,
sum(case when subject='數學' then score else 0 end) 數學,
sum(case when subject='語文' then score else 0 end) 語文,
sum(case when subject='外語' then score else 0 end) 外語
from scores
group by student_name;
2.迴圈語句
【loop】
--exit when
declare
v_rlt number(8):=-3;
begin
<>
loop
dbms_output.put_line('v_rlt = '||v_rlt);
v_rlt:=v_rlt+1;
exit fst_loop when v_rlt > 3;
end loop;
dbms_output.put_line('loop迴圈已經結束!');
end;
--結果
v_rlt = -3
v_rlt = -2
v_rlt = -1
v_rlt = 0
v_rlt = 1
v_rlt = 2
v_rlt = 3
loop迴圈已經結束!
--if exit
declare
v_rlt number(8):=-3;
begin
<>
loop
dbms_output.put_line('v_rlt = '||v_rlt);
v_rlt:=v_rlt+1;
if v_rlt > 3 then
dbms_output.put_line('變數的值已經大於3,當前值為'||v_rlt);
exit fst_loop;
end if;
end loop fst_loop;
dbms_output.put_line('loop迴圈已經結束!');
end;
【while...loop】
--while...loop
declare
v_rlt number(8):=-3;
begin
<>
while(v_rlt < 4)
loop
dbms_output.put_line('v_rlt = '||v_rlt);
v_rlt:=v_rlt+1;
end loop while_loop;
dbms_output.put_line('while迴圈已經結束!');
end;
【for...loop】
--for..loop
begin
for v_rlt in -3..3 loop
dbms_output.put_line('v_rlt = '||v_rlt);
end loop;
dbms_output.put_line('for迴圈已經結束!');
end;
Oracle 條件控制語句
pl sql有3種型別的條件控制語句 if語句 elsif語句 case語句 1.if語句 if then語句 語法格式 if condition then statement endif if then else語句 語法格式 if condition then statement1 else s...
Oracle中的控制語句
set serverout on declare employee number number begin select count into employee count from employees where employee age 30 if employee count 10 then ...
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...