Can we declare a Cursor in Package Specs?

Dear buddies
Can I Declare a Cursor in Package Specs so that I can call that cursor and use its data in some procedures and functions of package. Otherwise I've to write that cursor for every sub-program of a package which I don't feel a smart way to accomplish the job.

Hi,
here is a short example with the whole way down. Maybe the concept is getting clearer with this:
first of all, if you do not have the table emp, here the DDL for this example.
Be carefull, works only for german clients because of the names of months, sorry for that.
CREATE TABLE EMP
(EMPNO NUMBER(4) NOT NULL,
ENAME VARCHAR2(10),
JOB VARCHAR2(9),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(7, 2),
COMM NUMBER(7, 2),
DEPTNO NUMBER(2));
set echo on
INSERT INTO EMP VALUES
(7369, 'SMITH', 'CLERK', 7902,
TO_DATE('17-DEZ-1980', 'DD-MON-YYYY'), 800, NULL, 20);
INSERT INTO EMP VALUES
(7499, 'ALLEN', 'SALESMAN', 7698,
TO_DATE('20-FEB-1981', 'DD-MON-YYYY'), 1600, 300, 30);
INSERT INTO EMP VALUES
(7521, 'WARD', 'SALESMAN', 7698,
TO_DATE('22-FEB-1981', 'DD-MON-YYYY'), 1250, 500, 30);
INSERT INTO EMP VALUES
(7566, 'JONES', 'MANAGER', 7839,
TO_DATE('2-APR-1981', 'DD-MON-YYYY'), 2975, NULL, 20);
INSERT INTO EMP VALUES
(7654, 'MARTIN', 'SALESMAN', 7698,
TO_DATE('28-SEP-1981', 'DD-MON-YYYY'), 1250, 1400, 30);
INSERT INTO EMP VALUES
(7698, 'BLAKE', 'MANAGER', 7839,
TO_DATE('1-MAI-1981', 'DD-MON-YYYY'), 2850, NULL, 30);
INSERT INTO EMP VALUES
(7782, 'CLARK', 'MANAGER', 7839,
TO_DATE('9-JUN-1981', 'DD-MON-YYYY'), 2450, NULL, 10);
INSERT INTO EMP VALUES
(7788, 'SCOTT', 'ANALYST', 7566,
TO_DATE('09-DEZ-1982', 'DD-MON-YYYY'), 3000, NULL, 20);
INSERT INTO EMP VALUES
(7839, 'KING', 'PRESIDENT', NULL,
TO_DATE('17-NOV-1981', 'DD-MON-YYYY'), 5000, NULL, 10);
INSERT INTO EMP VALUES
(7844, 'TURNER', 'SALESMAN', 7698,
TO_DATE('8-SEP-1981', 'DD-MON-YYYY'), 1500, 0, 30);
INSERT INTO EMP VALUES
(7876, 'ADAMS', 'CLERK', 7788,
TO_DATE('12-JAN-1983', 'DD-MON-YYYY'), 1100, NULL, 20);
INSERT INTO EMP VALUES
(7900, 'JAMES', 'CLERK', 7698,
TO_DATE('3-DEZ-1981', 'DD-MON-YYYY'), 950, NULL, 30);
INSERT INTO EMP VALUES
(7902, 'FORD', 'ANALYST', 7566,
TO_DATE('3-DEZ-1981', 'DD-MON-YYYY'), 3000, NULL, 20);
INSERT INTO EMP VALUES
(7934, 'MILLER', 'CLERK', 7782,
TO_DATE('23-JAN-1982', 'DD-MON-YYYY'), 1300, NULL, 10);2. Package Spec:
create or replace
package test_cursor as
  --Type for the returncode of the function
  TYPE typ_emp IS TABLE OF emp%rowtype;
  --Array for fetching, of course also possible in the body
  t_emp typ_emp;
  --function wich returns the array from fetching the cursor
  function get_emp return typ_emp;
  --function for manupilation data retrieved by the function
  PROCEDURE man_emp;
