Library /sys$common/syshlp/SQL$HELP72.HLB  —  DECLARE  Routine  Examples
    Example 1: Definining a domain and referencing an external
    function

    SQL> create domain MONEY as integer (2);
    SQL>
    SQL> create function INTEREST_PAID
    cont>    (in :amt MONEY)
    cont>    returns MONEY;
    cont>    external
    cont>       language C
    cont>       parameter style GENERAL;
    SQL>
    SQL> alter domain MONEY
    cont>    add
    cont>       check (INTEREST_PAID (value) > 0)
    cont>       not deferrable;

    Once the ALTER DOMAIN is completed, neither the function nor the
    domain can be defined before the other. Here is a fragment of the
    result of executing the output from the RMU Extract command.

    SQL> create domain MONEY
    cont>     INTEGER (2)
    cont>     check((INTEREST_PAID(value) > 0))
    cont>     not deferrable;
    %SQL-F-RTNNOTDEF, function or procedure INTEREST_PAID is not defined
    SQL>
    SQL> commit work;
    SQL> create function INTEREST_PAID (
    cont>     in    :AMT
    cont>         MONEY
    cont>         by reference)
    cont>     returns
    cont>         MONEY by value
    cont>     language SQL;
    cont>     external
    cont>         language C
    cont>         parameter style GENERAL
    cont>     deterministic
    cont>     called on null input
    cont>     ;
    %SQL-F-NO_SUCH_FIELD, Domain MONEY does not exist in this database or schema
    SQL> commit work;

    This problem is avoided for RMU Extract by adding the FORWARD_
    REFERENCES item to the command line:

    $ RMU/EXTRACT/ITEM=(ALL,FORWARD_REFERENCES) databasename/OUTPUT=script.SQL

    The script now contains a forward declaration of the function
    INTEREST_PAID so that execution of the script can succeed.

    SQL> declare function INTEREST_PAID (
    cont>     in    :AMT
    cont>         INTEGER (2))
    cont>     returns
    cont>         INTEGER (2)
    cont>     ;
    SQL>
    SQL> create domain MONEY
    cont>     INTEGER (2)
    cont>     check((INTEREST_PAID(value) > 0))
    cont>     not deferrable;
    SQL>
    SQL> commit work;
    SQL> create function INTEREST_PAID (
    cont>     in    :AMT
    cont>         MONEY
    cont>         by reference)
    cont>     returns
    cont>         MONEY by value
    cont>     language SQL;
    cont>     external
    cont>         language C
    cont>         parameter style GENERAL
    cont>     deterministic
    cont>     called on null input
    cont>     ;
    SQL> commit work;
Close Help