简体   繁体   中英

Set an out parameter value from a pl/sql block stored in a clob column

I have the following table and relevant column..

TABLEA
SQL_SCRIPT    CLOB

Here is a procedure that executes the pl/sql block in the clob..

Create procedure (p_exit_code IN OUT NUMBER)
AS
V_sql_val   sql_script%TYPE;
…
BEGIN
Select sql_script into v_sql_val from tablea;

EXECUTE IMMEDIATE sql_script;

END;

In SQL_SCRIPT I am trying to do following in the exception handler:

EXCEPTION
  WHEN EXCP_STOP_PROCESS THEN
    p_exit_code := 1;
END;

I need to set the value of p_exit_code parameter in procedure from the clob script. How can I do this?

If I understand correctly, you need to set the value of a variable within sql_script and return this to the calling procedure. This can be achieved using bind variables. A very simple test case is below:

declare 

  -- ':return_code' is the bind variable
  sql_script varchar2(1000) := 'begin :return_code := 1; end;';
  vn_result number;

begin

  execute immediate sql_script using out vn_result;
  dbms_output.put_line(vn_result);

end;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM