ORCL-主线4-存储过程

ORCL存储过程

简介

存储过程时在大型数据库系统中,一组为了完成特定功能的SQL语句集,经过编译后存储在数据库中,用户通过指定的存储过程的名字并给出参数(如果有)来执行它,存储过程时数据库中一个重要对象,任何一个设计良好的数据库应用程序都应该用到存储过程。

语法

create [or replace] PROCEDURE 过程名[(参数名 in/out 数据类型)]
AS
begin
	PLSQL子程序体;
end;
或者

create [or replace] PROCEDURE 过程名[(参数名 in/out 数据类型)]
IS
begin
	PLSQL子程序体;
end 过程名;

测试

问题1:给指定的员工涨100工资,并打印出涨前与涨后的工资

create or replace proceduce addSall(eno in number)
is 
	pemp myemp%rowtype;
begin
 select * into pemp from myemp where empno=eno;
 update myemp set sal=sal+100 where empno=eno;
 
 dbms_output.put_line('涨工资前'|| pemp.sal||'涨工资后'||(pemp.sal+100));
 end addSall;
 
 调用
 begin
 	addSall(eno => 7902);
 	commit;
 end;
 

存储函数

区别

一般来讲,过程和函数的区别在于函数可以有一个返回值;而过程没有返回值。

但过程和函数都可以通过 out 指定一个或多个输出参数。我们可以利用 out 参数,在过程和函数中实

现返回多个值。

测试

create or replace function empincome(eno in emp.empno%type) return
number is
 psal emp.sal%type;
 pcomm emp.comm%type;
begin
 select t.sal into psal from emp t where t.empno = eno;
 return psal * 12 + nvl(pcomm, 0);
end;
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值