Oracle_19流程控制语句

不小心删了,看别人的


--流程控制语句
--if
--注意elsif的写法
declare
v_empno emp.empno%type;
v_sal emp.sal%type;
v_comments varchar2(40);

begin
v_empno:=7369;
select sal into v_sal from emp where empno=v_empno;
if v_sal<1500 then
v_comments:='too low';
elsif v_sal<3000 then
v_comments:='so so';
else
v_comments:='so high';
end if;
dbms_output.put_line('the sal is'||v_sal||','||v_comments);


end;

--case
declare
v_grade char(1):=upper('&p_grade');
v_comments varchar2(40);
begin
v_comments:=
case v_grade
when 'A' then 'excellent';
when 'B' then 'good';
when 'C' then 'so so';
else 'error grade'
end;
dbms_output.put_line(v_grade||','||v_comments);

end;
--循环语句;while for loop
--loop
declare
v_count number(2):=0;
begin
loop
v_count:=v_count+1;
dbms_output.put_line(v_count);
exit when v_count=10;
end loop;
dbms_output.put_line('game over') ;
end;
--for
declare
v_count number(2):=0;

begin
for v_count in 1..10 loop
dbms_output.put_line(v_count);
end loop;
dbms_output.put_line('game over');


for v_count in reverse 1..10 loop--反转
dbms_output.put_line(v_count);
end loop;
dbms_output.put_line('game over');
end;


--while 同上






--goto
declare
v_count number(2);=0
begin
for v_c
end;























































相关文档
最新文档