if (分3類) java if (條件) { .... } pl/sql if 條件 then ..... end if; ---------------- select * from tt3 select age from tt3 where id=1 ---------------------- declare myage tt3.age%type; begin select age into myage from tt3 where id=1; --if (age>=19) { -- System.out.println("成年人"); --} if myage>=19 then dbms_output.put_line('成年人'); end if; end; --------------------------- if else java if(條件){ ... }else{ ... } --pl/sql if 條件 then else end if; declare myage tt3.age%type; begin select age into myage from tt3 where id=1; if myage>=18 then dbms_output.put_line('成年人'); else dbms_output.put_line('未成年人'); end if; end; update tt3 set age=19 where id=1 commit; ------------------------- if else if else java if(條件1){ .... }else if(條件2) { .... }else { } --pl/sql if 條件1 then elsif 條件2 then else end if; ------------------ declare myage tt3.age%type; begin select age into myage from tt3 where id=1; if myage>=50 then dbms_output.put_line('中老年人'); elsif myage>=18 then dbms_output.put_line('成年的年青人'); else dbms_output.put_line('未成年人'); end if; end; ----------------- case [selector] when 1 then 語句1; when 2 then 語句2; when 3 then 語句3; else 語句4 end case; declare my_user tt3%rowtype; begin select * into my_user from tt3 where id=1; -- my_user.city case my_user.city when '北京' then dbms_output.put_line('長城很好玩'); when '上海' then dbms_output.put_line('浦東很好玩'); when '珠海' then dbms_output.put_line('南方IT最好玩'); else dbms_output.put_line('不如到珠海南方玩一下'); end case; end; update tt3 set city='上海' where id=1 commit; case [selector] when 1 then '返回結果1'; when 2 then '返回結果2'; when 3 then '返回結果3'; else '返回結果4' end case; --------------- select * from tt3 where id=1; -------------- declare my_user tt3%rowtype; show_message varchar2(200); begin select * into my_user from tt3 where id=1; -- my_user.city show_message:= case my_user.city when '北京' then '長城' when '上海' then '浦東' when '珠海' then '南方' else '珠海南方' end; dbms_output.put_line(my_user.user_name||'('||my_user.city||')'||show_message||'很好玩'); end; ---------- declare my_user tt3%rowtype; show_message varchar2(200); begin select * into my_user from tt3 where id=1; show_message:= case when my_user.age>50 then '來自於'||my_user.city|| my_user.user_name ||'是一個中老年年人' when my_user.age>=18 then my_user.user_name || '是一個成年人' else my_user.user_name || '是個未成年人,'||'可以到'||my_user.city||'找她' end; dbms_output.put_line(show_message); end; update tt3 set age=12 where id=1 commit;