--===================================存储过程(过程)
/*
举例:在网站上买东西,提交订单后,
库存量减少(update),账户的信息也会发生减少(update),
生成订单(insert),备份数据(insert),记录日志(insert)
使用java代码在业务逻辑中处理这些操作(调用dao操作数据库)
以上这一系列操作都可以使用存储过程来实现
存储过程:封装了一系列了sql语句,事先编译好,存储在数据库端,供其他程序员调用
好处:效率高
--创建存储过程的语法
create or replace procedure 过程名称(参数1 in\out,参数2 in|out)
as|is
--在存储过程中定义变量
begin
--封装多条sql语句
end;
*/
--给某个员工涨工资,打印出涨前涨后的工资
create or replace procedure pro_add_sal(eno in number,money in number)
as
oldsal number;
newsal number;
begin
--查询出来打印涨前的工资
select sal into oldsal from emp where empno=eno;
dbms_output.put_line('涨前工资:'||oldsal);
--加工资
update emp set sal = sal+money where empno = eno;
commit;
--查询涨之后的工资
select sal into newsal from emp where empno=eno;
dbms_output.put_line('涨后工资:'||newsal);
end;
--调用测试
--第一种方式: 用的比较少,如果输出参数,接收不了
call pro_add_sal(7788,100);
--第二种方式:【推荐】
declare
begin
--调用存储过程
pro_add_sal(7788,200);
end;
select * from emp where empno = 7788;