You need to store each and every line of the dynamic sql in a file using UTL_FILE Package before you could execute it so that you can refer the same file after executing the code this here serves you as a log file for debugging.
where p_string_in is dynamic SQL for each line.
Suppose if my dynamic SQL consists of following 3 lines.
EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS''
then you will call UTL_FILE.PUT_LINE function 3 times
UTL_FILE.PUT_LINE(v_filehandle 'EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_FORMAT = 'DD-MON-YYYY HH24:MI:SS''');