Dynamic call Store Procedure (execute immediate ) Out parameters Problems

rusty1119 picture rusty1119 · Jun 22, 2015 · Viewed 8k times · Source

I have problem Dynamic Call Store Procedure

    v_sql      := 'begin '|| p_procname ||  '(''test1'','' test2 '',:v_output2);  end;';
    execute immediate v_sql
    using  out v_output2 ;
    dbms_output.put_line(v_output2 || ' ' );

In here ı can call procedure with execute immediate . But my problem is dynamic bind variable . This values comes from log table then i parse for execute_immediate procedure

    v_sql      := 'begin '|| p_procname ||  '(''test1'','' test2'',:v_output2);  end;';
    v_sql1:= ||using||  'out v_output2 ' ;

    execute immediate v_sql
    v_sql1;

It doesnt work like that . How can i make dynamic variables bind , because i call a lot of procedure and thats procedure has different in and out parameters. I hope you can understand what problem i have .How can i pass this problems thx

Answer

vishnu sable picture vishnu sable · Jun 22, 2015

here is simple procedure

 create procedure test_proc(p_user varchar2, p_code varchar2, p_error varchar2) is
 begin
   p_error := p_user || p_code;
 end; 

calling code for same ..

Declare
  v_test_proc varchar2(50) := 'test_proc';
  p_user      varchar2(50) := 'test_name';
  p_code      varchar2(50) := 'test_code';
  p_error     varchar2(100);
  v_sql       varchar2(2000);
begin
  v_sql := 'begin ' || v_test_proc || '( :1 ,:2, :3 ); end;';
  execute immediate v_sql
    using p_user, p_code, out p_error;
  dbms_output.put_line(p_error);
end;