存储过程无参数,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;it

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

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

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

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


---------------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;db

  --需不须要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;----查询执行存储过程后是否插入成功  

相关文章
相关标签/搜索