end test_cursor;3. Package Body
create or replace
package body test_cursor as
  FUNCTION get_emp RETURN typ_emp AS
  cursor c_emp is select * from emp;
  BEGIN
    open c_emp;
    fetch c_emp BULK COLLECT INTO t_emp;
    CLOSE c_emp;
    --t_emp returns the whole table set from emp
    return t_emp;
  end get_emp;
  PROCEDURE man_emp AS
  --just for not confusing names, is the same as t_emp of course
  v_emp_array typ_emp;
  BEGIN
    --call the function and retrieve the whole data set
    v_emp_array := get_emp;
    --now manipulate the data, in this case just write the names to the calling client
    FOR rec IN v_emp_array.FIRST .. v_emp_array.LAST
    loop
      dbms_output.put_line(v_emp_array(rec).ename);
    end loop;
  end man_emp;
end test_cursor;4. Calling the procedure
SET serveroutput ON
exec test_cursor.man_emp;5. And this is the result:
anonymer Block abgeschlossen
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLERPlease be aware, this is just for demonstration purpose, of course it makes no sense to display the names this way. But how to call a funktion returning arrays with datasets from fetching cursors is shown here.
Hth
Joerg

Similar Messages

  • Declaring private cursors in package header

    Hi.
    Im tunning a PLSQL package , and im having the following doubt.
    This package has alot of cursors declared in the package header, but the cursors are private. (called within the package only)
    Could the public functions from the package have a loss of performance by using those cursors? (should the private cursors be declared within the functions or at least inside package body?)
    Im kind of new with plsql, so please bare with me :) .
    Cheers.

    there's no performance loss.
    however, unless the cursors are to be accessible outside the package (which is what happens when they are declared in the spec (not header)), then there's no benefit either. if they are truely meant to be private, then you can remove them from the spec. and if you're wrong, and they are called from elsewhere, you'll find out soon enough.

  • How to declare a cursor with stored proc?

    Hi All,
    Can we declare a cursor with stored proc?
    For Example -
    CREATE PROCEDURE DDL_proc() LANGUAGE SQLSCRIPT AS
        CURSOR c_cursor1 (v_isbn VARCHAR(20)) FOR CALL SYS.GET_OBJECT_DEFINITION(<SCHEMA_NAME>, <TABLE_NAME>).;
         BEGIN
              FOR cur_row as c_cursor1 DO
              END FOR;
         END;
    Could you please have a look on the same?
    Thank you,
    Vijeesh

    Oracle PL/SQL also has a select into statement which is described in the same manual the link takes you to part of.
    select column_list
    into variable_list
    from table(s)
    where conditions
    The PL/SQL Users Guide is something you are going to want to have gone over cover to cover before you start converting because so that you make the best choices for how to rewrite the code: select into, explicit cursor, implicit cursor, for loop, simple loop, while loop, collections,bulk load, etc ....
    HTH -- Mark D Powell --

  • Can we declare trigger in package

    Hi
    Can we declare trigger in package specification and body of trigger in package body. If so just give me the syntax.
    Thanks

    No. Just think: trigger would be firing on what? :-)
    But you can call (packaged) procedure from trigger.

  • Wants Some Help About Package Spec

    Hi Friends,
    I developed one package spec in my Report.
    It has around 40 Ref Cursors.
    I created 40 Functions for those Ref Cursors.
    Right now all are in my Report at client end.
    At present the performance is very slow.
    Can i maintain these Package spec & Functions
    in data base side? If possible how ?
    If i maintain like that my performance is
    increases or not?

    You should be able to move those to the server. Read Chapter 6 in Oracle Report Documentation. Just click on topic "Documentation" on your left to find documentation on report.

  • Problem with "Package Spec" please help.

    Hello once again.
    I'm developing a master-detail form, so I'm using a "Package Spec" variable to hold the primary key value from the master form. The primary key value for the master is generated by a sequence.
    Here's the package spec:
    PACKAGE primary_keygen IS
    pkey varchar2(15); 
    END;Now the master table has the following "Before Insert" Trigger .
    CREATE OR REPLACE TRIGGER MASTER_NUM_GEN
    BEFORE INSERT
    ON MASTER
    FOR EACH ROW
    DECLARE
    primary_key_value varchar2(15);
    BEGIN
    select lpad(to_char(ref_gen.nextval), 4,'0')
    into primary_key_value from dual;
    primary_keygen.pkey:='ABC/'||primary_key_value;
    :new.Ref_Number:=primary_keygen.pkey;
    END;For the detail block. I have the following "Before Insert Trigger" to generate the primary key values.
    CREATE OR REPLACE TRIGGER DET1_NUM_GEN
    BEFORE INSERT
    ON DETAIL1
    FOR EACH ROW
    BEGIN
    if :new.M_ref_number is NULL THEN
    :new.M_ref_number:=primary_keygen.pkey;
    ENd if;
    END;Works quite fine if I have only one detail block. But if I have multiple detail blocks. Depending on the user's selection. i.e. After entering data into the master block, the user selects a detail block ('Letter type'- using stacked canvases for this purpose and radio buttons for selecting the view) and then Inserts data into it. here's what I do in the Detail block2.
    CREATE OR REPLACE TRIGGER OREF_NUM_GEN
    BEFORE INSERT
    ON DETAIL2
    FOR EACH ROW
    BEGIN
    if :new.O_ref_number is NULL THEN
    :new.O_ref_number:=pkey_gen.master_key;
    ENd if;
    END;Now the problem is that When I enter one record into detail1, works fine, but for the second time, when I try to insert another record. the master table gets a new reference number (primary key value) while the detail block gets the previous value that was used in the first record!, so that means 'pkey_gen.master_key' is holding the old value, while in my opinion it should hold the new value, I dont know whats wrong here. If I try to insert two consecutive records into the same detail table, I get an error saying "Unique Constraint voilated", becuase the variable is holding the old values.
    And lastly after it inserts the record into the database, I get a dialog box saying, "successfuly inserted 2 records into the database" and when I click ok, the Form closes by itself, any ideas on how to stop this?
    I'm really stuck here. Please help me out on this.
    Thanks.
    Note: I'm using Form6i with Database 10g.
    Message was edited by:
    fahimkhan82

    Hi,
    Maybe the best way to start is to try building a new form from scratch. For simplicity I will assume that you have one master and one detail table. Master table has a primary key and the detail table has a foreign key to the master. Based on this, with the forms you can create a database block based on your master table. Use the wizard. Again using the wizard, create a second block based on the detail table. You'll see a screen to prompt to create a relationship. Create one by selecting the master table and the right foreign key relation. Now take a close look to all triggers automatically created by the form. Also check the "Relations" object found in you master block object tree. Note that the foreight key column in the detail table has the "Copy Value From Item" property set to monitor the master block's primary key.
    This is the basic. You don't need the database triggers, except (in case you want to insert through, say, SLQPlus) the one for the master table, which will look like this:
    CREATE OR REPLACE TRIGGER MASTER_NUM_GEN
    BEFORE INSERT
    ON MASTER
    FOR EACH ROW
    BEGIN
    IF :new.ref_number IS NULL THEN
    select 'ABC/'||pad(to_char(ref_gen.nextval), 4,'0')
    into :new.ref_number
    from dual;
    END IF;
    END;
    Now you have to take care about the inserts in your form. Create PRE-INSERT trigger on the master block.
    IF :master.ref_number IS NULL THEN
    SELECT 'ABC/'||pad(to_char(ref_gen.NEXTVAL), 4,'0')
    INTO :master.ref_number
    FROM dual;
    END IF;
    Run the form and explore different situations to see how the form is keeping the data integrity.
    Compile with Shift+K (incremental). Sometimes forms blow just because not all of the trigers were compiled properly.
    Hope this helps...

  • Define userdefined types in package spec

    perfectly working userdefined in one schema when brought in to package spec of another schema give me an error:
    Error(26,6): PLS-00540: object not supported in this context.
    I am looking for some rules to follow when decalring types in a package specifications.
    Thank you

    See following section of PL/SQL User's Guide and Reference http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96624/10_objs.htm#4139
    that says:
    Currently, you cannot define object types in a PL/SQL block, subprogram, or package
    The list of types that can be created in a package specification seems to be:
    - subtype: http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96624/03_types.htm#3359
    - collections: http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96624/05_colls.htm#19661
    - record:
    http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96624/05_colls.htm#7543
    - ref cursor:
    http://download-uk.oracle.com/docs/cd/B10501_01/appdev.920/a96624/06_ora.htm#1554
    Not sure that this is the full list because I did not find a complete list in one PL/SQL document.
    Message was edited by:
    Pierre Forstmann

  • Reg: Package Spec and Body

    All,
    I am adding a function to an existing package. I have added the function code only in the package body and compiled. I have received the below error.
    PLS-00313: 'Fun_check' not declared in this scope
    Where as, I have declared the same function in the package specification, then no issues.
    So, my question is, Can't we add the function/procedure without the declaration of it inside the package specification.Because,I see,  there were many functions inside the same package body, which were not declared in the package specification.  What will happen,  if we declare the function/proc  inside the package spec and what if not.
    Thanks in advance.
    Thanks,

    EV259 wrote:
    PLS-00313: 'Fun_check' not declared in this scope
    For this error need to define the local programs before these being called by another program in package body.
    Check below example for giving proper scope to local program in package body.
    create or replace package p1
    as
    procedure p1;
    function f1 return number;
    end p1;
    create or replace package body p1
    as
    procedure p1
    is
    var number;
    begin
      null;
      var := f_l;  -- first:- calling local f_l before defining will throw error
    end;
    function f_l   --second:- defining local f_l
    return number
    is
    begin
         null;
      return 2;
    end;
    function f1
    return number
    is
    begin
       null;
       return 1;
    end;
    end p1;
    Warning: Package Body created with compilation errors.
    SQL> show err
    Errors for PACKAGE BODY P1:
    LINE/COL ERROR
    8/3      PL/SQL: Statement ignored
    8/10     PLS-00313: 'F_L' not declared in this scope
    ------ Now Creating scope for local function f_l through out pkg body by defining it first!
    create or replace package body p1
    as
    ------- can be called in any program below it
    function f_l
    return number
    is
    begin
         null;
      return 2;
    end;
    procedure p1
    is
    var number;
    begin
      null;
      var := f_l;
    end;
    function f1
    return number
    is
    begin
       null;
       return 1;
    end;
    end p1;
    Package body created.

  • Package Spec

    1. what is the purpose of creating bodyless package ? what are the advantages of creating like this ?
    2. what is the reason for using "CREATE OR REPLACE PACKAGE" instead of dropping and creating ?

    Balarenganathan wrote:
    1. what is the purpose of creating bodyless package ? what are the advantages of creating like this ?Here's one example of a user for creating a bodyless package...
    Packages tend to fail because of their "package state". A package has a "state" when it contains package level variables/constants etc. and the package is called. Upon first calling the package, the "state" is created in memory to hold the values of those variables etc. If an object that the package depends upon e.g. a table is altered in some way e.g. dropped and recreated, then because of the database dependencies, the package takes on an INVALID status. When you next make a call to the package, Oracle looks at the status and sees that it is invalid, then determines that the package has a "state". Because something has altered that the package depended upon, the state is taken as being out of date and is discarded, thus causing the "Package state has been discarded" error message.
    If a package does not have package level variables etc. i.e. the "state" then, taking the same example above, the package takes on an INVALID status, but when you next make a call to the package, Oracle sees it as Invalid, but knows that there is no "state" attached to it, and so is able to recompile the package automatically and then carry on execution without causing any error messages. The only exception here is if the thing that the package was dependant on has changes in such a way that the package cannot compile, in which case you'll get an Invalid package type of error.
    And if you want to know how to prevent discarded package states....
    Move all constants and variables into a stand-alone package spec and reference those from your initial package. Thus when the status of your original package is invlidated for whatever reason, it has no package state and can be recompiled automatically, however the package containing the vars/const will not become invalidated as it has no dependencies, so the state that is in memory for that package will remain and can continue to be used.
    As for having package level cursors, you'll need to make these local to the procedures/functions using them as you won't be able to reference cursors across packages like that (not sure about using REF CURSORS though.... there's one for me to investigate!)
    This first example shows the package state being invalided by the addition of a new column on the table, and causing it to give a "Package state discarded" error...
    SQL> set serveroutput on
    SQL>
    SQL> create table dependonme (x number)
      2  /
    Table created.
    SQL>
    SQL> insert into dependonme values (5)
      2  /
    1 row created.
    SQL>
    SQL> create or replace package mypkg is
      2    procedure myproc;
      3  end mypkg;
      4  /
    Package created.
    SQL>
    SQL> create or replace package body mypkg is
      2    v_statevar number := 5; -- this means my package has a state
      3
      4    procedure myproc is
      5      myval number;
      6    begin
      7      select x
      8      into myval
      9      from dependonme;
    10
    11      myval := myval * v_statevar;
    12      DBMS_OUTPUT.PUT_LINE('My Result is: '||myval);
    13    end;
    14  end mypkg;
    15  /
    Package body created.
    SQL>
    SQL> exec mypkg.myproc
    My Result is: 25
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        VALID
    SQL>
    SQL>
    SQL> alter table dependonme add (y number)
      2  /
    Table altered.
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        INVALID
    SQL>
    SQL> exec mypkg.myproc
    BEGIN mypkg.myproc; END;
    ERROR at line 1:
    ORA-04068: existing state of packages has been discarded
    ORA-04061: existing state of package body "SCOTT.MYPKG" has been invalidated
    ORA-06508: PL/SQL: could not find program unit being called: "SCOTT.MYPKG"
    ORA-06512: at line 1
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        INVALID
    SQL>
    SQL> exec mypkg.myproc
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        VALIDAnd this next example shows how having the package variables in their own package spec, allows the package to automatically recompile when it is called even though it became invalidated by the action of adding a column to the table.
    SQL> drop table dependonme
      2  /
    Table dropped.
    SQL>
    SQL> drop package mypkg
      2  /
    Package dropped.
    SQL>
    SQL> set serveroutput on
    SQL>
    SQL> create table dependonme (x number)
      2  /
    Table created.
    SQL>
    SQL> insert into dependonme values (5)
      2  /
    1 row created.
    SQL>
    SQL> create or replace package mypkg is
      2    procedure myproc;
      3  end mypkg;
      4  /
    Package created.
    SQL>
    SQL> create or replace package mypkg_state is
      2    v_statevar number := 5; -- package state in seperate package spec
      3  end mypkg_state;
      4  /
    Package created.
    SQL>
    SQL> create or replace package body mypkg is
      2    -- this package has no state area
      3
      4    procedure myproc is
      5      myval number;
      6    begin
      7      select x
      8      into myval
      9      from dependonme;
    10
    11      myval := myval * mypkg_state.v_statevar;  -- note: references the mypkg_state package
    12      DBMS_OUTPUT.PUT_LINE('My Result is: '||myval);
    13    end;
    14  end mypkg;
    15  /
    Package body created.
    SQL>
    SQL> exec mypkg.myproc
    My Result is: 25
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        VALID
    SQL>
    SQL> alter table dependonme add (y number)
      2  /
    Table altered.
    SQL>
    SQL> select object_name, object_type, status from user_objects where object_name = 'MYPKG'
      2  /
    OBJECT_NAME
    OBJECT_TYPE         STATUS
    MYPKG
    PACKAGE             VALID
    MYPKG
    PACKAGE BODY        INVALID
    SQL>
    SQL> exec mypkg.myproc
    My Result is: 25
    PL/SQL procedure successfully completed.The other uses are of course that you just want to create a load of type definitions etc. to be used by multiple packages elsewhere. ;)
    2. what is the reason for using "CREATE OR REPLACE PACKAGE" instead of dropping and creating ?What's the reason for dropping and recreating when you've got the option to create or replace? ;)

  • How can I replace the cursor in the below query?

    I have this below query which calls a stored procedure that takes only 1 item's attributes at a time. But because of performance problems we are
    required to remove the cursor. How can I replace the below cursor logic with set operations or CTE? Please advice.
    DECLARE db_cursor_ava CURSOR
    FOR
    SELECT t.[agent-id],
    t.[start-date],
    t.[end-date],
    t.[monitor-days],
    t.[monitor-start],
    t.[monitor-end],
    t.[timezone-offset]
    FROM @tmpAgentPeriodTimeRange t
    OPEN db_cursor_ava
    FETCH NEXT FROM db_cursor_ava INTO @agentID_ava,
    @stDateTime_ava,
    @endDateTime_ava,
    @monDays_ava,
    @monSt_ava,
    @monEnd_ava,
    @offset_ava
    WHILE @@FETCH_STATUS = 0
    BEGIN
    DELETE
    FROM @tmpMonitorPeriod
    DELETE
    FROM @tmpFinalResult
    SET @runID = 1
    IF(@endDateTime_ava>DATEADD(MI,@offset_ava, GETUTCDATE()))
    BEGIN
    SET @endDateTime_ava=DATEADD(MI,@offset_ava, GETUTCDATE())
    END
    INSERT INTO @tmpMonitorPeriod
    EXEC core.usp_GetMonitoringPeriod
    @startDate = @stDateTime_ava,
    @endDate = @endDateTime_ava,
    @monitoringDays = @monDays_ava,
    @monitoringStart = @monSt_ava,
    @monitoringEnd = @monEnd_ava
    SELECT @maxID = MAX(tm.id)
    FROM @tmpMonitorPeriod tm
    FETCH NEXT FROM db_cursor_ava INTO @agentID_ava,
    @stDateTime_ava,
    @endDateTime_ava,
    @monDays_ava,
    @monSt_ava,
    @monEnd_ava,
    @offset_ava
    END
    CLOSE db_cursor_ava
    DEALLOCATE db_cursor_ava
    mayooran99

    You've been down this path before  - and the response is exactly the same.
    how to replace cursor logic
    And I'll suggest that you post the entire code - since you repeatedly delete 2 table variables but only populate one. The setting of @maxID also seems to have no purpose. And perhaps the issue here isn't the cursor but the general approach.  Who knows
    - but it appears you may have prematurely assumed that the cursor is the problem.

  • Schema name not present on filename for "Save Package Spec and Body"

    In versions previous to 3.0 EA, the filename defaulted to schema.object.sql when using the "Save Package Spec and Body" on the right click of the package/body. This appears to have disappeared. Also, it now defaults to the .PLS ext/type, which I prefer to save them as .SQL (which i can override, but it would be nice in the file type dropdown). Also, I had posted a suggestion about the actual file not including the schema name prefixing the object name when using the "Save Package Spec and Body". i.e. it does create or replace package reader_package instead of what it should be doing which is create or replace package schema.reader_package

    Would be nice indeed having the real name as default, and all supported PL/SQL types (as in the preferences) in the extensions dropdown.
    As for the schema name inside, I reckon that would do damage for more users than it would do good for others. But a preference would be best of course.
    K.

  • Query: Can we write Triggers in a Packages??

    Hi Al

    Triggers provide a way of executing PL/SQL code on the occurrence of specific database events. For example, you can maintain an audit log by setting triggers to fire when insert or update operations are carried out on a table. The insert and update triggers add an entry to an audit table whenever the table is altered.
    The actions that Informix Dynamic Server triggers perform are constrained to multiple insert, update, delete, and execute procedure clauses; whereas, Oracle allows triggers to execute arbitrary PL/SQL code. Oracle triggers are similar to stored procedures in that they can contain declarative, execution, and exception handling code blocks.if you mean trigger call package, yes!
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7004.htm
    Edited by: Surachart (HunterX) on Jun 14, 2009 8:46 PM

  • Report cannot access pl/sql table variable defined in Package Spec.

    Hi,
    I've created a package spec called pkg_report with a PL/SQL table variable defined called body_text_table. When I tried to compile the following code under the Before Report trigger:
    :desc := pkg_report.body_text_table(1);
    Oracle gave me the following error:
    Implementation Restriction: 'PKG_REPORT.BODY_TEXT_TABLE': Cannot directly access remote package variable or cursor.
    Does anyone have any idea about this error? Thank you for your time at looking at it.
    Regards,
    John

    You cannot directly access the package variable in a database package. The work around is to create a set_variable and get_variable wrapper function in the package body. See Metalink note 105838.1 for more info.
    A simple example:
    create or replace package my_package as
      my_var     number;
      function   get_variable return number ;
      procedure  set_variable (p_value in number) ;
    end ;
    create or replace package body my_package as
      function get_variable return number is
      begin
        return my_var;
      end ;
      procedure set_variable(p_value in number) is
      begin
        my_var := p_value ;
      end ;
    end;

  • USING SEQUENCE IN PACKAGE SPEC

    I Want to Use Sequence.NEXTVAL & Sequence.CURRVAL throughout the package. How can i declare the global sequence variable and make them available for all the stored procedures inside the package ?
    Any help highly appreciated..
    Thank you all in advance

    Data Boy wrote:
    No i know that but using directly SEQUENCE.CURRVAL inside the Insert statement is not a good practice.
    We need to declare inside the procedure a variable and then fetch the SEQUENCE.CURRVAL into that variable
    and use that variable inside the insert statement. But we that variable scope will be available only inside that procedure.
    if i want the same CURRVAL in another stored procedure. How can i get it ..that is my Question.What exactly are you trying to achieve?
    If it's a case of needing to know the value of the sequence number assigned to an inserted record you would typically use the RETURNING clause on the insert statement...
    SQL> create table temp (id number, val varchar2(20));
    Table created.
    SQL> create sequence temp_seq;
    Sequence created.
    SQL> ed
    Wrote file afiedt.buf
      1  create trigger trg_temp before insert on temp
      2  for each row
      3  begin
      4    select temp_seq.nextval into :new.id from dual;
      5* end;
    SQL> /
    Trigger created.
    SQL> set serverout on
    SQL> declare
      2    v_num number;
      3  begin
      4    insert into temp (val) values ('Fred') returning id into v_num;
      5    dbms_output.put_line('ID inserted was: '||to_char(v_num));
      6  end;
      7  /
    ID inserted was: 1
    PL/SQL procedure successfully completed.
    SQL> select * from temp;
            ID VAL
             1 Fred
    SQL>

  • Copying Packaging Spec

    When I am copying packaging spec, the fields  'Category', 'Sub-Category' & 'Group' are getting copied over, however the fields under 'Available UOM', 'UOM Conversions' and Cross Reference' are not getting copied, whether I choose to keep the copied Spec linked to the Template or not. [Both the Spec copied from and the Template used has those UOM/Cross reference fields defined] . Aren't those UOM/Cross reference fields suppose to be copied over to the new Spec?  When I create a new Spec from Template, system brings over all fields [UOM/Cross reference etc.] from Template, so I was expecting the same behavior while copying too, since I am linking to the Template during the copying process. Can someone shed some light on this issue please?

    I believe that the functional use cases are different. When you are copying from a Template, you are not copying a real existing specification - rather, you are creating a spec with values that should be there by default. These values from a template are typically not meant to be specific to one single specification, but rather to a grouping/classification of specs. Perhaps a Beverage type specification, created from a Beverage template, would have certain Available UOMs that a Sauce specification would not. Cross References on a template may be used for pack size purposes, which may also be specific to a template.
    When you copy an existing specification, the assumption is that the specification is linked to some external system(s) using the cross references - if those were copied over, you could have an possible discrepancy. Also, since you are doing a copy and not a new revision, we assumed the UOM info would be different so is is cleared out.

