您的位置:首页 > 数据库 > Oracle

oracle之存储过程6- if、for、游标使用

2017-03-13 15:26 495 查看
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语句使用



 

 

Sql代码  


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’中。



Sql代码  


 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;  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: