oracle存储过程和存储函数(1)

--第一个存储过程
create or replace procedure sayhelloworld
as 
begin
   dbms_output.put_line("hello world");
end;

--调用存储过程
--1.execute exec
--2.在存储过程中调用
/*
begin

   sayhelloworld();

end;
*/

--带参数的存储过程
create or replace procedure raisesalary(eno in number)
--指定参数是输入参数还是输出参数

as

psal emp.sal%type;

begin

  select sal into psal from emp where empno = eno;
  update emp set sal=sal+100 where empno = eno;
  dbms_output.put_line(psal);

end;
/*
注意:
一般不在存储过程或者存储函数中,commit rollback
*/

存储函数,可带参数,并返回一个计算值。
函数和过程的结构类似,但必须有一个return子句,用于返回函数值。

--查询某个员工的年收入
create or replace function querysal(eno in number)
return number;
as
--定义变量要存员工的薪水和奖金
psal emp.sal%type;
pcomm emp.comm%type;

begin

select sal,comm into psal,pcomm from emp where empno=eno;

return psal*12+nvl(pcomm,0);

end;

/*
过程和函数多可以通过out指定一个或多个输入参数。我们可以利用
out参数,在过程和函数中实现返回多个值。
--过程可以通过out参数来实现有返回值
*/

--如果只有一个返回值,用存储函数。否则用存储过程。
--查询某个员工姓名、月薪和职位
create or replace procedure queryinfo(
    eno in number,
    pename out varchar2,
    psal out number,
    pjob out varchar2
)

as 
begin
select ename,sal,job from emp where empno = eno;
end;
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值