Maybe you are looking for

  • [SOLVED]Gnome 3 / Nautilus removable devices doesn't automount anymore

    I use Gnome3 with gnome-shell and openbox. Recently on nautilus my other partitions and removable devices does not show up. I can see the partitions on the terminal and mount them manually but i need to fix this. Please help. Last edited by kanine5 (

  • TAB SEPARATED instead of COMMA SEPARATED

    Hi everybody, I need to generate a Comma Separated File with reports 9i. As I read here on OTN I defined Destination Format as DELIMITEDDATA and I tried DELIMITED. In the first try, report builder crashed instantly and in the latter try, report build

  • Sysid and client of caller for EJB Jco function

    Hello, I'm trying to identify the sender system and client (ABAP) for a processFunction call implemented as ejb (with JCO interface). Does someone knew a method to access caller information from the processFunction call? Regards, Frank

  • Copy the value from one item into another

    Hi, I have a page with 2 items on it: Field1 and Field2. When the user enters a value in Field1 and tabs out, I want to copy the value to Field2. I have changed the setField1 method in the VORowImpl to call setField2 passing in the same value. In the

  • Folders do not appear on Pla

    New to MP3 readers. I purchased a Zen Nano today. Using Windows Explorer, I created two folders on the F: dri've (which is the player), and moved several music files into the 'music' folder and several podcasts into the 'podcast' folder. I verified t