Chapter 9. DBMS_DDL

Table of Contents

9.1. Overview
9.2. Procedures and Functions
9.2.1. CREATE_WRAPPED
9.2.2. IS_TRIGGER_FIRE_ONCE
9.2.3. SET_TRIGGER_FIRING_PROPERTY
9.2.4. WRAP

This chapter describes the basic concepts of DBMS_DDL package and how to use it.

9.1. Overview

DBMS_DDL provides WRAPPING and other DDL related functions for DDLs that start with CREATE OR REPLACE PROCEDURE, or PACKAGE.

9.2. Procedures and Functions

This section describes the procedures and functions provided by DBMS_DDL package in alphabetical order.

9.2.1. CREATE_WRAPPED

Wraps a DDL that starts with CREATE OR REPLACE PROCEDURE, FUNCTION, PACKAGE or PACKAGE BODY, and then executes it.

This procedure performs the same action as the following.

EXECUTE IMMEDIATE
        DBMS_DDL.WRAP(ddl);

Details about the CREATE_WRAPPED procedure are as follows:

  • Prototype

    DBMS_DDL.CREATE_WRAPPED
              ( ddl IN VARCHAR2 )
  • Parameter

    ParameterDescription
    ddl

    DDL that starts with CREATE OR REPLACE PROCEDURE, FUNCTION, PACKAGE or PACKAGE BODY.

    Unlike tbwrap tool, only one DDL is allowed.

  • Example

    create or replace procedure create_wrapped_example
    is
        hello_ddl varchar(1000) := 'create or replace procedure hello
                                    is
                                      str varchar(10) := ''hello'';
                                    begin
                                      DBMS_OUTPUT.PUT_LINE(str);
                                    end;';
    begin
        DBMS_DDL.CREATE_WRAPPED(hello_ddl);
    end;
    /

    Note

    DBMS_DDL.CREATE_WRAPPED is executed based on the caller's privilege without referencing the caller's role. Hence, the previous hello_ddl example can only be executed by a caller with the CREATE ANY PROCEDURE privilege.

9.2.2. IS_TRIGGER_FIRE_ONCE

Returns whether FireOnce, an attribute of TRIGGER, is set.

Details about the IS_TRIGGER_FIRE_ONCE function are as follows:

  • Prototype

    DBMS_DDL.IS_TRIGGER_FIRE_ONCE
              ( trig_owner IN VARCHAR2, trig_name IN VARCHAR2 ) RETURN
              BOOLEAN;
  • Parameter

    ParameterDescription
    trig_ownerTRIGGER owner.
    trig_nameTRIGGER name.

9.2.3. SET_TRIGGER_FIRING_PROPERTY

Sets the value of FireOnce, an attribute of TRIGGER.

Details about the SET_TRIGGER_FIRING_PROPERTY procedure are as follows:

  • Prototype

    DBMS_DDL.SET_TRIGGER_FIRING_PROPERTY
              ( trig_owner IN VARCHAR2, trig_name IN VARCHAR2, fire_once IN
              BOOLEAN )
  • Parameter

    ParameterDescription
    trig_ownerTRIGGER owner.
    trig_nameTRIGGER name.
    fire_onceNew FireOnce value.

9.2.4. WRAP

Returns the result of wrapping a DDL that starts with CREATE OR REPLACE PROCEDURE, FUNCTION, PACKAGE or PACKAGE BODY.

A ddl can be wrapped by executing the following.

EXECUTE IMMEDIATE
      DBMS_DDL.WRAP(ddl);

Details about the WRAP function are as follows:

  • Prototype

    DBMS_DDL.WRAP (
              ddl IN VARCHAR2 ) RETURN VARCHAR2;
  • Parameter

    ParameterDescription
    ddl

    DDL that starts with CREATE OR REPLACE PROCEDURE, FUNCTION, PACKAGE or PACKAGE BODY.

    Unlike tbwrap tool, only one DDL is allowed.

  • Example

    create or replace procedure wrap_example
    is
        hello_ddl varchar(1000) := 'create or replace procedure hello
                                    is
                                      str varchar(10) := ''hello'';
                                    begin
                                      DBMS_OUTPUT.PUT_LINE(str);
                                    end;';
    begin
        EXECUTE IMMEDIATE DBMS_DDL.WRAP(hello_ddl);
    end;
    /