断点

每天进步一点点!
posts - 174, comments - 56, trackbacks - 0, articles - 21

procedure存储过程

Posted on 2010-07-24 16:17 断点 阅读(245) 评论(0)  编辑  收藏 所属分类: Oracle DBA

--创建存储过程:
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;


只有注册用户登录后才能发表评论。


网站导航: