SQL/Oracle
[Oracle] 조건문
에띠
2022. 6. 16. 09:33
728x90
if문
if 조건식1 then
조건식1이 true일 때 실행할 문장;
elsif 조건식2 then
조건식2가 true일 때 실행할 문장;
elsif 조건식3 then
조건식3이 true일 때 실행할 문장;
...
else
모든 조건식이 false일 때 실행할 문장;
end if;
declare
avg_score number := 85;
begin
if avg_score >= 90 then
dbms_output.put_line('A학점');
elsif avg_score >= 80 then
dbms_output.put_line('B학점');
elsif avg_score >= 70 then
dbms_output.put_line('C학점');
elsif avg_score >= 60 then
dbms_output.put_line('D학점');
else
dbms_output.put_line('F학점');
end if;
end;
case문
case when 조건식1 then
조건식1이 true인 경우 실행할 문장;
when 조건식2 then
조건식2가 true인 경우 실행할 문장;
when 조건식3 then
조건식3이 true인 경우 실행할 문장;
...
else
모든 조건이 false인 경우 실행할 문장;
end case;
declare
avg_score number := 85;
begin
case when avg_score >= 90 then
dbms_output.put_line('A학점');
when avg_score >= 80 then
dbms_output.put_line('B학점');
when avg_score >= 70 then
dbms_output.put_line('C학점');
when avg_score >= 60 then
dbms_output.put_line('D학점');
else
dbms_output.put_line('F학점');
end case;
end;
728x90