procedure存储过程

--创建存储过程:
create or replace procedure p
is
  cursor c is
  select * from emp2 for update;
begin
  for v_temp in c loop 
    if(v_temp.deptno = 10) then
      update emp2 set sal = sal+10 where current of c;
    elsif(v_temp.deptno = 20) then
      update emp2 set sal = sal+20 where current of c;
    else
       update emp2 set sal = sal+50 where current of c;
    end if;
  end loop;
  commit;
end;

--执行:
exec p;

begin
p;
end;


--带参数的存储过程,in传入参数,默认为传入,out传出。
create or replace procedure p
   (v_a in number,v_b number,v_ret out number,v_temp in out number)
is
begin
  if(v_a >v_b) then
    v_ret := v_a;
  else
    v_ret := v_b;
  end if;
  v_temp :=v_temp +1;
end;

declare
  v_a number := 3;
  v_b number := 4;
  v_ret number;
  v_temp number := 5;
begin
  p(v_a,v_b,v_ret,v_temp);
  dbms_output.put_line(v_ret);
  dbms_output.put_line(v_temp);
end;

你可能感兴趣的:(procedure存储过程)