存储过程无参数,in,out ,in out 的用法

select * from scott.emp where empno=7839 or empno=7566 
select * from emp5
create table emp5 as select * from  scott.emp


-----------------in

create or replace procedure raisesalary(eno in number)
as
--定义一个变量保存涨薪前的薪水
  psal emp5.sal%type;
begin
  --得到员工涨前的薪水
  select sal into psal from emp5 where empno =eno;

  --给该员工涨100
  update emp5 set sal=sal+100 where empno=eno;

  --需不需要commit?
  --注意:一般不在存储过程或者存储函数中,commit和rollback(一般是谁调用谁提交,保证事务完整性)

  --打印
  dbms_output.put_line('涨前:'||psal||'   涨后:'||(psal + 100));
end;
/

begin
 raisesalary(7839);
 raisesalary(7566); 
 commit;
end;
/


---------------in,out

create or replace procedure raisesalary1(eno in number,sal out emp5.sal%type)
as
--定义一个变量保存涨薪前的薪水
  psal emp5.sal%type;
begin
  --得到员工涨前的薪水
  select sal into psal from emp5 where empno =eno;

  --给该员工涨100
  update emp5 set sal=sal+100 where empno=eno;

  --需不需要commit?
  --注意:一般不在存储过程或者存储函数中,commit和rollback(一般是谁调用谁提交,保证事务完整性)

  --打印
    sal:=psal;
  dbms_output.put_line('涨前:'||psal||'   涨后:'||(psal + 100));
    
    --dbms_output.put_line(sal);
end;
/

declare a emp5.sal%type;

begin
 raisesalary1(7839,a);
dbms_output.put_line('a='||a);
 raisesalary1(7566,a); 
dbms_output.put_line(a);
 commit;
 
end;

------------------in out


create or replace procedure raisesalary2(sal2 in out number) as
  --定义一个变量保存涨薪前的薪水
  psal number;
begin
  --得到员工涨前的薪水
 -- select sal into psal from emp5 where empno = sal2;

  --给该员工涨100
  update emp5 set sal = sal + 100 where empno = sal2;
    
    

  --需不需要commit?
  --注意:一般不在存储过程或者存储函数中,commit和rollback(一般是谁调用谁提交,保证事务完整性)

  --打印
  sal2 := psal;
  dbms_output.put_line('涨前:' || psal || '   涨后:' || (psal + 100));

  --dbms_output.put_line(sal);
end;
/

declare
  a number := 7839;---得另定义一个变量去接收返回值

begin
  raisesalary2(a);
  dbms_output.put_line('a=' || a);
  a := 7566;
  raisesalary2(a);
  dbms_output.put_line(a);
  commit;

end;


select * from emp5


---------------------无参数的存储过程

create procedure a1 as 

begin

insert into emp5(empno,ename,job) values(111,'hello','hello');
commit;
end;


begin 

 a1;
 end;


select * from emp5;----查询执行存储过程后是否插入成功
 

转载于:https://my.oschina.net/u/3563297/blog/3053783

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值