DB Trigger: select from and into current table

I'm running 8.0.5 and facing a table looking like MYTAB(RECID,RECLABEL,..., PARENTRECID, PARENTRECLABEL) where:
. RECID = current record UID (say: employee number)
. RECLABEL = current record label (say: employee name)
. PARENTRECID = RECID of another record in table MYTAB (say: employee ID of the manager of the current employee)
. PARENTRECLABEL = must be made to hold automatically the contents of RECLABEL in the parent record (say: the name of the manager of the current employee)
I know an easy way to get this info would be to use a view like CREATE VIEW MYVIEW AS SELECT A.RECID, A.RECLABEL, A.PARENTRECID, B.RECLABEL "PARENTRECLABEL" FROM MYTAB A, MYTAB B WHERE A.PARENTRECID=B.RECID but for various reasons I would really love to denormalize that info into column PARENTRECLABEL using a database trigger.
Obviously, table MYTAB itself cannot be selected from during the execution of the dB trigger: mutating table error !
I tried:
. to select from a view defined as "SELECT * FROM MYTAB" as suggested in another thread, but this trick didn't seem to be sufficient to lure Oracle (it still says I'm trying to select from a mutating table !)
. to use a package within which a PL/SQL table variable is filled with the list of affected RECID on a FOR EACH ROW basis, and to issue updates in a after statement (thus: not AFTER EACH ROW) AFTER UPDATE trigger - but it's too late already and those updates are apparently not taken into account by the database.
Any other suggestions?
Thx - Didier

