oracle 存储过程

1.创建包

  create or replace package packagename is

    procedure prcedurename(vars varchar2);

end packagename;

2 创建包体

  create or repalce package body packagename  is

       procedure prcedurename(vars in varchar2)  is

             begin

                  。。。。。。

             end prcedurename;

    end packagename  ;

3基础语法

   (1)if

       if    【条件】   then

      elseif 【条件】   then

      else  then

      end if;

   (2)for循环(也可以用游标 )

     for  i in 1..27 loop

    .......

    end loop;

  (3) 表迁移

  insert into tablename1  select  from tablename2;

  (4)  merge into  语法,有就更新,没有就插入 

merge into Tablename1 a using

Tablename2 b

on  a.id=b.id

when matched then update  set  a.xx=b.xx

when not matched then insert (a.x,a.xx) values(b.x,b.xx);

语法

MERGE INTO [your table-name] [rename your table here] USING ( [write your query here] )[rename your query-sql and using just like a table] ON ([conditional expression here] AND [...]...) WHEN MATHED THEN [here you can execute some update sql or something else ] WHEN NOT MATHED THEN [execute something else here ! ]

(5) 给字段赋值 

icount number;

 select count(*) into icount from emp where sal>isal and job=sjob;

(6) in输入参数,out输出参数

(7) 游标的定义

CREATE OR REPLACE PROCEDURE EMPLIST
        as
         CURSOR emp_cursor IS
        SELECT f_pid,f_pname,f_proce FROM t_part;
         CURSOR emp_cursor2 IS
        SELECT f_pid,f_pname,f_proce FROM t_part;

        BEGIN
FOR Emp_record IN emp_cursor LOOP

FOR Emp_record2 IN emp_cursor2 LOOP

(8)调用存储过程

1、SQL>exec  proc_emp('参数1','参数2');//无返回值过程调用  
2、SQL>var vsal number  
     SQL> exec proc_emp ('参数1',:vsal);// 有返回值过程调用  
      或者:call proc_emp ('参数1',:vsal);// 有返回值过程调用  

          if(Emp_record.f_proce+Emp_record2.f_proce<25) then
         DBMS_OUTPUT.PUT_LINE(Emp_record.f_proce||'|'||Emp_record2.f_proce);
        end if;

       END LOOP;

        END LOOP;

END;

(9)异常

  exception
      when others then
        raise_application_error(1111, sqlerrm);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值