1、if判断语句使用
create or replace procedure test01 is
V_TEST number(10):=1;
begin
if V_TEST = 1 then
dbms_output.put_line('1----');
end if;
if V_TEST = 1 then
dbms_output.put_line('1----');
else if V_TEST = 2 then
dbms_output.put_line('2----');
else if V_TEST = 3 then
dbms_output.put_line('3----');
end if;
end if;
end if;
end test01;
2、for语句使用
- create or replace procedure test01 is
- begin
- For x in 0 .. 10 LOOP
- dbms_output.put_line(x||'----');
- end LOOP;
- end test01;
3、游标使用
游标的使用 Oracle 中Cursor 是非常有用的,用于遍历临时表中的查询结果。
将emp表中"ename"和"deptno"查询出,存放到cusor_01游标中。for循环迭代游标集合。每次迭代的结果存到‘c’中。
- create or replace procedure test01 is
- cursor cusor_1 is select ename,deptno from emp ;--定义一个游标
- begin
- for c in cusor_1 loop
- dbms_output.put_line('员工姓名:'||c.ename||' 部门编号:'||c.deptno);
- end loop;
- end test01;