存储过程的创建和使用,以及存储过程和存储函数的区别

简单存储过程的创建和使用

--简单存储过程的创建和使用
create or replace procedure test(ids account.id%type)
as
begin
  update account set money = money + 100 where id = ids;
  commit;
end;

--查询一下
select * from account where id = 3;

--调用一下
declare
begin
  test(3);
end;

带有输出变量的存储过程

create or replace procedure test1(ids account.id%type , moneys out number)
as
i account.money%type;
begin
  select money+100 into moneys from account where id = ids;
 -- moneys := i;
end;

--带有输出变量的存储过程测试
select * from account for update;

declare
i number(10);
begin
  test1(3,i);
  dbms_output.put_line(i);
end;

存储过程和存储函数的区别

  1. 存储函数有返回值,而存储过程没有返回值。存储函数一定要有返回值,不然和存储过程就没有区别
  2. 如果存储过程想实现有返回值的业务,我们就必须使用out类型的参数。
  3. 而是在存储过程内部给out类型参数赋值,在执行完毕后,我们直接拿到输出类型参数的值
  4. 即便是存储过程使用了out类型的参数,起本质也不是真的有了返回值,

存储函数

--存储函数必须有返回值吗???
--存储函数和存储过程有什么区别???
--plsql中存储函数的return可以省略吗???
--存储函数的返回值必须接收

--存储函数
create or replace function f_test(uid account.id%type) return number
is
   s number(10);
begin
  select money+200 into s from account where id = uid;
  dbms_output.put_line(s);
  return s;
end;

select * from account where id = 1;
--测试存储函数
declare
s number(10);
begin
  s := f_test(1);
end;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值