/*
创建和使用存储过程
用CREATE PROCEDURE命令建立存储过程和存储函数。
语法:
create [or replace] PROCEDURE 过程名(参数列表)
AS
PLSQL子程序体;
*/
–第一个存储过程:打印Hello World
/*
调用存储过程
1.exec sayhelloworld();
2.begin
sayhelloworld();
sayhelloworld();
end;
/
*/
create or replace procedure sayhelloworld
as
--说明部分
begin
dbms_output.put_line('Hello World');
end;
/
–创建一个带参数的存储过程:
–给指定的员工涨100块钱的工资,并且打印涨前和涨后的薪水
/*
如何调用:
begin
raisesalary(7839);
raisesalary(7566);
commit;
end;
/
*/
create or replace procedure raisesalary(eno in number)
as
--定义一个变量保存涨薪前的薪水
psal emp.sal%type;
begin
--得到员工涨前的薪水
select sal into psal from emp where empno =eno;
--给该员工涨100
update emp set sal=sal+100 where empno=eno;
--需不需要commit?
--注意:一般不在存储过程或者存储函数中,commit和rollback(一般是谁调用谁提交,保证事务完整性)
--打印
dbms_output.put_line('涨前:'||psal||' 涨后:'||(psal + 100));
end;
/