2 if case when和迴圈語句

2021-08-03 08:39:30 字數 1792 閱讀 1357

一、if條件語句

set serverout on;  (//此句作用:在控制台輸出結果)

declare aj_count number;

begin

select count(*) into aj_count from tb_st_ajjbxx;

if aj_count> 10000 then

dbms_output.put_line('有' || aj_count || '個');

else

dbms_output.put_line('有' || aj_count || '個');

end if;

end;

二、case when

set serverout on;

declare aj_count number;

begin

select count(*) into aj_count from tb_st_ajjbxx;

case when aj_count <10000 then dbms_output.put_line('有aa' || aj_count || '個');

when aj_count >=10000 then dbms_output.put_line('有bb' || aj_count || '個');

end case;

end;

三、迴圈語句

(1)無條件迴圈 loop

set serverout on;

declare g_id number:=1;

losal number;

hisal number;

begin

loop

if(g_id>3) then exit;

end if;  (if then exit end if;   此處為loop迴圈必須的)

select   username,password into losal,hisal from t_user where id=g_id; 

dbms_output.put_line(g_id || '數值為' || losal || 'aaaa' || hisal);

g_id := g_id+1;

end loop;

end;

(2)while 迴圈

set serverout on;

declare g_id number:=1;

losal number;

hisal number;

begin

while g_id<3 loop

select username,password into losal,hisal from t_user where id=g_id; 

dbms_output.put_line(g_id || '數值為' || losal || 'bbb' || hisal);

g_id := g_id+1;

end loop;

end;

(3)for 迴圈

set serverout on;

declare losal number;

hisal number;

begin

for g_id in 1..4 loop

select username,password into losal,hisal from t_user where id=g_id; 

dbms_output.put_line(g_id || '數值為' || losal || 'bbb' || hisal);

end loop;

end;

python基礎知識 條件判斷語句和迴圈語句

條件判斷語句 最有名的if語句。可能會有零到多個elif部分,else是可選的。其中,elif 是 else if 的縮寫。if.elif.elif.序列用於代替其他語言中的 switch 或 case 語句。簡單的例子 height float input 請輸入身高 單位 公尺 weight f...

2 python的分支和迴圈

條件分支 if 條件 elif 條件 elif 條件 else and 與運算條件表示式 三元操作符 x if 條件 else y斷言 assert關鍵字 當這個關鍵字後邊的條件為假的時候,程式自動崩潰並丟擲assertionerror的異常。eg assert 3 4一般來說我們可以用ta在程式中...

2 判斷語句和迴圈語句

注意 混合運算時,優先順序順序為 高於 高於 為了避免歧義,建議使用 來處理運算子優先順序 並且,不同型別的數字在進行混合運算時,整數將會轉換成浮點數進行運算。shift enter 指標快速到下一行 如果某些條件滿足,才能做某件事情 條件不滿足時,則不能做,這就是所謂的判斷 如果 就 if 要判讀...