Deleting/Updating records from an object table in PL/SQL

Hello All,
VER:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
PL/SQL Release 11.2.0.3.0 - Production
CORE     11.2.0.3.0     Production
TNS for Linux: Version 11.2.0.3.0 - Production
NLSRTL Version 11.2.0.3.0 - Production
I have created an object and inserted records in it. Is there any way we can delete/update records from it. I do not want to delete based on iteration like delete.collection but I would like to know if we can delete directly from obj like delete from table...
CREATE OR REPLACE TYPE test_type AS OBJECT
col1 number,
col2 varchar2(100)
CREATE OR REPLACE TYPE tab_type is table of test_type;
DECLARE
test_tab tab_type;
l_cnt NUMBER;
BEGIN
select test_type(col1,col2) bulk collect
into test_tab from (select 1 as col1,'test1' as col2 from dual
                    union all
                    select 2,'test2' from dual);
IF test_tab.count>0
THEN
DELETE FROM TABLE(CAST(test_tab as tab_type)) a
where a.col1=1;
END IF;
l_cnt := test_tab.count;
END;Thx
Shank.

SB,
I have a scenario wherein I insert few records into a collection table. I'm gonna filter few records from collection table based on the filter.
I want to delete the records that didn't match the filter. Right now, I'm inserting the records into a physical table and deleting from there. I do no want to use a physical table. Trying to avoid it.
Would like to delete from collection itself.
DELETE FROM TABLE(CAST(lv_attr_filter_tab as EDMS_CSPP_DISC_REQ_TAB_TYPE))
                             WHERE NOT EXISTS (SELECT 1
                                   FROM edms_disc_lines_stg edls
                                   WHERE edls.req_id = edrg.request_id
                                      AND edls.disc_line_id = edrg.discount_id
                                      AND UPPER(edls.disc_status) IN ('ACTIVE');

Similar Messages

  • I HAVE A SOURCE TABLE WITH 10 RECORDS AND TARGET TABLE 15 RECORDS. MY WUESTION IS USING WITH THE TABLE COMPARISON TRANSFORM I WANT TO DELETE UNMATCHED RECORDS FROM THE TARGET TABLE ??

    I HAVE A SOURCE TABLE WITH 10 RECORDS AND TARGET TABLE 15 RECORDS. MY QUESTION IS USING WITH THE TABLE COMPARISON TRANSFORM .I WANT TO DELETE UNMATCHED RECORDS FROM THE TARGET TABLE ?? HOW IT IS ??

    Hi Kishore,
    First identify deleted records by selecting "Detect deleted rows from comparison table" feature in Table Comparison
    Then Use Map Operation with Input row type as "delete" and output row type as "delete" to delete records from target table.

  • Creating a Trigger for Deleting the records from a parent Table

    I am new to creating Trigger
    We will need several small tables that will be used to store any records that are deleted by the owner of the table. These will likely need a trigger where we would Delete from the parent table and on that Delete populate the child table with the previous record's data.
    Please give me a pseudo code for this
    Thanks
    John
    Edited by: user10750995 on Dec 30, 2008 9:06 AM

    Something like this:
    CREATE OR REPLACE TRIGGER trg_my_table_hist
    AFTER DELETE
    ON my_table
    FOR EACH ROW
    BEGIN
    INSERT INTO Hist_MyTable
    ( column1, column2, ..., DELETION_DATE)
    VALUES
    (:OLD.column1, :OLD.column2, ...., SYSDATE);
    END;
    /My_Table is your main table. When a row is deleted, the trigger will be fired and copy the deleted row to another table called Hist_My_Table. I'm supposing that the history table has all columns as they are defined in main tables plus a column named DELETION_DATE.
    My experience indicates that, probably, it's a good idea maintain update history and the user. But it depends on your requests.
    Regards,
    Miguel

  • TABLE OF Clause to fetch records from an object table.?

    Hi All,
    I want to know where in Oracle we can find material related to TABLE(OBJECT TYPE) Clause.
    Please find the code below which I am using.
    CREATE OR REPLACE TYPE OBJ_EMPNO AS OBJECT(EMPNO NUMBER);
    CREATE OR REPLACE TYPE TAB_EMPNO AS TABLE OF OBJ_EMPNO;
    DECLARE
    TYP_EMPNO TAB_EMPNO := TAB_EMPNO(OBJ_EMPNO(10), OBJ_EMPNO(20));
    BEGIN
    FOR REC IN (SELECT FROM TABLE(TYP_EMPNO)) LOOP*
    DBMS_OUTPUT.PUT_LINE(TREC.EMPNO);
    END LOOP;
    END;
    THE ABOVE Code works fine. But my question is Where can I find document related to TABLE(OBJECT TYPE) Clause.
    I searched a lot and found some in Oracle documentation, but most of them are not related to my requirement.
    Would appreciate if someone provide me some information here.
    Thanks,
    MK.

    where in Oracle we can find material related to TABLE(OBJECT TYPE) Clause.See TABLE().

  • Deleting few records from a large table

    Hi,
    I have a table having roughly 1.5 million. I sent a script to delete 16 duplicate records and it took more than 20 minute.
    Any help is appreciated
    Thanks
    Racle

    Since the delete statement keeps a log of records being deleted in case the delete statement may need to be rolled back, it may take a while to delete. Also, do the columns in your where clause have indexes on them? If no, then your system may have a hard time finding the records that need to be deleted. The truncate table command also deletes records much faster than the delete statement, but it doesn't keep a log of the records being deleted so use with caution!

  • How to delete a record from BSEG table

    Dear Experts,
    How to delete a record from BSEG table.
    If there possible to delete some records from transparent table ?
    Please help.
    Regards,
    Tan

    Hi,
    Deleting a record from a standard table can be done only if table maintenance exists - Cehck tcode - SM30.  But it is not advisable to delete records, coz the records may be dependent on many other tables.  If u delete in a single place, there may be chance that inconsistency in the data happens and hence will affect ur financial statements.
    Pls. assign points, if useful
    Regards,
    Sridevi

  • Delete a record from a table in a Database with Database Connectivity

    I can't find the function from the Database Connectivity library that allows me to delete a record from a table of the database. I tried to use DB Tools Free Object.vi function but this one deletes only the table created with a query.
    Thankyou

    I have used the sql query as described above and it works fine with access DB and the DB toolkit, the free object vi only deallocated a recordset's references this will noty alter the database since the record is a copy of the databases information.  The SQL delete function is very versatile and you should be able to delete records with no problem.
    Paul
    Paul Falkenstein
    Coleman Technologies Inc.
    CLA, CPI, AIA-Vision
    Labview 4.0- 2013, RT, Vision, FPGA

  • How to delete records from dynamic internal table.

    Hi Experts,
    Need urgent help!!!
    Issue is with Dynamic internal tables.
    Below is code written by me :
    FORM select_query USING Lw_tabnam
                      TYPE  t682i-kotabnr.
      DATA :  lw_line  TYPE REF TO data,
              lw_line1 TYPE REF TO data.
        CREATE DATA Lw_line    TYPE (lw_TABNAM).
        ASSIGN      Lw_line->* TO   <WA_tbl>.
        CREATE DATA LW_LINE    TYPE STANDARD TABLE OF (Lw_tabnam)
                               WITH NON-UNIQUE DEFAULT KEY.
        ASSIGN      Lw_line->* TO <TBL>.
        SELECT * FROM  (Lw_tabnam)
                 INTO CORRESPONDING FIELDS OF TABLE <TBL>
                 WHERE (t_keys).
    Endform.
    code is working fine.
    here even the table name and where condition are dynamic,everything is fine upto this point.
    Now i have to delete some record from <TBL> based on some conditons.
         for ex : ( here lc_fieldname is KUNNR)
          loop at t_kunnr.
              lw_tabix = sy-tabix.
            Read table <tbl>
                    with key (lc_fieldname) = t_kunnr-kunnr ASSIGNING <wa_tbl>.
            If sy-subrc = 0.
            *Delete
            delete <tbl> from <wa_tbl>
    delete <tbl> index  lw_tabix.
            Endif.
         Endloop.
    The above delete statement doesn't work ,even we can't use index as it gives a syntax error " something related to "index is not allowed in standard table or hash table.
    Can you help me ab't how to delete records in Dynamic internal table?
    Other option that i am thinking of is to create a static table of type dynamic table.
    means, data itab type standard table of <tbl> .I know the syntax is wrong ,however is there any way to do this?
    Thanks in advance ,
    If you have any suggestion ab't this then do let me know.
    bye,
    Gaurav.

    Hi
    I wrote this code and it works fine:
    DATA LW_TABNAM(10) VALUE 'LFA1'.
    DATA : LW_LINES TYPE REF TO DATA,
           LW_LINE  TYPE REF TO DATA.
    FIELD-SYMBOLS: <TABLE> TYPE TABLE,
                   <WA>    TYPE ANY.
    CREATE DATA LW_LINES TYPE TABLE OF (LW_TABNAM)
    WITH NON-UNIQUE DEFAULT KEY.
    ASSIGN LW_LINES->* TO <TABLE>.
    CREATE DATA LW_LINE TYPE (LW_TABNAM).
    ASSIGN LW_LINE->* TO <WA>.
    DO 10 TIMES.
      APPEND INITIAL LINE TO <TABLE>.
    ENDDO.
    SY-TABIX = 4.
    DELETE <TABLE> INDEX SY-TABIX.
    WRITE SY-SUBRC.
    I hope it help you
    Max

  • How to update Records from Internal table to u2018Zu2019 table?

    Hi Friends,
    How to update Records from Internal table to u2018Zu2019 table.
    I have records in Internal table , that records want to update on u2018Zmarau2019 Table.
    ( my internal table & u2018 Zu2019 table structures are same.)
    Thanking you.
    Regards,
    Subash

    Hi,
    loop at internal table.
    modify <Z- table > from values < internal table Workarea>.
    if sy-subrc = 0.
      COMMIT work.
    else.
      ROLLBACK waork.
    endif.
    endloop.
    or
    UPDATE <Z- table > from table < internal table Workarea>.
    if sy-subrc = 0.
      COMMIT work.
    else.
      ROLLBACK waork.
    endif.
    Prabhudas

  • Deleting records from Self-Referencing Table

    I am using this query to dodge the foreign key error when trying to delete a record from a table that has primary key and referencing foreign key in the same table. It works with smaller set of data but for a table with 400,000 records it fails with error
    : maximum recursion limit of 500 reached. I changed maxrecursion to 3267 and even 0. but no records were returned it infact went to infinite loop..
    Please help if u have an alternative solution othr than a cascade trigger(which I am already considering)
    WITH    q AS
            SELECT  id, siteUrl
            FROM    TestComposite
            WHERE   id = 42
                    AND siteUrl = 'site1'
            UNION ALL
            SELECT  tc.id, tc.siteUrl
            FROM    q
            JOIN    TestComposite tc
            ON      tc.parentID = q.id
                    AND tc.siteUrl = q.siteUrl
    select * 
    FROM    TestComposite
    WHERE   EXISTS
            SELECT  id, siteUrl
            INTERSECT
            SELECT  id, siteUrl
            FROM    q
    Thanks,
    J

    I am using this query to dodge the foreign key error when trying to delete a record from a table that has primary key and referencing foreign key in the same table. It works with smaller set of data but for a table with 400,000 records it fails with error
    : maximum recursion limit of 500 reached. I changed maxrecursion to 3267 and even 0. but no records were returned it in fact went to infinite loop..
    That is a questionable approach. Don't dodge table constraints. They have a reason to be there. Deep recursion is also doubtful approach.
    USE tempdb;
    GO
    SELECT * INTO Employee FROM AdventureWorks.HumanResources.Employee;
    GO
    ALTER TABLE Employee ADD constraint PK PRIMARY KEY (EmployeeID);
    ALTER TABLE Employee ADD constraint fkPK FOREIGN KEY (ManagerID) REFERENCES Employee(EmployeeID);
    GO
    SELECT * FROM Employee;
    GO
    -- Staff - no child records
    DELETE Employee WHERE EmployeeID = 283; -- (1 row(s) affected)
    -- Manager - child records
    DELETE Employee WHERE EmployeeID = 284;
    Msg 547, Level 16, State 0, Line 19
    The DELETE statement conflicted with the SAME TABLE REFERENCE constraint "fkPK". The conflict occurred in database "tempdb", table "dbo.Employee", column 'ManagerID'.
    The statement has been terminated.
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Is it safe to purge / delete older records from AUD$ table in SYS schema

    Hi,
    Can we purge / delete older records from AUD$ table in SYS schema.
    Please advice.
    Thanks
    Naveen

    Pl see MOS Doc 73408.1 (How to Truncate, Delete, or Purge Rows from the Audit Trail Table SYS.AUD$) fro details on how to do so.
    HTH
    Srini

  • Deleting records from a recursive table query

    Hi All,
    I have the follow query, I would like to ask for your help, please: we use recursive tables for various purposes and one of them may have 100,000's records.
    What would be the best approach to delete records from such a table?
    I was thinking about two below, but any additional one will be more than welcome as well:
    (1) I can DELETE FROM my_table WHERE my_table_id IN (SELECT my_table_id FROM my_table START WITH my_table_parent_id = X CONNECT BY PRIOR my_table_id = my_table_parent_id, but it means that I will run on my_table twice, no?
    (2) I thought also to create a Foreign Key of my_table_id REFERENCES my_table_parent_id, but then I am afraid it will effect DML commands on that table.
    Thank you in advance

    Hi,
    kdwolf wrote:
    ... (1) I can DELETE FROM my_table WHERE my_table_id IN (SELECT my_table_id FROM my_table START WITH my_table_parent_id = X CONNECT BY PRIOR my_table_id = my_table_parent_id, but it means that I will run on my_table twice, no?Sorry, I'm not sure whqt you mean by "I will run on my_table twice". Assuming you don't already have a foreign key constraint (as you described below) I don;t know any other way, let alone a more efficient way, to get the same results.
    (2) I thought also to create a Foreign Key of my_table_id REFERENCES my_table_parent_id, but then I am afraid it will effect DML commands on that table.You're right; a foreign key constraint always costs a little whenever you do DML. Someone who knows your application and your system as well as you do will have to decide if the benefit of having accurate, consistent data justifies that additional cost. If you're not sure, I suggest you add the constraint.
    One advantage of having a foreign key constraint is that you can create it with the "ON DELETE CASCADE" option. Then, if you simply say "DELETE FROM my_table WHERE my_table_patrent_id = X", all the descendants of those rows will automatically be deleted, exactly as you requested in (1) above.

  • Error on activation of data records from ODS object

    hi,
    Kindly help with my BW Problem, the error occured on the
    activation of ODS. The error says "<i>Request
    REQU_43MNOPW29W4F5M037J7OAFP52 in ODS ZPUR_O01 must have QM
    status green before it is activated</i>" and "<i>Activation of data
    records from ODS object ZPUR_O01 terminated</i>"
    I tried to check the data in the ODS Object by choosing
    <LS>Administrator Workbench > data targets > context menu on ODS
    Object ZPUR_O01 but the status are green and when i tried to
    activate it the logs says "<i>ODS object ZPUR_O01 was built
    incorrectly. Cannot update request
    REQU_43MODQ3GF69X17B71ZKQMN85I(20,154)
    ODS object ZPUR_O01 was built incorrectly. Cannot update request
    REQU_43MQ8A8F0L1US5COQTUUWX3BA(20,155)
    ODS object ZPUR_O01 was built incorrectly. Cannot update request
    REQU_43MQ8OQQTY21YQ37RMA1WMO06(20,156)
    Data to be activated successfully checked against archiving
    objects                                   
    Activation of data records from ODS object ZPUR_O01 terminated</i>"
    Please help me with this problem.

    Hi Jay
    U need to update these requests to ODS
    REQU_43MODQ3GF69X17B71ZKQMN85I(20,154)
    REQU_43MQ8A8F0L1US5COQTUUWX3BA(20,155)
    REQU_43MQ8OQQTY21YQ37RMA1WMO06(20,156)
    1) delete the current request
    2)Reconstruct the requests above three request
    3)and then Load the current reqest (REQU_43MNOPW29W4F5M037J7OAFP52)
    Then only u will be able to activate the ODS....
    This is an serialization issue...
    hope it helps
    regrds
    AK
    assign points if usefull

  • How to delete the row from the ADF table using popup box

    Hi,
    I have one requirement like need to delete a record from the table, but that time need to show one popup window for confirmation of the deletion. I am using Delete buttom from the vo operations. I am able to delete the row with out popup but when i used the popup that time deletion is not happening.
    Can any one help me in this.
    Regards,

    Issue was resolved.

  • Deleting selected record in Dynamic Internal table

    Hi Friends,
    I want to delete selected row from a dynamic internal table. The selected entry should be deleted from Adobe and as well as Webdynpro abap.
    Kindly help me how to solve this problem.
    Thanks in advance.
    Regards,
    Phani.

    Hi Matthias,
    Thanks a lot for responding.
    In my adobe i kept a check box to delete the record. It should delete the selected ones. But right now, its deleting one by one.
    I have coded following script for delete button:
    IT_TIME_SHEET --> is my internal table
    G_ROW_STATUS is the field to track the action performed.
    var tlength = xfa.resolveNodes("IT_TIME_SHEET.DATA[*]").length;
    for ( var i=0; i<tlength; i++
    if(xfa.resolveNode("IT_TIME_SHEET.DATA["i"].FLAG").rawValue ==
    1 )
    IT_TIME_SHEET.DATA.instanceManager.removeInstance(i);
    G_ROW_STATUS.rawValue = "DELETE";
    In the Webdynpro abap following code I wrote:
        row_count = 1.
        FIELD-SYMBOLS <wa> TYPE zshr_time_sheet_time.
        LOOP AT it_time_sheet ASSIGNING <wa>.
          <wa>-srl_no = row_count.
          row_count = row_count + 1.
        ENDLOOP.
        last_row = <wa>-srl_no.
          DELETE it_time_sheet WHERE srl_no EQ last_row.
    Suppose if two records checkboxes are selected I can loop at the internal table IT_TIME_SHEET in webdynpro and delete where checkbox is selected.
    But problem is once user deletes records, adobe is deleting only one record and if i delete two records from webdynpro it looks like something wrong for the user.
    Please help me how to solve this problem.
    Regards,
    Phani.

Maybe you are looking for