ORACLE存储过程 以oracle自带例子数据库的表举例 1、 create or replace procedure p is cursor c is select * from emp2 for update; begin for v_emp in c loop if(v_emp.sal <2000) then update emp2 set sal =sal+1 where current of c ; elsif(v_emp.sal>=2000) then delete from emp2 where current of c; end if; end loop; commit; end; 创建了存储过程不代表运行了存储过程; 运行此存储过程 : 方式一 exec p; 方式二 begin p; end; 2、带参数的存储过程 in 相当于程序里的参数,供传入用,在存储过程不能改变其值; out 相当于程序里的返回值,在存储过程中可以为其赋值传出; in out 既可以当参数又可以当返回值用; 不带上述说明符默认为in类型; 下例中v_a v_b 为in类型 v_c 为out类型 v_d 为in out 类型 create or replace procedure p(v_a in number,v_b number,v_c out number,v_d in out number) is begin if(v_a > v_b) then v_c := v_a; else v_c := v_b; end if; v_d := v_d+1; end; ---> 调试时: 可以在命令窗口调试,出错时 用show errors 显示出错信息; 可以在plDv中调试; ---> 运行时: 可以在命令窗口运行: declare v_a number:=3; v_b number:=4; v_c number; v_d number:=5; begin p(v_a,v_b,v_c,v_d); dbms_output.put_line(v_c); dbms_output.put_line(v_d); end; 可以在plDv中调试;
存储过程的调用
最新推荐文章于 2023-05-19 23:30:00 发布