oracle中存储过程与函数

存储过程架构

Create or replace procedure 名字[(参数)]

as or is

begin

sql语句

[exception]

end proc名字

调用:execute或者用块来处理

函数架构

create or replace function 名字[(参数)]

return 返回类型

as or is

begin

end 名字;

参数:参数名称 in ||out ||in out 数据类型

 

实例

过程

create or replace procedure proc_demo(i_id number,o_sum out number,o_count out number)

as

Begin

select count(*),sum(age) into o_count,o_sum from t where id>i_id;

exception

when no_data_found then dbms_output.put_line('你所查找的数据不存在');

when others then dbms_output.put_line('发生其他错误');

end proc_demo;

 

过程的调用

declare

o_sum number;

o_count number;

begin

proc_demo(15,o_sum,o_count);

end;

 

函数

create or replace function get_sum(i_id number,o_sum out number)

return number;

as

begin

select sum(age) into o_sum from t where id>i_id;

return o_sum;

exception

when no_data_found then dbms_output.put_line('所需要的数据没有找到');

when others then dbms_output.put_line('发生其它错误');

end get_sum;

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值