Set Up Table
CREATE TABLE employees AS SELECT * FROM hr.employees
Table created.
Package to Support Bulk Insert
CREATE OR REPLACE PACKAGE employees_dml
IS
TYPE demo_aat IS TABLE OF employees%ROWTYPE
INDEX BY PLS_INTEGER;
PROCEDURE insert_rows ( rows_in IN demo_aat );
END;
Package created.
Use DBMS_DB_VERSION to Optimize Code
CREATE OR REPLACE PACKAGE BODY employees_dml
IS
PROCEDURE insert_rows ( rows_in IN demo_aat )
IS
BEGIN
$IF DBMS_DB_VERSION.VER_LE_10_1
$THEN
DECLARE
l_dense demo_aat;
l_index PLS_INTEGER := rows_in.FIRST;
BEGIN
WHILE (l_index IS NOT NULL)
LOOP
l_dense (l_dense.COUNT + 1) := rows_in (l_index);
l_index := rows_in.NEXT (l_index);
END LOOP;
FORALL indx IN l_dense.FIRST .. l_dense.LAST
INSERT INTO employees VALUES l_dense (indx);
END;
$ELSE
FORALL indx IN INDICES OF rows_in
INSERT INTO employees VALUES rows_in (indx);
$END
END insert_rows;
END;
Package Body created.
Quality Assurance with Conditional Compilation
CREATE OR REPLACE PROCEDURE compute_intensive
AUTHID DEFINER
IS
BEGIN
$IF $$plsql_optimize_level < 2
$THEN
$ERROR 'compute_intensive must be compiled with maximum optimization!' $END
$END
NULL;
END compute_intensive;
Procedure created.
Hide/Expose Private Subprograms for Testing
ALTER SESSION SET PLSQL_CCFLAGS = 'show_private_joke_programs:FALSE'
Statement processed.
Hide/Expose Private Subprograms for Testing
CREATE OR REPLACE PACKAGE sense_of_humor
IS
PROCEDURE calc_how_funny (
joke_in IN VARCHAR2
, funny_rating_out OUT NUMBER
, appropriate_age_out OUT NUMBER
);
$IF $$show_private_joke_programs $THEN
FUNCTION humor_level ( joke_in IN VARCHAR2 )
RETURN NUMBER;
FUNCTION maturity_level ( joke_in IN VARCHAR2 )
RETURN NUMBER;
$END
END;
Package created.
Hide/Expose Private Subprograms for Testing
CREATE OR REPLACE PACKAGE BODY sense_of_humor
IS
FUNCTION humor_level ( joke_in IN VARCHAR2 )
RETURN NUMBER
IS
BEGIN
-- Some really interesting code here...
RETURN 100;
END humor_level;
FUNCTION maturity_level ( joke_in IN VARCHAR2 )
RETURN NUMBER
IS
BEGIN
-- Some really interesting code here...
RETURN 100;
END maturity_level;
PROCEDURE calc_how_funny (
joke_in IN VARCHAR2
, funny_rating_out OUT NUMBER
, appropriate_age_out OUT NUMBER
)
IS
BEGIN
funny_rating_out := humor_level ( joke_in );
appropriate_age_out := maturity_level ( joke_in );
END calc_how_funny;
END;
Package Body created.
Private Subprogram Cannot Be Executed
BEGIN
DBMS_OUTPUT.PUT_LINE (sense_of_humor.humor_level (
'Why did the chicken cross the road?'));
END;
ORA-06550: line 2, column 41: PLS-00302: component 'HUMOR_LEVEL' must be declaredMore Details: https://docs.oracle.com/error-help/db/ora-06550
Change CC Flag and Recompile
ALTER SESSION SET PLSQL_CCFLAGS = 'show_private_joke_programs:TRUE'
Statement processed.
Change CC Flag and Recompile
ALTER PACKAGE sense_of_humor COMPILE
Package altered.
BEGIN
DBMS_OUTPUT.PUT_LINE (sense_of_humor.humor_level (
'Why did the chicken cross the road?'));
END;
100
Helper Procedure Showing CC Flag Values
CREATE OR REPLACE PROCEDURE show_cc_parameters
IS
/* Reflect contents of all_plsql_object_settings */
BEGIN
IF $$plsql_debug
THEN
DBMS_OUTPUT.put_line ('DEBUG ON');
ELSE
DBMS_OUTPUT.put_line ('DEBUG OFF');
END IF;
DBMS_OUTPUT.put_line ('Opt Level = ' || $$plsql_optimize_level);
DBMS_OUTPUT.put_line ('Code Type = ' || $$plsql_code_type);
DBMS_OUTPUT.put_line ('Warnings Setting = ' || $$plsql_warnings);
DBMS_OUTPUT.put_line ('NLS Length Semantics = ' || $$nls_length_semantics);
DBMS_OUTPUT.put_line ('CC Flags = ' || $$plsql_ccflags);
DBMS_OUTPUT.put_line ('PLScope = ' || $$plscope_settings);
END show_cc_parameters;
Procedure created.
ALTER SESSION SET plsql_warnings = 'ENABLE:ALL'
Statement processed.
ALTER SESSION SET plscope_settings='IDENTIFIERS:ALL'
Statement processed.
BEGIN
show_cc_parameters ();
END;
DEBUG OFF
Opt Level = 2
Code Type = INTERPRETED
Warnings Setting = DISABLE:ALL
NLS Length Semantics = BYTE
CC Flags = show_private_joke_programs:TRUE
PLScope = IDENTIFIERS:NONE
Use $IF to Control Tracing
ALTER SESSION SET PLSQL_CCFLAGS = 'oe_debug:true, oe_trace_level:10'
Statement processed.
Use $IF to Control Tracing
CREATE OR REPLACE PROCEDURE calculate_totals
IS
BEGIN
$IF $$oe_debug AND $$oe_trace_level >= 5
$THEN
-- q$error_manager.trace ...
DBMS_OUTPUT.PUT_LINE ('Tracing at level 5 or higher');
$END
DBMS_OUTPUT.PUT_LINE ('Normal processing');
END calculate_totals;
Warning: PROCEDURE CALCULATE_TOTALS Line/Col: 1/1 PLW-05018: unit CALCULATE_TOTALS omitted optional AUTHID clause; default value DEFINER usedMore Details: https://docs.oracle.com/error-help/db/ora-20001
Use $IF to Control Tracing
BEGIN
calculate_totals;
END;
Tracing at level 5 or higher
Normal processing
Use $IF to Control Tracing
ALTER SESSION SET PLSQL_CCFLAGS = 'oe_debug:false'
Statement processed.
Use $IF to Control Tracing
ALTER PROCEDURE calculate_totals COMPILE
Procedure altered.
Use $IF to Control Tracing
BEGIN
calculate_totals;
END;
Normal processing