首页 > 数据库 > 数据库开发技术 > 动态调用带参数的存储过程
上面测试的都是没有参数的存储过程;
请问如何动态调用带参数的存储过程;
如:proc_one,proc_two都是没有参数的;
如果是有参数,怎么样把参数从proc_main传递给proc_one,
proc_one修改后,还能传递给proc_main;
空心菜 | 12/12/2006, 22:47
今天中午抽空为其写了一个新的demo,希望能有所帮助
说明:proc_one、proc_two、proc_three用来模拟三个procedure,proc_main用来通过动态调用前面三个过
程的过程。在proc_main中输入一个参数,在proc_one/two/three中处理后返回到proc_main中。下面是code
和测试过程。
SQL> create or replace procedure proc_one(p_arg in out varchar2) as
2 begin
3 dbms_output.put_line('one proc call, input arg is '||p_arg);
4 p_arg:=p_arg||' return from proc_one';
5 end;
6 /
过程已创建。
SQL>
SQL> create or replace procedure proc_two(p_arg in out varchar2) as
2 begin
3 dbms_output.put_line('two proc call, input arg is '||p_arg);
4 p_arg:=p_arg||' return from proc_two';
5 end;
6 /
过程已创建。
SQL>
SQL> create or replace procedure proc_three(p_arg in out varchar2) as
2 begin
3 dbms_output.put_line('three proc call, input arg is '||p_arg);
4 p_arg:=p_arg||' return from proc_three';
5 end;
6 /
过程已创建。
SQL> create or replace procedure proc_main(
2 v_procname in varchar2,
3 p_arg in varchar2 default null)
4 as
5
6 v_sql varchar2(255);
7 v_ret varchar2(255);
8 begin
9 v_ret:=p_arg;
10 v_sql:='begin '||v_procname||'(:v1); end;';
11 execute immediate v_sql using in out v_ret;
12 dbms_output.put_line('main proc call completed!');
13 dbms_output.put_line('main input arg return is '||v_ret);
14 end;
15 /
过程已创建。
SQL>
SQL> 备注:v_ret变量是在proc_main中动态传入到要调用的过程中的参数,然后接受被调用过程处理后的结果并在proc_main中显示。
SQL> set serveroutput on
SQL> exec proc_main('proc_one','call one');
one proc call, input arg is call one
main proc call completed!
main input arg return is call one return from proc_one
PL/SQL 过程已成功完成。
SQL> exec proc_main('proc_two','call two');
two proc call, input arg is call two
main proc call completed!
main input arg return is call two return from proc_two
PL/SQL 过程已成功完成。
SQL> exec proc_main('proc_three','call three');
three proc call, input arg is call three
main proc call completed!
main input arg return is call three return from proc_three
PL/SQL 过程已成功完成。
SQL> thomas zhang 的杂货铺[@more@]
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/658202/viewspace-1032467/ ,如需转载,请注明出处,否则将追究法律责任。