版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/wangtongxue123456/article/details/79681881
语法
create [or replace] PROCEDURE 过程名(参数列表) AS PLSQL 子程序体
实例
set serveroutput on
--第一个储存过程 :Hello Word
create or replace procedure sayehelloworld
as
--说明部分
/*
调用存储过程的两种方法
1.exec sayhelloworld()
2.
begin
sayehelloworld
sayehelloworld
end;
*/
begin
DBMS_OUTPUT.PUT_LINE('Hello Word');
end;
带参数的储存过程
--创建带参数的储存过程
--给指定的员工涨100块钱
/**
如何调用
begin
raisealary('a')
commit
end;
*/
create or replace procedure raisealary(eno in char)
as
--定义一个变量保存涨前的薪水
psal a.num%type;
begin
--得到员工涨前的薪水
select num into psal from a where id=eno;
--给员工涨工资
update a set num=num+100 where num=eno;
-- 一般不再储存过程中提交和回滚
--打印
DBMS_OUTPUT.PUT_LINE('涨前'||psal||'涨后'||psal+100);
end;
函数 为一 命名的储存过程,可带参数,并返回一计算值。 函数和过程结构类似,但必须有一个return子句,用于返回函数值。 创建存储函数的语法
create [or replace] function 函数名(参数列表)
return 函数值类型
AS
pl/sql 子程序体
in和out参数
一般来讲,存储过程和存储函数的区别在于储存函数可以有一个返回值;而存储过程没有返回值。 1、存储过程和存储函数都可以有out参数。2、存储过程和存储函数都可以有多个out参数哦。3、存储过程可以通过out参数来实现返回值。
什么时候用存储过程和存储函数
CREATE OR REPLACE
PACKAGE QUERYCESHI AS
type numlistcursor is ref cursor;
procedure finda(numlist out numlistcursor);
END QUERYCESHI;
CREATE OR REPLACE
PACKAGE BODY QUERYCESHI AS
procedure finda(numlist out numlistcursor) AS
BEGIN
-- TODO: procedure QUERYCESHI.finda所需的实施
open numlist for select * from A;
NULL;
END finda;
END QUERYCESHI;
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有