Oracle对象之存储过程

存储过程

存储过程(Stored Procedure)是在大型数据库系统中,一组为了完成特定功能的SQL 语句集,经编译后存储在数据库中,用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它。存储过程是数据库中的一个重要对象,任何一个设计良好的数据库应用程序都应该用到存储过程。
 
创建存储过程语法:
 
create [or replace] PROCEDURE 过程名[(参数名 in/out 数据类型)]
AS
begin
        PLSQL子程序体;
End;
 
或者
create [or replace] PROCEDURE 过程名[(参数名 in/out 数据类型)]
is
begin
        PLSQL子程序体;
End  过程名;
 
范例1:给指定的员工涨100工资,并打印出涨前和涨后的工资
 
分析:我们需要使用带有参数的存储过程
 
 1 create or replace procedure addSal1(eno in number) is
 2   pemp myemp%rowtype;
 3 begin
 4   select * into pemp from myemp where empno = eno;
 5   update myemp set sal = sal + 100 where empno = eno;
 6   dbms_output.put_line('涨工资前' || pemp.sal || '涨工资后' || (pemp.sal + 100));
 7 end addSal1;
 8 调用
 9 begin
10   -- Call the procedure
11   addsal1(eno => 7902);
12   commit;
13 end;
14  
原文地址:https://www.cnblogs.com/anzhi/p/7515959.html