14.0k views
5 votes
Create a procedure namedDD_COMP1_SPthat compiles to contain a singleDBMS_OUTPUTstatement based on a compilation flag value. If the compilation flag value isTRUE, this valueshould be displayed. If the compilation flag value isFALSE, this value should be displayed.Name the compilation flagASSIGN. Create and run the procedure for both compiler flag values.In addition, run a command that displays the compile source code for the procedure when thecompiler flag value isTRUE.

User JoGusto
by
8.3k points

1 Answer

6 votes

Final answer:

Create the procedure DD_COMP1_SP with conditional compilation in Oracle using the PLSQL_CCFLAGS to set a flag named ASSIGN. Execute the procedure with different flag values and retrieve the source code based on the flag value being TRUE.

Step-by-step explanation:

To create a procedure in Oracle that uses a compilation flag named ASSIGN, you can utilize the PL/SQL conditional compilation feature. The procedure DD_COMP1_SP will output a different message based on the value of this flag. Below is how you can write and execute the procedure:



Procedure Creation


  1. Create the procedure with conditional compilation:

    CREATE OR REPLACE PROCEDURE DD_COMP1_SP
    IS
    BEGIN
    $IF $$ASSIGN
    $THEN
    DBMS_OUTPUT.PUT_LINE('The compilation flag value is TRUE.');
    $ELSE
    DBMS_OUTPUT.PUT_LINE('The compilation flag value is FALSE.');
    $END
    END DD_COMP1_SP;


  2. Alter session to set the flag to TRUE, compile the procedure, and run it:

    ALTER SESSION SET PLSQL_CCFLAGS = 'ASSIGN:TRUE';
    EXEC DD_COMP1_SP;


  3. Alter session to set the flag to FALSE, compile the procedure, and run it:

    ALTER SESSION SET PLSQL_CCFLAGS = 'ASSIGN:FALSE';
    EXEC DD_COMP1_SP;


  4. To display the compile source code when the compiler flag value is TRUE:

    ALTER SESSION SET PLSQL_CCFLAGS = 'ASSIGN:TRUE';
    SELECT text FROM user_source WHERE name = 'DD_COMP1_SP' AND type = 'PROCEDURE';

By following the above steps, you can create a procedure that outputs messages based on the compilation flag value and then query the source code as required.

User Hons
by
7.8k points