Here's the code, if the formatting in unpreserved please do let me I'll mail the same.
The Package
CREATE OR REPLACE PACKAGE save_table_package
AS
TYPE saved_test2_type
IS TABLE OF test2%ROWTYPE
INDEX BY BINARY_INTEGER;
saved_test2 saved_test2_type;
saved_test2_num NUMBER:= 1;
PROCEDURE save_test2_row(i_id NUMBER
,i_ename VARCHAR2
,i_mgr_id NUMBER
,i_mgr_ename VARCHAR2
PROCEDURE clear_rows;
END save_table_package;
show err
CREATE OR REPLACE PACKAGE BODY save_table_package AS
PROCEDURE save_test2_row(i_id NUMBER
,i_ename VARCHAR2
,i_mgr_id NUMBER
,i_mgr_ename VARCHAR2
IS
BEGIN
DBMS_OUTPUT.PUT_LINE('Enter pkg.save_test2_row:'| |TO_CHAR(save_table_package.saved_test2_num,'099999'));
save_table_package.saved_test2(saved_test2_num).id := i_id;
save_table_package.saved_test2(saved_test2_num).ename := i_ename;
save_table_package.saved_test2(saved_test2_num).mgr_id := i_mgr_id;
save_table_package.saved_test2(saved_test2_num).mgr_ename := i_mgr_ename;
DBMS_OUTPUT.PUT_LINE('Saved Details Of Row ###:' | |
TO_CHAR(save_table_package.saved_test2_num,'099999') | |'('| |
TO_CHAR(save_table_package.saved_test2(saved_test2_num).id,'099') | |','| |
save_table_package.saved_test2(saved_test2_num).ename | |','| |
save_table_package.saved_test2(saved_test2_num).mgr_id | |','| |
save_table_package.saved_test2(saved_test2_num).mgr_ename | |')'
save_table_package.saved_test2_num := save_table_package.saved_test2_num + 1;
DBMS_OUTPUT.PUT_LINE('Leave pkg.save_test2_row:'| |TO_CHAR(save_table_package.saved_test2_num,'099999'));
END save_test2_row;
PROCEDURE clear_rows IS
BEGIN
DBMS_OUTPUT.PUT_LINE('Enter pkg.clear_rows :'| |TO_CHAR(save_table_package.saved_test2_num,'099999'));
save_table_package.saved_test2_num := 1;
DBMS_OUTPUT.PUT_LINE(' Leave pkg.clear_rows :'| |TO_CHAR(save_table_package.saved_test2_num,'099999'));
END clear_rows;
END save_table_package;
show err
The Triggers
CREATE OR REPLACE TRIGGER trig_bfr_iup_test2_fer
BEFORE INSERT OR UPDATE OF mgr_id ON test2 FOR EACH ROW
DECLARE
BEGIN
DBMS_OUTPUT.PUT_LINE('Enter before insupd:'| |TO_CHAR(save_table_package.saved_test2_num,'099999'));
save_table_package.save_test2_row(:new.id
,:new.ename
,:new.mgr_id
,:new.mgr_ename);
DBMS_OUTPUT.PUT_LINE('Leave before insupd:'| |TO_CHAR(save_table_package.saved_test2_num,'099999'));
END;
show err
CREATE OR REPLACE TRIGGER trig_aft_iup_test2_stm
AFTER INSERT OR UPDATE OF mgr_id ON test2
DECLARE
BEGIN
DBMS_OUTPUT.PUT_LINE('Enter after insupd:'| |TO_CHAR(save_table_package.saved_test2_num,'099999'));
FOR i IN 1 .. save_table_package.saved_test2_num - 1
LOOP
UPDATE test2 eme
SET mgr_ename = (SELECT mgr.ename
FROM test2 mgr
WHERE mgr.id = eme.mgr_id)
WHERE eme.id = save_table_package.saved_test2(i).id
DBMS_OUTPUT.PUT_LINE('MGR_ENAME Set Row#:'| |TO_CHAR(i,'099999'));
END LOOP;
save_table_package.clear_rows;
DBMS_OUTPUT.PUT_LINE('Leave after insupd:'| |TO_CHAR(save_table_package.saved_test2_num,'099999'));
END;
show err
null

Similar Messages

  • Problems pasting pie chart from Numbers into Pages table

    Hello,
    I'm trying to paste a pie chart from Numbers into a table cell in Pages 09 but it doesn't allow me. Would you know why?
    Thanks,
    Pedro

    Probably because it is a smart object connected back to the Numbers document.
    If you want it purely as a graphic, try copying the chart in Numbers switching to Preview.app and going command n which will make it a pdf file, then copy that and paste that into Pages. But it will no longer be a live chart.
    Peter

  • Difference between 'Selections from' and 'Search helps' in some HR program

    Hi,
    I notice at the top portions of some programs like Payroll Driver and pre-DME program there's two separate pushbuttons, 'Selections from' and 'Search helps'. What's the diff between the two?
    Because to me, both seem to have same functionality, i.e. to further filter the records.
    When I create customized programs, usually I use logical database pnp, and by that, we are adding 'Selections from' at the selection screen to help further select.
    So my questions:
    1. Why is there another button to help filter? Since both have same functionality to filter.
    2. What's the diff between the 2?
    3. Can somebody confirm the 'Search helps' is really for filtering?
    Thank you.

    Hi,
    If this spool is being generated internal to your program, then sy-spono should have the value.
    Regards,
    Lijo Joseph

  • To fetch selective fields from DATABASETABLE into Internal TABLE

    Hi Friends,
    I have declared an internal table with fields for e.g. A , B , C , D.
    This does not have any records as of now.
    I have to fetch data from a DATABASE TABLE with fields A , B , X , Y , Z having records .
    I only need records for fields A B fron DB table.Can any one pls tell how can I do that with performance issues in mind as lots of records are there.
    I had written a query where:
    SELECT A B from dbtab
                        into CORRESPONDING FIELDS of table it_table.
    It_table i had defined with only two fields A B.
    Is this correct?
    Please tell wats the way to do it as I am new to ABAP.
    THANKS in ADVANCE..

    Hi.....
    What mentioned in all above answers is very helpful for ur requirement...
    and...
       Here some Steps to increase the performence of your programs...
    >Use Select Single when only one row is expected
    >Use Select Where rather than Selectu2026Check
    >Use Select with aggregate functions (SUM, MAX, MINu2026)
    >Use a View instead of nested Selects
    >Use Select column specific instead of select * for few fields
    >Use Selectu2026Into Table rather than Select...Move Corru2026Apend
    >Use Join extension with Select if possible
    >Use special operators (CO, CA, CS) rather than code your own
    >Use Delete Adjacent Duplicates rather than manual processing
    >Specify key fields for Readu2026Binary Search
    >Use Loop At Where rather than Loop Atu2026Check
    >Copy Internal Tables with TAB_DEST() = TAB_SRC()
    >Specify the sort key as restrictively as possible
    >Use Append To, Insert Into, Collect Into rather than Move
    >Compare tables with If Tab1() = Tab2()u2026
    >Use Delete ITAB Whereu2026 instead of Loop At ITAB Whereu2026Delete..
    >Use Case statements instead of If-constructions
    >Use Call Functions wisely, Performs use less memory
    >Use While instead of Do Exit
    >Use Type I for Indices
    >Keep Occurs clause realistic or use 0
    >Use COMMIT WORK as appropriate to free the Data Base and preserve work
    >
    >Avoid:
    >Using Shift inside a While-loop
    >Leaving unneeded declarations in your program
    >Using Move-corresponding for just a few fields
    >Excessive nested includes within function calls
    >Using DB field names if the value will be changed
    >Using Occurs clause if only the header is needed
    Thanks,
    Naveen.I

  • Insertion of records from view into a table

    hello Friends,
    I have a view LGR is build on 12 table,this view has over 1 millon records, now when i run reports based on this view are so much slower, for speeding up reports i create a table LGRT and base all the reports on it, but the problem is that after any chage to the data of the LGR view , I delete all records from LGRT table and reinsert all records from LGR view
    delete from lgrt;
    insert into lgrt
    select *
    from lgr
    friends its a very long procedure what can i do to minimaze the human work.....
    i mean that it should be done automatically.

    Hello,
    It sounds like you could use a materialised view here to speed things up, also it will save you the hassle of deleting records from the temporary table etc as they offer quite a few synchronisation options. Have a look at the documentation here:
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_63a.htm#SQLRF01302
    There a quite a few examples toward the bottom of the page.
    HTH

  • Select from multiple entries in table cell.

    Hi All,
    I'm having issues when trying to do a simple select from an access database:
    <CFQUERY NAME="GetAllByMonth" DATASOURCE="dsn">
    SELECT * FROM table WHERE  strMonth = '#url.strMonth#' AND strDisplay = Yes
    order by strOrder_id
    </CFQUERY>
    Table cells in rows contain coma separated values:
    January, February, March, April, May, June, October, November, December
    Unfortunately the query returns no values. I've tried changing the "=" with "like", "contains" but with no results.
    Difficult to know what to search for so any help gratefully recieved.
    Ta
    Trevor

    Here is an absolutely crazy "hack" that I once used when dealing with a database like that.  It had hundreds of thousands of rows with comma separated values that for various legacy could not be changed.
    So one day I did this ...  SELECT DISTINCT column_from_purgatory FROM table_from_hell.
    Much to my surprise, there were less than a hundred DISTINCT values in that column.  (They were, fortunately, reasonably-sized VARCHARs.)
    So I built a table of those values, then created a separate table into which I could put each of the comma-separated parts, and then wrote a small (Perl) script to populate the two.  For example, a row containing "January, March, April" would be linked to three rows containing one month-name each.
    Now, as long as I had a way to be sure that this pair of lookup-tables was always complete (which was slightly problematic), I had something that I could actually JOIN to.  It wasn't pretty ... in fact, it was butt-ugly ... but it saved a tremendous amount of processing time for this application.

  • Regarding passing selection screen values into internal table

    Hi,
    I have created one selection screen with fields
    <b>POSNR LIKE VBAP-POSNR</b>
    <b>SELECT-OPTIONS: s_posnr FOR vbap-posnr.</b>
    I had created one internal table as:
    <b>DATA: BEGIN OF i_item OCCURS 0,
            posnr     LIKE vbap-posnr,
          END OF i_item.</b>
    Now what i want is to pass what ever entries available in <b>s_posnr into i_item</b> internal table.
    If user gives 10 in select-screen i_item should have 10,
    If user gives 10 to 30 in select-screen i_item should have 10,20,30 entries.
    If user gives nothing in s_posnr of selection screen
    then i_item should have all the valid item no's[POSNR's]
    from respective sales order.
    Can anybody tell me how can i solve this issue!
    Thanks in advance.
    Thanks & Regards,
    Prasad.

    Hi Prasad,
    I guess somewhere on your selection screen there is also a parameter for sales order (eg. pa_vbeln)?
    Then:
    SELECT posnr
          FROM vbap
          INTO TABLE i_item
         WHERE vbeln EQ pa_vbeln
           AND posnr IN s_posnr.
    Will get all position numbers in your internal table.
    Regards,
    John.

  • How to control the number of rows selected from a sybase database table?

    Hi, JDBC guru,
    I'm working on project using Sybase 11.9.x database.We need to process a record in a table,first select it from the table,then do some computing,finally write it to a dbf file, if the above steps succeed,remove the original row in the table.Quite evidently, all these operation should be put into one transaction. But how can I select just a number of rows from the sybase database table?
    Any hints?
    Thank you in advance.
    Regards,
    Jusitne

    Statement stmt...
    stmt.setMaxRows(20);

  • Parse XML Elements/Attributes from CLOB into Oracle Table

    Hi!
    I have an XML file (loaded into a CLOB) which I need to parse and have each individual element and attribute inserted into an oracle table for manipulation.
    Eg: XML File...
    <PERSON>
    <PER_ID changed="1">1</PER_ID>
    <SURNAME changed="1">MARTIN</SURNAME>
    <ADDRESS>
    <STREET_NO changed="1">1</STREET_NO>
    <POSTCODE changed="1">LE3 8RA</POSTCODE>
    </ADDRESS>
    </PERSON>
    There will only ever be one address.
    From this I need to extract
    * PER_ID and related changed attribute
    * SURNAME and related changed attribute
    * STREET_NO and related changed attribute
    * POSTCODE and related changed attribute
    and insert a single record into the table below:
    CREATE TABLE PERSON AS
    ( PER_ID VARCHAR2(10)
    , ID_CHANGED VARCHAR2(1)
    , SURNAME VARCHAR2(30)
    , ID_CHANGED VARCHAR2(1)
    , STREET_NO VARCHAR2(5)
    , ID_CHANGED VARCHAR2(1)
    , POSTCODE VARCHAR2(10) );
    Any assistance/advice would be very much appreciated. I've tried using DBMS_XMLSave / DBMS_XMLStore which works great at pulling in elements (PER_ID, SURNAME, etc) straight into the table but doesn't look at the changed attributes, and I need both.
    Thanks a million in advance to anyone who can crack this!!
    Jay

    Try looking at this thread
    Loading datafrom a PL/SQL table into the Database table

  • Import only the rows of emp table from Test into emp table of Prod

    hi,
    Test Instance:
    =========
    I have a table "emp". I want to take export of it.
    Prod Instance:
    =========
    Table with name "emp" already exists.
    I want to import only the rows of emp table from Test Instance into emp table of Prod Instance.
    regards,
    charan

    Charan,
    Set the import command IGNORE=Y
    Importing into Existing Tables
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14215/exp_imp.htm#i1023662
    Regards,
    Hussein

  • Selecting from a view when tables are in more than one schema problem

    I give up where am I missing it. Why is the ORA-01031 error being generated on the view u1.bv1. In testing even if I give object access to u3 I still get the same errors:
    SQL>
    SQL> drop user u1 cascade;
    drop user u1 cascade
    ERROR at line 1:
    ORA-01918: user 'U1' does not exist
    SQL> drop user u2 cascade;
    drop user u2 cascade
    ERROR at line 1:
    ORA-01918: user 'U2' does not exist
    SQL> drop user u3 cascade;
    drop user u3 cascade
    ERROR at line 1:
    ORA-01918: user 'U3' does not exist
    SQL> drop role aRole;
    drop role aRole
    ERROR at line 1:
    ORA-01919: role 'AROLE' does not exist
    SQL>
    SQL>
    SQL> select user from dual;
    USER
    SYS
    1 row selected.
    SQL>
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
    PL/SQL Release 10.2.0.1.0 - Production
    CORE     10.2.0.1.0     Production
    TNS for Solaris: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    5 rows selected.
    SQL>
    SQL> create user u1 identified by u1 default tablespace users
    2 quota unlimited on users;
    User created.
    SQL>
    SQL> create user u2 identified by u2 default tablespace users
    2 quota unlimited on users;
    User created.
    SQL>
    SQL> create role aRole;
    Role created.
    SQL>
    SQL> create user u3 identified by u3 default tablespace users;
    User created.
    SQL>
    SQL> grant aRole to u3;
    Grant succeeded.
    SQL>
    SQL> alter user u3 default role all;
    User altered.
    SQL>
    SQL> grant create session to u3;
    Grant succeeded.
    SQL>
    SQL> create table u1.t1(c1 number);
    Table created.
    SQL>
    SQL> create table u2.t1(c1 number);
    Table created.
    SQL>
    SQL> grant select on u2.t1 to u1;
    Grant succeeded.
    SQL>
    SQL> create or replace view u1.bv1 as
    2 select u1.t1.c1 as c1 ,u2.t1.c1 as c2
    3 from u1.t1, u2.t1 where u1.t1.c1 = u2.t1.c1;
    View created.
    SQL>
    SQL> grant select on u1.bv1 to aRole;
    Grant succeeded.
    SQL>
    SQL> create or replace view u1.gv1 as select * from u1.t1;
    View created.
    SQL>
    SQL> grant select on u1.gv1 to aRole;
    Grant succeeded.
    SQL>
    SQL> connect u3/u3
    Connected.
    SQL>
    SQL> select * from u1.bv1;
    select * from u1.bv1
    ERROR at line 1:
    ORA-01031: insufficient privileges
    SQL>
    SQL> select * from u1.gv1;
    no rows selected
    SQL>
    SQL> spool off

    User u1 cannot do a grant on a view to other user if the view uses tables from other schemas unless you do a "with grant option" grant.
    You need to do the following to make it work:
    SQL> grant select on u2.t1 to u1 with grant option;
    Grant succeeded.
    SQL>

  • Inserting multiple selection from checkbox into one column of the database

    Hi,
    How to insert multiple selection values from checkbox into one column of the database.
    Anyone can u help me
    Thanx

    hi
    try to use request.getParameterValues("fieldname")

  • Select from dual  into a variable through db links

    HI,I need to select value of current_timestamp in to a variable d1 of a remote database inside function.
    function (db_lnk varchar2)return number
    as
    dbl varchar2(10);
    begin
    dbl:=db_lnk;
    select current_timestamp into d1 from dual@dbl;
    end;
    but getting error table or v iew does not exist.
    if i do
    select current_timestamp into d1 from dual@'||dbl||';
    then it says database link name expected.
    How to achieve this?
    Thanks

    Peter Gjelstrup wrote:
    Foreign languages, foreign languages :-){noformat}*grins*{noformat} I know - and your English is miles better than my Danish (I'm assuming - hopefully correctly?! - that that's your 1st language based on your location!) which I don't even know any words of! *{:-)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Select from a dynamically chosen table

    Hi everyone,
    I'm willing to retrieve information stored in a given column of a given table, both generated dynamically. Thus, I have a string S1 with the table name and a string S2 with a column name of this table.
    My aim would be to do something like that :
    +select single * into corresponding fields of X
    from (S1)
    where Y = 'SomeValue'.+
    X being like a line of the table (S1)
    Y being the column name stored in S2.
    But for this, I need to fine a correct way to define X and Y from S1 and S2, which I failed to do until now. My first idea was to use field-symbols but it didn't help me. It might be quite easy or maybe impossible, I don't even know as my knowledge in ABAP is far from being excellent, but any reply would be welcome.
    Best regards,
    François

    Hi,
    if you only want to select only the given column(s)
    (here 'BUTXT') use the 2nd alternative:
    REPORT  YMI_SG_NACHWEIS_A NO STANDARD PAGE HEADING.
    FIELD-SYMBOLS:
    <t001>, <fs>.
    DATA:
    lr_t001 TYPE REF TO data.
    CONSTANTS:
    s1(30) VALUE 'T001',
    s2(30) VALUE 'BUKRS',
    s3(30) VALUE 'BUTXT'.
    DATA:
    lt_where(72) OCCURS 0 WITH HEADER LINE,
    lt_field(72) OCCURS 0 WITH HEADER LINE.
    append s3 to lt_field.
    CREATE DATA lr_t001 TYPE (s1).
    ASSIGN lr_t001->* TO <t001>.
    ASSIGN (s1) TO <fs>.
    CONCATENATE s2 '=' '3000' INTO lt_where SEPARATED BY space.
    APPEND lt_where.
    SELECT *
    INTO <t001>
    FROM (s1)
    WHERE (lt_where).
      ASSIGN COMPONENT s3 OF STRUCTURE <t001> TO <fs>.
      WRITE: / s3, ': ', <fs>.
    ENDSELECT.
    *2nd alternative
    skip 2.
    write:/'2nd'.
    uline.
    select (lt_field) into corresponding fields of <t001>
    FROM (s1)
    WHERE (lt_where).
      ASSIGN COMPONENT s3 OF STRUCTURE <t001> TO <fs>.
      WRITE: / s3, ': ', <fs>.
    ENDSELECT.
    grx
    Andreas

  • Returning a selection from a list or table

    I'm looking for a nice way to present the selcted value of a JList or a JTable to the rest of the program. So far the only thing I know to do is make the selection a static variable of the class implementing the ListSelectionListener interface. For instance, in the code below, I would make the variable rowNum a static variable, accessible from outside. But OO says to make it a method like public int getSelection(){return rowNum}i've had difficulty extracting the selection and making it available where it is really needed, in the business logic of the program. Any comments would be appreciated.class TablePanel extends JPanel
      ConnectionHandler ch;
      static TheTableModel tm;
      ListSelectionHandler selector;
      TablePanel(ConnectionHandler ch)
        this.ch = ch;
        tm = new TheTableModel();
        JTable jt = new JTable(tm);
        //selection mechanics
        jt.setPreferredScrollableViewportSize(new Dimension(900,200));
        ListSelectionModel rowSM = jt.getSelectionModel();
        selector = new ListSelectionHandler();
        rowSM.addListSelectionListener(selector);
        jt.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        //set column widths
        TableColumn column = null;
        for (int i = 0; i<9;i++)
          column = jt.getColumnModel().getColumn(i);
          if(i==0) column.setPreferredWidth(40);
          column.setPreferredWidth(100);
        //display
        JScrollPane jsp = new JScrollPane(jt);
        add(jsp);
    class ListSelectionHandler implements ListSelectionListener
      public void valueChanged(ListSelectionEvent e)
        ListSelectionModel lsm = (ListSelectionModel)e.getSource();
        if(lsm.isSelectionEmpty()) return;
        int rowNum = lsm.getMinSelectionIndex();
        if(!e.getValueIsAdjusting())
          System.out.println(rowNum +" =rowNum");
    }

    You could make it a method like
    public int getSelection() {
       return table.getSelectedRow();
    }That would work fine provided 'table' is kept as an instance variable. As far as I can see, there's no need for a static variable here. If you wanted to return different information, you could do it the same way (eg, returning the selected value, instead of the row, etc.)

Maybe you are looking for

  • Exporting pdf shows all the .ai layers when flipping through pages

    I'm building complicated illustrator files with vector and placed images and saving them as .ai files. Then I place then into my indesign file and export into a multiple page PDF. Unfortunately when I view the PDF, instead of just showing one flat im

  • Lumia 1020 Screen issue

    Not totally sure how to explain this... When the phone is at the lock screen, showing the clock on a BLACK background where the background is back lit.  If I am in the Dark so theres no light source to glare off the screen, I can see what look like d

  • Migrating from Brio 8.5 to EPM 11x

    Hi All, We are planning to migrate brio from 8.5 to 11.x.. 1.Which version we have to migrate from 8.5 ? Is it 11.1.2.2 or earlier versions? 2. How to download versions earlier 11.1.2.2(Ex:11.1.1.3)? 3.Our workspace has 300 user accesibililty,is it g

  • Multiple Fiscal year variant

    For global consolidaiton I have all company with same fiscal year variant. For 2 regional consolidation I have different kind of fiscal year variant. Do we handle different fiscal year variant thru different consolidation area or different data basis

  • How to move the vertical scrollbar ?

    Hi How can I move a vertical scrollbar in the HTML page to a desired position.The position is actually a list tag element.?