oracle学习之存储过程

--第一个存储过程,打印一个hello world
/*
调用存储过程:
1.exec sayhelloworld();
2.begin 
    sayhelloworld();
    sayhelloworld();
 end;
 /
*/
create or replace procedure sayhelloworld
as 
--说明部分
begin 
    dbms_output.put_line('Hello world');
end;
/

-------------------------------------------------------------------


--创建一个带参数的存储过程
--给指定的员工涨100块钱的工资,并且打印涨前和涨后的薪水
/*
    如何调用:
begin
    raisesalary(1);
    raisesalary(2);
    commit;
end;
/
*/
create or replace  procedure raisesalary(eno in number)
as
--定义一个变量保存涨前的工资
psal emp.sal%type;
begin
--得到员工的涨前薪水
  select sal into psal from emp where id = eno;

  --给该员工涨一百元的工资
  update emp set sal = sal + 100 where id=eno;

  --需不需要commit?
  --注意:一般不在存储过程或者存储函数中,commit和rollback。

  --打印涨前和涨后的薪水
  dbms_output.put_line('涨前:'||psal||'   涨后:'||(psal + 100));
end;
/



-----------------------------------------------------------
create or replace function queryempincome(eno in number)
return number
as
--定义变量保存员工的薪水和奖金
    psal emp.sal%type;
    pcomm emp.comm%type;
begin
    --得到员工的月薪和奖金
    select sal,comm into psal,pcomm from emp where id = eno;

    --直接返回年薪
    return psal * 12 + nvl(pcomm,0) ;
end;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值