Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2006
    Posts
    4

    Question Unanswered: forward reference to a procedure in a package

    hi
    I just want to know how can we forward reference a procedure that is called in a package body.

    code --

    create or replace package test as
    procedure main;
    end test;

    create or replace package body test as

    procedure main is
    being
    validdata;
    printdata;
    end main ;
    end test;

    note : valid data and print data are two procedures that are to be declared outside the package body


    thanking you

    pavan kumar n bhaskara

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    As far as I know, forward reference is not allowed in PL/SQL. You can, of course, create dummy functions/procedures and complete them later. Syntax would then be like this:
    Code:
    CREATE OR REPLACE PROCEDURE validdata
    IS
    BEGIN
      NULL;
    END validdata;

  3. #3
    Join Date
    May 2004
    Location
    Dominican Republic
    Posts
    721
    I never ever worry about that actually. Why ? well, because as soon as you call the function/procedure in the package it will get validated if you have previously defined it.
    Code:
    SQL> create or replace package test is
      2     procedure test;
      3  end;
      4  /
    
    Package created.
    
    SQL> create or replace package body test is
      2     procedure test is
      3     begin
      4             foobar;
      5     end;
      6  end;
      7  /
    
    Warning: Package Body created with compilation errors.
    
    SQL> show err
    Errors for PACKAGE BODY TEST:
    
    LINE/COL ERROR
    -------- -----------------------------------------------------------------
    4/3      PLS-00201: identifier 'FOOBAR' must be declared
    4/3      PL/SQL: Statement ignored
    ... so what ?
    Code:
    SQL> create or replace procedure foobar is
      2  begin
      3     null;
      4  end;
      5  /
    
    Procedure created.
    
    SQL> exec test.test
    
    PL/SQL procedure successfully completed.
    
    SQL>
    Anyway, I can see this only done with functions..
    Code:
    SQL> create or replace package test is
      2     procedure test;
      3  end;
      4  /
    
    Package created.
    
    SQL> create or replace package body test is
      2          procedure test is
      3                  l_number        pls_integer;
      4          begin
      5                  execute immediate 'select foobar() from dual' into l_number;
      6                  dbms_output.put_line( l_number );
      7          end;
      8  end;
      9  /
    
    Package body created.
    
    SQL> create or replace function foobar return number is
      2  begin
      3     dbms_output.put_line( 'This is foobar' );
      4     return 1;
      5  end;
      6  /
    
    Function created.
    
    SQL> set serveroutput on
    SQL> exec test.test
    This is foobar
    1
    
    PL/SQL procedure successfully completed.
    
    SQL>
    mm.. for some reason, dbms_application_info.set_client_info didn't work inside of foobar.. which leads me to believe the procedure itself does commit, to send this information to v$session.. can anyone ellaborate more on this ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •