Reinforce the Default
ALTER PROCEDURE post_processed
COMPILE plsql_optimize_level=2
ORA-04043: object POST_PROCESSED does not existMore Details: https://docs.oracle.com/error-help/db/ora-04043
Branch Code Based on Opt Level
CREATE OR REPLACE PROCEDURE post_processed
IS
BEGIN
$IF $$plsql_optimize_level = 1
$THEN
-- Slow and problematic
NULL;
$ELSE
-- Fast and modern and easy
NULL;
$END
END post_processed;
Procedure created.
Show the Code!
BEGIN
DBMS_PREPROCESSOR.print_post_processed_source (
'PROCEDURE',
SYS_CONTEXT ('userenv', 'current_schema'),
'POST_PROCESSED');
END;
Statement processed.
PROCEDURE post_processed
IS
BEGIN
-- Fast and modern and easy
NULL;
END post_processed;
Change Optimization Level
ALTER PROCEDURE post_processed
COMPILE plsql_optimize_level=1
Procedure altered.
View Post-Processed Code Again
DECLARE
l_postproc_code DBMS_PREPROCESSOR.source_lines_t;
l_row PLS_INTEGER;
BEGIN
l_postproc_code :=
DBMS_PREPROCESSOR.get_post_processed_source (
'PROCEDURE',
SYS_CONTEXT ('userenv', 'current_schema'),
'POST_PROCESSED');
l_row := l_postproc_code.FIRST;
WHILE (l_row IS NOT NULL)
LOOP
DBMS_OUTPUT.put_line (
LPAD (l_row, 3)
|| ' - '
|| RTRIM (l_postproc_code (l_row), CHR (10)));
l_row := l_postproc_code.NEXT (l_row);
END LOOP;
END;
Statement processed.
1 - PROCEDURE post_processed
2 - IS
3 - BEGIN
4 -
5 -
6 - -- Slow and problematic
7 - NULL;
8 -
9 -
10 -
11 -
12 - END post_processed;
Print Source Code from DBMS_PREPROCESSOR
DECLARE
l_code DBMS_SQL.varchar2a;
l_source VARCHAR2 (32767);
BEGIN
SELECT text
BULK COLLECT INTO l_code
FROM user_source
WHERE name = 'POST_PROCESSED' AND TYPE = 'PROCEDURE'
ORDER BY line;
FOR indx IN 1 .. l_code.COUNT
LOOP
l_source := l_source || l_code (indx);
END LOOP;
DBMS_PREPROCESSOR.print_post_processed_source (l_source);
END;
Statement processed.
PROCEDURE post_processed
IS
BEGIN
-- Fast and modern and easy
NULL;
END post_processed;
Reusable Utility to Display Code
CREATE PROCEDURE show_code_for (tp IN VARCHAR2, nm IN VARCHAR2)
IS
l_postproc_code DBMS_PREPROCESSOR.source_lines_t;
l_row PLS_INTEGER;
BEGIN
l_postproc_code :=
DBMS_PREPROCESSOR.get_post_processed_source (
tp,
SYS_CONTEXT ('userenv', 'current_schema'),
nm);
l_row := l_postproc_code.FIRST;
WHILE (l_row IS NOT NULL)
LOOP
DBMS_OUTPUT.put_line (
LPAD (l_row, 3)
|| ' - '
|| RTRIM (l_postproc_code (l_row), CHR (10)));
l_row := l_postproc_code.NEXT (l_row);
END LOOP;
END;
Procedure created.