declare --if语句
v_empno emp.empno%type:=&no;
v_deptno emp.deptno%type;
begin
select emp.deptno into v_deptno from emp where emp.empno=v_empno;
if v_deptno=10 then
dbms_output.put_line('-------10----------');
elsif v_deptno=20 then
dbms_output.put_line('=======20=========');
else
dbms_output.put_line('********30*********');
end if;
end;
/
2、for
declare --for循环
i int := 1;
begin
for i in reverse 1..10 loop
dbms_output.put_line('i='||i);
end loop;
end;
/
3、case
declare --case语句
v_empno emp.empno%type:=&no;
v_deptno emp.deptno%type;
begin
select emp.deptno into v_deptno from emp where emp.empno=v_empno;
case v_deptno
when 10 then
dbms_output.put_line('-------10----------');
when 20 then
dbms_output.put_line('=======20=========');
else
dbms_output.put_line('********30*********');
end case;
end;
/
declare --case语句
v_empno emp.empno%type:=&no;
v_deptno emp.deptno%type;
begin
select emp.deptno into v_deptno from emp where emp.empno=v_empno;
case
when v_deptno=10 then
dbms_output.put_line('-------10----------');
when v_deptno=20 then
dbms_output.put_line('=======20=========');
else
dbms_output.put_line('********30*********');
end case;
end;
/
4、loop
declare --loop循环
i int := 1;
begin
loop
dbms_output.put_line('i='||i);
exit when i=10;
i:=i+1;
end loop;
end;
/
5、while
declare --while循环
i int := 1;
begin
while i<=10 loop
dbms_output.put_line('i='||i);
i:=i+1;
end loop;
end;
/