oracle存储过程代码格式

先来一个简单的存储过程样式--更新某员工的工资,并打印更新之前和更新之后的数据;

  create or replace procedure updateEmpSal( en in number,psal in number)

  as

                   oldSal emp.sal%type;

                   newSal emp.sal%type;

  begin

                   select sal into oldSal from emp where empno = en;

                   dbms_output.put_line('更新之前:’|| oldSal);

                   update emp set sal = sal + psal where empno = en;

                   commit;

                   select sal into newSal from emp where empno = en;

                   dbms_output.put_line('更新之后:’|| newSal);

end;

-----加上注释和数据名称

创建 或 更新 存储过程 过程名称 (参数1 和类型;in为输入参数,out输出参数)

as

oldSal emp的工资为此赋值;

newSal emp的工资为此赋值;

begin 

       --查询并打印更新之前的工资

       --更新工资

       --查询并打印更新之后的工资

end;

----访问存储过程

  --call updateEmpSal (123,500);--123为员工号 --500 为增加的工资;

2、

----举例: 根据员工编号得到年薪

       create or replace procedure getYearSalByEmpno(eno in number ,yearsal out number)--out代表此参数是输出参数

       as

       begin

         select sal * 12 + nvl(comm ,0) into yearsal from emp where empno = eno;--nvl(p1,p2)--如果p1为空取值p2;

       end;   

​      -- 访问带有输出参数的存储过程    

       declare

        ys number; --ys为参数名

        begin

         getYearSalByEmpno (7788,ys);  

        dbms_output.put_line(ys); --打印员工的年薪

        end;

--08-05-22 待增  sasha



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值