set serveroutput on
set verify off

alter session set current_schema = &1;

DECLARE
 P_SQL_ID VARCHAR2(100) := '&2';
 P_DEST_SO_NAME VARCHAR2(100) := '&3';
 P_DEST_SO_CAT VARCHAR2(100) := '&4';
 
 v_sqltext varchar2(32000);

 err_num          number;
 err_msg          varchar2 (255);
BEGIN      
    select SQL_FULLTEXT
      into v_sqltext
      from v$sql
     where sql_id = P_SQL_ID
	   and rownum <2;
    
    execute immediate 'create public outline '||P_DEST_SO_NAME||' for category '||P_DEST_SO_CAT||' on '||v_sqltext; 

    dbms_output.put_line('ol '||P_DEST_SO_NAME||' creada sin errores en la categoria: '||P_DEST_SO_CAT||' para la consulta: '||P_SQL_ID);
    
    commit;
EXCEPTION
 when others then
      err_num := sqlcode;
      err_msg := sqlerrm;

      rollback;
      raise_application_error(-20001, 'error general. '||err_num||'-'||err_msg);

END;
/
