存储过程与存储函数说明:存储函数有返回值!存储过程没有返回值!
指存储在数据库中供所有用户程序调用的子程序叫存储过程、存储函数。
什么时候用存储过程/存储函数
原则:如果只有一个返回值,用存储函数;否则,就用存储过程。
1.创建存储过程
用CREATE PROCEDURE命令建立存储过程。语法如下:
create [or replace] PROCEDURE 过程名[(参数列表)]
AS
变量声明
PLSQL子程序体;
1)存储过程入门:
create or replace
procedure sayHello
as
begin
dbms_output.put_line('hello world!');
end;
cmd命令行执行程序:
2)给员工涨工资
create or replace
procedure addSal(eno in number)
as
begin
update emp2 set sal=sal*1.1 where empno=eno;
dbms_output.put_line('涨工资完毕');
end;
3)带有输出结果的存储过程
create or replace
procedure queryEmpSal (eno in number,pname out VARCHAR2,psal out number)
as
begin
select ename ,sal into pname,psal from emp2 where empno=eno;
end;
测试上述代码: