Insert/update - merge  apex items

hello =)
i want to insert data into a table and if the table has already the "List_id" i want to update values:
begin
FOR i IN 1..APEX_APPLICATION.G_F01.COUNT LOOP
MERGE INTO list_values
USING dual
ON (list_values.list_id = to_number(APEX_APPLICATION.G_F02(i))
WHEN MATCHED THEN
UPDATE
SET
list_values.product_fk=:P900_PRODUCT_NAME,
ist_values.attribute=APEX_APPLICATION.G_F04(i),
list_values.value=APEX_APPLICATION.G_F05(i)
WHEN NOT MATCHED THEN
INSERT
list_values.product_fk,list_values.attribute,list_values.value
VALUES
*:P900_PRODUCT_NAME,APEX_APPLICATION.G_F04(i),APEX_APPLICATION.G_F05(i)*
end loop;
end;
got a lot of sql errors...
+1+ error has occurred
ORA-06550:line 6, column 65: PL/SQL: ORA-00907: missing right parenthesis ORA-06550: line 4, column 1: PL/SQL: SQL Statement ignored
Maybe someone can help me with the syntax of the merge statement or maybe merge doesn't work in this case. because of the apex_items.
also got seperated insert/update process. they work perfect, if i use the processes singly:
Begin
FOR i IN 1..APEX_APPLICATION.G_F01.COUNT LOOP
insert into List_values (product_fk,attribute,value)
values (:P900_PRODUCT_NAME,APEX_APPLICATION.G_F04(i),APEX_APPLICATION.G_F05(i));
END LOOP;
end;
begin
FOR i IN 1..APEX_APPLICATION.G_F01.COUNT LOOP
update List_values
set
product_fk=:P900_PRODUCT_NAME,
attribute=APEX_APPLICATION.G_F04(i),
value=APEX_APPLICATION.G_F05(i)
where list_id=to_number(APEX_APPLICATION.G_F02(i));
END LOOP;
end;
Maybe someone can help me to combine them.
Thank u =)

You were missing a right parenthesis at the end of line 7.
BEGIN
   FOR i IN 1 .. APEX_APPLICATION.g_f01.COUNT
   LOOP
      MERGE INTO LIST_VALUES
           USING DUAL
              ON (LIST_VALUES.list_id =
                     TO_NUMBER (APEX_APPLICATION.g_f02 (i)))
      WHEN MATCHED
      THEN
         UPDATE SET
            LIST_VALUES.product_fk = :p900_product_name,
            ist_values.attribute = APEX_APPLICATION.g_f04 (i),
            LIST_VALUES.VALUE = APEX_APPLICATION.g_f05 (i)
      WHEN NOT MATCHED
      THEN
         INSERT     (LIST_VALUES.product_fk,
                     LIST_VALUES.attribute,
                     LIST_VALUES.VALUE)
             VALUES (
                       :p900_product_name,
                       APEX_APPLICATION.g_f04 (i),
                       APEX_APPLICATION.g_f05 (i));
   END LOOP;
END;Jeff

Similar Messages

  • Can you create nested condition in merge(e.g. insert/update) using owb

    Hi,
    Does OWB9iR2 allow you to build in nested condition in merge. such as
    If no match on col1 and col2 then
    if col3 match then no new sequence insert <---
    else insert new sequence;
    else (there is match on col1 and col2)
    update col3 and sequence.
    I have an incremental load for a lookup table, where insert/update is used. There are two match columns and surrogate key is used. When there is no match, it shall not insert a sequence when there is a match on third column. I can not use the 3rd column in the original match because it shall be updated where there is a match for the two match column.
    I am trying to avoid using transformant for performance impact. Thanks

    HIi I think the misleading thing is that in PL/SQL you can use booleans, which is not possible in SQL. So in a PL/SQL tranformation, this is OK:
    a:= case when not orgid_lkup( INGRP1.ORG_ID )
    then get_supid(..)
    else ...
    but, the following SQL does not work:
    select case when not orgid_lkup( INGRP1.ORG_ID )
    then get_supid(..)
    else ...
    into a
    from dual;
    I ended up using only 0/1 as boolean return values for these reasons;
    so I can have:
    select
    case when orgid_lkup( INGRP1.ORG_ID ) = 0 then ...
    though true booleans are better if you don't have to embed them in SQL.
    Antonio

  • Insert/Update/Delete Non-PO Invoice Line Item via FM/BAPI?

    Does anyone know of a way to insert/update/delete an Invoice Line item (Non-PO Accounting Invoice - Transaction FB60 or FV60) using a BAPI or Function Module (or set of function modules) using ABAP? I have been trying to find some code to accomplish this and am stuck on a couple of issues.
    I have found PRELIMINARY_POSTING_FB01 and PP_CHANGE_DOCUMENT_ENJ but both seem to submit the details to background processes. This is an issue because it gives the user a success message after execution but later delivers the error to Workflow. This is for an interfacing program so the results should be as real time as possible.
    Has anyone accomplished this via FM or BAPI and if so would you mind sharing your experiences?
    Thank you very much,
    Andy

    SG- Thank you for the reply.
    I have been playing with BAPI_INCOMINGINVOICE_PARK and I'm not sure if it is doing exactly what we want, but it is something that I have considered in the past. I plan on looking into BAPI_ACC_INVOICE_RECEIPT_POST this morning, hopefully that will provide some more for us.
    If possible I'd like to avoid BDC sessions because this program could hypothetically interface with multiple SAP systems with different configurations.
    I will check into those FM's and thank you very much.

  • APEX time to insert update and/or records

    Hello everyone,
    I know how to get the time APEX needs to load a repor! But how can I get the time APEX took to insert, update and or delete a records!! Does this work with #TIMING# as well??? If it does where to put this...
    Thank you
    Regards
    Sebastian

    I use the APEX version 2.0.1 provided by the Oralce Database 10g XE!
    And I wanna know how long it takes to insert, update or delete a records???
    I may should add that I link the different buttons to the specific processes to running the approproated sql statements!
    When I use the debug mode as mentions there is no hit how long APEX took to insert, update or delete a records. It just shows the basic time values how long it takes to load the whole application.
    Regards
    Sebastian

  • Merge vs Insert & Update Performance Comparison

    I am trying to do an insert and update to the target table from source table (oracle 11g).Its OLTP.Merge will be better or Insert & Update will be better..

    Hi,
    Welcome to the forum!
    user3893088 wrote:
    I am trying to do an insert and update to the target table from source table (oracle 11g).Its OLTP.Merge will be better or Insert & Update will be better..No one can say whether one will necessarily be better than the other, especially without seeing exactly what you're doing.
    For performance questions, see the forum FAQ
    SQL and PL/SQL FAQ
    #3 "How to improve the performance"
    I would guess that MERGE would be faster, because it only needs to scan the source table once. MERGE will proably be simpler to code, and easier to read and understand as well, so maintenance will take less time.

  • Using Merge to Update to Insert, Update, and also deleting obsolete records

    Hi all!!!
    Suppose that a have the following table, called Orders:
    ORDERID        STATUS      PRICE
             1          0        100
             2          0        200
             3          0        300
             4          0        350
             5          0        390 Also, there is a procedure that will generate some data on a global temporary table, called Orders_Temp. This temporary table will be used to update the Orders table.+Orders+ have a trigger that will perform different operations when a Insert, Delete or Update command is performed.
    Consider that the Orders_Temp table have the following data after running a procedure that is responsible for updating orders data:
    ORDERID        STATUS      PRICE
             1          1        100
             2          2        200
             3          0        300
             5          0        390
             6          0        350 As you can see, orders 1 and 2 were updated. Order 3 and 5 were untouched, order 4 was deleted and order 6 was inserted. Merge will handle the correctly handle orders 1, 2, 3, 5 and 6, even though generating a update to orders 3 and 5, that were not changed.
    So, here are the questions:
    1) How could I delete the order 4 from Orders, since this order was not present on the Orders_Temp? Is there a way to use the merge command to do this?
    2) Is there any way to not generate a update operation for orders 3 and 5, that were not changed?
    I´m using Oracle 10.2 SE.
    Thanks a lot!
    Regis

    Hello G!
    Thank you so much for your help.
    Your code took only a modification:
    MERGE INTO orders tgt
    USING (SELECT A.*, 1 mask
              FROM orders_temp A
            UNION ALL
            SELECT A.*, 0
              FROM orders A
             WHERE NOT EXISTS
                     (SELECT 1
                        FROM orders_temp b
                       WHERE A.order_id = b.order_id)) src
        ON (tgt.order_id = src.order_id)
    WHEN MATCHED
    THEN
      UPDATE SET tgt.status = src.status, tgt.price = src.price
         /*WHERE src.mask = 1
           AND tgt.status != src.status
           AND tgt.price != src.price*/
      DELETE
         WHERE src.mask = 0
    WHEN NOT MATCHED
    THEN
      INSERT VALUES (src.order_id, src.status, src.priceWithout doing this, the DELETE WHERE clause was never called. After reading the docs, I found why:
    Specify the DELETE where_clause to clean up data in a table while populating or updating it. The only rows affected by this clause are those rows in the destination table that are updated by the merge operation. That is, the DELETE WHERE condition evaluates the updated value, not the original value that was evaluated by the UPDATE SET ... WHERE condition. If a row of the destination table meets the DELETE condition but is not included in the join defined by the ON clause, then it is not deleted. Any delete triggers defined on the target table will be activated for each row deletion.http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_9016.htm
    >
    From what I understand, if we restrict the records on update set_clause, the delete  where_clause will no be able to process because they were not touched. So, as as workaroud, I´m checking if the record was changed inside my trigger.
    Thanks a lot!
    Regards.
    Regis

  • Inserted | updated | deleted | merged

    Hello,
    If a table has been set to update/insert and a row arrives with a matching column then the corresponding row in the target table is updated. In the job details window shouldnt it show a 1 under the updated section. My question really is, what does the merged tab indicate ?
    Thanks

    Hi,
    As per my knowledge
    If map runs in row based mode-- insert,update tabs are filled
    If map runs in set based mode- merge will come
    Row Based mode: In the pl/sql pkg generated by the map
    insert and update operation will happen for each row
    For insert/update option --First insert statement will run if the record exists then exception will come , then in the exception block update statment will be there and thee the record will be udpated..
    For update/insert option -- First it tries to update the record.. if it doestnt find the record it raises an exception , in the exception block insert statment will be ther
    that will insert the record..
    In Set based Mode:
    Instead of separate insert/update statements one merge stament will be there it will run...
    So set based mode is faster than row based mode..
    If any errors comes, then its difficult to find the source record causing the error in set based mode as it is in merge statment
    but it is easy in row based as it will do insert/update for each record --- each record will be inserted in the audit tables.
    Hope this will give u an idea
    Than you

  • How to update an existing item in a sharepoint list using the WSS adapter for Biztalk

    Is there a way that a record in SP list be updated using WSS adapter in biztalk ?
    BizTalk 2013 and SP 2013 ..
    Regards
    Ritu Raj
    When you see answers and helpful posts,
    please click Vote As Helpful, Propose As Answer, and/or Mark As Answer

    A ListItem has its own unique row id so in all likelihood, an insert with the same data will result in a new list entry. The Lists Web Service however, has an UpdateListItem method which will take an update request. [refer
    http://msdn.microsoft.com/en-us/library/office/websvclists.lists.updatelistitems(v=office.15).aspx ]
    There is another note in the conference (marked answered) to your List Item Update problem. Probably worth a try too. [refer
    http://social.msdn.microsoft.com/Forums/en-US/bee8f6c6-3259-4764-bafa-6689f5fd6ec9/how-to-update-an-existing-item-in-a-sharepoint-list-using-the-wss-adapter-for-biztalk?forum=biztalkgeneral ]
    Regards.

  • Populating apex item checkbox in report row based on database value

    Hi All
    I am looking for help setting an apex item checkbox to 'checked' depending on a record exisiting in a database and I would appreciate a little guidance.
    At the moment I have a report which looks a bit like this
    SELECT licence_user_identifier,
    description,
    licence_name,
    apex_item.checkbox(22,licence_id)
    FROM TABLE(SOL_LICENCE.F_RETRIEVE_ORG_LICENCES ( 121 ));
    4 columns and the last column is a checkbox called 'assign' and is used to assign the selected licence to a user(who is already displayed on the page in another table). There is save button which when clicked saves a record to the database if the checkbox is selected.
    However when the page is displayed the checkbox should be prepopulated/checked if there is a record in the database saying that the licence is assigned to the current user. I have created a page process to try and collect this information and populate the checkboxes on load - before header. However I am having difficulty referencing the apex_application item the corresponds to each row because when I use the FOR i IN 1 .. apex_application.g_f22.COUNT LOOP it only selects the item if it is checked. Can anyone point me in the right direction?
    here is the process I have to populate the checkboxes, it is not getting to my flow.debug as there are no selected checkboxes:-(
    DECLARE
    v_count     NUMBER;
    CURSOR getlicences (p_co_id so05.co_id%TYPE)
         IS
    SELECT     licence_id
    FROM     so05_cust_org_licences
    WHERE     co_id = p_co_id;
    BEGIN
         IF :p9_co_id IS NOT NULL
         THEN
              FOR each_rec IN getlicences (:p9_co_id)
              LOOP
                   --check if a record exists
                   SELECT     COUNT ( * )
                   INTO     v_count
                   FROM     so05_cust_org_licences
                   WHERE     co_id = :p9_co_id AND licence_id = each_rec.licence_id;
    --if the record exists populate the checkbox
                   IF v_count > 0
                   THEN
                        FOR i IN 1 .. apex_application.g_f22.COUNT
                        LOOP
    wwv_flow.debug ('bbbbbbbbbbccccccccccandwearein' || v_count);
                             IF apex_application.g_f22 (i) = each_rec.licence_id
                             THEN
                                  apex_application.g_f22 (i) := 1;
                             END IF;
                        END LOOP;
                   END IF;
              END LOOP;
         END IF;
    END;
    Thanks in advance
    Lynn

    Hi,
    Sorry my mistake. You can use the above link only to solve this problem, for this you have to use a hidden column to which you will assign 'Y' or 'N' as mentioned in that post.
    using that hidden column value you can fire your query accordingly.
    let's say your hidden column is f01 and checkbox column is f02 and the id column is f03, you can do like this
    create a process before your update process like this
    BEGIN
        -- Reset the hidden ADMIN_USER flag for all visible records to N
        -- Note: g_f01 maps to the hidden ADMIN_USER column
        FOR ii IN 1 .. APEX_Application.g_f01.COUNT
        LOOP
            APEX_Application.g_f01(ii) := 'N';
        END LOOP;
        -- Set the hidden ADMIN_USER flag for those records where the
        -- checkbox has been set by the user to Y
        -- Note: g_f02 is the checkbox column ADMIN_USER_CHECKBOX
        FOR ii IN 1 .. APEX_Application.g_f02.COUNT
        LOOP
            APEX_Application.g_f01(APEX_Application.g_f02(ii)) := 'Y';
        END LOOP;
    END;then write a new process positioning after above process
    if apex_application.g_f01 = 'Y' then
      your update query using id column (f03)
    else
      your delete query using that id column (f03)
    end if;hope this helps you.
    Thanks
    Tauceef

  • Invalid data has been used to update the list item. The field you are trying to update may be read only (Lookup Field).

    Hi.
    I am getting below error while adding value to look-up field.
    Invalid data has been used to update the list item. The field you are trying to update may be read only.
    I have tried many forums ans post but didn't come to know what's the root cause of issue. I am also posting Code for creating and adding lookup field.
    CAML to create lookup field (It works Fine)
    string lkproductNumber = "<Field Type='Lookup' DisplayName='Product Number' StaticName='ProductNumber' ReadOnly='FALSE' List='" + pNewMaster.Id + "' ShowField='Product_x0020_Number' />";
    Code to insert value to lookup field
    ClientContext client = new ClientContext(SiteUrl);
    client.Load(client.Web);
    client.Credentials = new NetworkCredential(this.UserName, this.Password, this.Domain);
    // Lookup Lists
    List pmList = client.Web.Lists.GetByTitle("Product_Master");
    //List Conatining Lookup Columns
    List piList = client.Web.Lists.GetByTitle("Product_Inventory");
    client.Load(piList);
    query.ViewXml = "<View/>";
    ListItemCollection collection = pmList.GetItems(query);
    client.Load(collection);
    client.ExecuteQuery();
    int prodid=0;
    foreach (ListItem item in collection)
    if (Convert.ToString(item["Product_x0020_Number"]) == ProductNumber)
    { prodid = Convert.ToInt32(item["ID"]); }
    ListItem piItem = piList.AddItem(new ListItemCreationInformation());
    piItem["Product_x0020_Number"] = new FieldLookupValue() { LookupId = prodid };
    piItem.Update();
    client.ExecuteQuery();
    Exception Detail
    Microsoft.SharePoint.Client.ServerException was caught
    Message=Invalid data has been used to update the list item. The field you are trying to update may be read only.
    Source=Microsoft.SharePoint.Client.Runtime
    ServerErrorCode=-2147352571
    ServerErrorTypeName=Microsoft.SharePoint.SPException
    ServerStackTrace=""
    StackTrace:
    at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
    at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
    at WebServiceProviders.ClientServices.NewProductInventory() in Z:\.............ClientServices.cs:line 889
    InnerException:
    Quick response is highly appreciated.
    Thanks
    Mehar

    Try some thing like below,
    your data value that needs to be update should be in this format "ID of the lookup";#"Title of the Lookup" 
    For example,
    listItem["Product_x0020_Number"]
    = "1;#iPhone";
    listItem["Product_x0020_Number"]
    = "2;#Mobile";
    Hope this helped you....

  • Inserting/ deleting a line item in MIGO Transaction ( Goods Issue )?

    Hi,
    Can anyone help me with the logic for Inserting / deleting a line item in MIGO Transaction?
    Thanks,
    cs

    Hi
    The following user exits and badis for migo:
    Check the mb_migo_badi and check the method 'LINE_MODIFY' for u r purpose.
    For undestanding see the documentation of the badi and see the example implementation
    class: CL_EXM_IM_MB_MIGO_BADI
                                                                                    Enhancement/ Business Add-in            Description                                                                               
    Enhancement                                                                               
    MB_CF001                                Customer Function Exit in the Case of Updating a Art. Doc.      
    MBCF0011                                Read from RESB and RKPF for print list in  MB26                 
    MBCF0010                                Customer exit: Create reservation BAPI_RESERVATION_CREATE1      
    MBCF0009                                Filling the storage location field                              
    MBCF0007                                Customer function exit: Updating a reservation                  
    MBCF0006                                Customer function for WBS element                               
    MBCF0005                                Article document item for goods receipt/issue slip              
    MBCF0002                                Customer function exit: Segment text in article doc. item                                                                               
    Business Add-in                                                                               
    MB_RESERVATION_BADI                     MB21/MB22: Check and Complete Dialog Data                       
    MB_QUAN_CHECK_BADI                      BAdI: Item Data at Time of Quantity Check                       
    MB_PHYSINV_INTERNAL                     Connection: Core Inventory and Retail AddOn                     
    MB_MIGO_ITEM_BADI                       BAdI in MIGO for Changing Item Data                             
    MB_MIGO_BADI                            BAdI in MIGO for External Detail Subscreens                     
    MB_DOC_BADI_INTERNAL                    BAdIs when Creating an Article Document (SAP Internal)          
    MB_DOCUMENT_UPDATE                      BADI when updating article document: MSEG and MKPF              
    MB_DOCUMENT_BADI                        BAdIs when Creating an Article Document                         
    MB_CIN_MM07MFB7_QTY                     Proposal of quantity from Excise invoice in GR                  
    MB_CIN_MM07MFB7                         BAdI for India Version exit in include MM07MFB7                 
    MB_CIN_LMBMBU04                         posting of gr                                                   
    MB_CHECK_LINE_BADI                      BAdI: Check Line Before Copying to the Blocking Tables          
    ARC_MM_MATBEL_WRITE                     Check Add-On-Specific Data for MM_MATBEL                        
    ARC_MM_MATBEL_CHECK                     Check Add-On-Specific Criteria for MM_MATBEL    
    If it is helpfu rewards points
    Regards
    Pratap.M

  • Insert, update and delete trigger over multiple Database Links

    Hello guys,
    first of all I'll explain my environment.
    I've got a Master DB and n Slave Databases. Insert, update and delete is only possible on the master DB (in my opinion this was the best way to avoid Data-inconsistencies due to locking problems) and should be passed to slave databases with a trigger. All Slave Databases are attached with DBLinks. And, additional to this things, I'd like to create a job that merges the Master DB into all Slave DB's every x minutes to restore consistency if any Error (eg Network crash) occurs.
    What I want to do now, is to iterate over all DB-Links in my trigger, and issue the insert/update/delete for all attached databases.
    This is possible with the command "execute immediate", but requires me to create textual strings with textually coded field values for the above mentioned commands.
    What I would like to know now, is, if there are any better ways to provide these functions. Important to me is, that all DB-Links are read dynamically from a table and that I don't have to do unnecessary string generations, and maybe affect the performance.
    I'm thankful for every Idea.
    Thank you in advance,
    best regards
    Christoph

    Well, I've been using mysql for a long time, yes, but I thought that this approach would be the best for my requirements.
    Materialized View's don't work for me, because I need real-time updates of the Slaves.
    So, sorry for asking that general, but what would be the best technology for the following problem:
    I've got n globally spread Systems. Each of it can update records in the Database. The easies way would be to provide one central DB, but that doesn't work for me, because when the WAN Connection fails, the System isn't available any longer. So I need to provide core information locally at every System (connected via LAN).
    Very important to me is, that Data remain consistent. That means, that it must not be that 2 systems update the same record on 2 different databases at the same time.
    I hope you understand what I'd need.
    Thank you very much for all your replies.
    best regards
    Christoph
    PS: I forgot to mention that the Databases won't be very large, just about 20k records, and about 10 queriees per second during peak times and there's just the need to sync 1 Table.
    Edited by: 907142 on 10.01.2012 23:14

  • How to insert/update Date field in Oracle with java code

    Dear All
    I have to insert/update a date column while creating a new item, but the problem is i am able to insert/update only date but i need both date and time along with AM/PM.
    By using these 3 lines i am able to insert/update only date.
    java.util.Date date = new java.util.Date();
    long dateLong = date.getTime();
    stmtPrep.setDate(33, new java.sql.Date(dateLong));
    Below code retrives the date exactly what i need but unable to pass in the statement:
    DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss a");
    java.util.Date d = (Date) new java.util.Date();
    String stringdate = formatter.format(d);
    String tmpdate = dateFormat();
    stmtPrep.setString(33, tmpdate); -- I tried with setObject as well but same error coming.
    Error is:
    ORA-01830: date format picture ends before converting entire input string
    Can u guide me how to get full date time with AM/PM?

    sasikrishna wrote:
    Dear All
    I have to insert/update a date column while creating a new item, but the problem is i am able to insert/update only date but i need both date and time along with AM/PM.
    By using these 3 lines i am able to insert/update only date.
    java.util.Date date = new java.util.Date();
    long dateLong = date.getTime();
    stmtPrep.setDate(33, new java.sql.Date(dateLong));That's by design. A java.sql.Date object matches an SQL DATE column (which doesn't include a time component). If you want something which matches an SQL TIMESTAMP colum (which includes both date and time components) then you should use a java.sql.Timestamp object.

  • How to insert data from APEX form into two tables

    Hi,
    I'm running APEX 4.1 with Oracle XE 11g, having two tables CERTIFICATES and USER_FILES. Some of the (useless) fields are cut to reduce information:
    CREATE TABLE CERTIFICATES
    CERT_ID NUMBER NOT NULL ,
    CERT_OWNER NUMBER NOT NULL ,
    CERT_VENDOR NUMBER NOT NULL ,
    CERT_NAME VARCHAR2 (128) ,
    CERT_FILE NUMBER NOT NULL ,
    ) TABLESPACE CP_DATA
    LOGGING;
    ALTER TABLE CERTIFICATES
    ADD CONSTRAINT CERTIFICATES_PK PRIMARY KEY ( CERT_ID ) ;
    CREATE TABLE USER_FILES
    FILE_ID NUMBER NOT NULL ,
    FILENAME VARCHAR2 (128) ,
    BLOB_CONTENT BLOB ,
    MIMETYPE VARCHAR2 (32) ,
    LAST_UPDATE_DATE DATE
    ) TABLESPACE CP_FILES
    LOGGING
    LOB ( BLOB_CONTENT ) STORE AS SECUREFILE
    TABLESPACE CP_FILES
    STORAGE (
    PCTINCREASE 0
    MINEXTENTS 1
    MAXEXTENTS UNLIMITED
    FREELISTS 1
    BUFFER_POOL DEFAULT
    RETENTION
    ENABLE STORAGE IN ROW
    NOCACHE
    ALTER TABLE USER_FILES
    ADD CONSTRAINT CERT_FILES_PK PRIMARY KEY ( FILE_ID ) ;
    ALTER TABLE CERTIFICATES
    ADD CONSTRAINT CERTIFICATES_USER_FILES_FK FOREIGN KEY
    CERT_FILE
    REFERENCES USER_FILES
    FILE_ID
    NOT DEFERRABLE
    What I'm trying to do is to allow users to fill out all the certificate data and upload a file in an APEX form. Once submitted the file should be uploaded in the USER_FILES table and all the fields along with CERT_ID, which is the foreign key pointing to the file in the USER_FILES table to be populated to the CERTIFICATES table. APEX wizard forms are based on one table and I'm unable to build form on both tables.
    That's why I've created a view (V_CERT_FILES) on both tables and using INSTEAD OF trigger to insert/update both tables. I've done this before and updating this kind of views works perfect. Here is where the problem comes, if I'm updating the view all the data is updated correctly, but if I'm inserting into the view all the fields are populated at CERTIFICATES table, but for USER_FILES only the fields FILE_ID and LAST_UPDATE_DATE are populated. The rest three regarding the LOB are missing: BLOB_CONTENT, FILENAME, MIMETYPE. There are no errors when running this from APEX, but If I try to insert into the view from SQLDeveloper, I got this error:
    ORA-22816: unsupported feature with RETURNING clause
    ORA-06512: at line 1
    As far as I know RETURNING clause in not supported in INSTEAD of triggers, although I didn't have any RETURNING clauses in my trigger (body is below).
    Now the interesting stuff, after long tracing I found why this is happening:
    First, insert is executed and the BLOB along with all its properties are uploaded to wwv_flow_file_objects$.
    Then the following insert is executed to populate all the fields except the BLOB and it's properties, rowid is RETURNED, but as we know RETURNING clause is not supported in INSTEAD OF triggers, that's why I got error:
    PARSE ERROR #1918608720:len=266 dep=3 uid=48 oct=2 lid=48 tim=1324569863593494 err=22816
    INSERT INTO "SVE". "V_CERT_FILES" ( "CERT_ID", "CERT_OWNER", "CERT_VENDOR", "CERT_NAME", "BLOB_CONTENT") VALUES (:B1 ,:B2 ,:B3 ,:B4, ,EMPTY_BLOB()) RETURNING ROWID INTO :O0
    CLOSE #1918608720:c=0,e=11,dep=3,type=0,tim=1324569863593909
    EXEC #1820672032:c=3000,e=3168,p=0,cr=2,cu=4,mis=0,r=0,dep=2,og=1,plh=0,tim=1324569863593969
    ERROR #43:err=22816 tim=1324569863593993
    CLOSE #1820672032:c=0,e=43,dep=2,type=1,tim=1324569863594167
    Next my trigger gets in action, sequences are generated, CERTIFICATES table is populated and then USER_FILES, but only the FILE_ID and LAST_UPDATE_DATE.
    Finally update is fired against my view (V_CERT_FILES), reading data from wwv_flow_files it populates BLOB_CONTENT, MIMETYPE and FILENAME fields at the specific rowid in V_CERT_FILES, the one returned from the insert at the beginning. Last, file is deleted from wwv_flow_files.
    I'm using sequences for the primary keys, this is only the body of the INSTEAD OF trigger:
    select user_files_seq.nextval into l_file_id from dual;
    select certificates_seq.nextval into l_cert_id from dual;
    insert into user_files (file_id, filename, blob_content, mimetype, last_update_date) values (l_file_id, :n.filename, :n.blob_content, :n.mimetype, sysdate);
    insert into certificates (cert_id, cert_owner, cert_vendor, cert_name, cert_file) values (l_cert_id, :n.cert_owner, :n.cert_vendor, :n.cert_name, l_file_id);
    I'm surprised that I wasn't able to find a valuable source of information regarding this problem, only MOS note about running SQLoader against view with CLOB column and INSTEAD OF trigger. The solution would be to ran it against base table, MOS ID 795956.1.
    Maybe I'm missing something and that's why I decided to share my problem here. So my question is how do you create this kind of architecture, insert into two tables with a relation between them in APEX ? I read a lot in the Internet, some advices were for creating custom form with APEX API, create a custom ARP, create two ARP or create a PL/SQL procedure for handing the DML?
    Thanks in advance.
    Regards,
    Sve

    Thank you however I was wondering if there was an example available which uses EJB and persistence.

  • Which is better: Oracle incremental update (merge) or Oracle incremental update

    Hi All,
    We have big data load happening from Oracle RDBMS(source) to Oracle RDBMS(target). The data is huge (in billions) and new insertions, updates will happen. I would like to understand which among
    Oracle incremental update (merge) or Oracle incremental update is better and faster -  for first load and subsequent incremental updates, deletes? I request you all to provide valid reasons since I need to present the same to my client
    If at all Oracle incremental update (merge) is better, then why ODI needs to have Oracle incremental update IKM.
    I have seen some discussions on the same topic but I have not yet got a proper response with reasons and that is why I am posting the question again
    Thanks & Regards,
    Sijee Sadasivan

    Hi Sijee Sadasivan,
    IKM SQL Control Append could be faster for the initial load. You will therefore need another interface for the initial load.
    From my experience IKM Oracle Incremental Update (Merge) is faster than IKM Oracle Incremental Update for the incremental load, but I think the best thing to do is to try it on your environment. Nothing is better than a benchmark .
    IKM Oracle Incremental Update is useful for Oracle RDBMS < 9i, before this syntax was introduced.
    Regards,
    JeromeFr

Maybe you are looking for

  • Year end closure - query

    Dear Sirs, I am trying to do yr end  lcosing. After using the t-code FAGLGVTR - the retained earning account balance matches exactly with the F.01 figures. The F.07 balance for customer does not match with FD10N. what could be the possible error or a

  • Days in wh

    hi,     we have ware houses like QA and QP..... my customer wants to know when the product comes to qa and how many days it was kept in qa ware house and when it moved to qp.... for ur clarification.. see below for format... from wh         date     

  • Why does my MacBook Air's shutting down slow down after the recent update?

    After the newly update OS X Update 10.9.4, the shut down of my MacBook Air slows down. It will stay several seconds more than before the update. This happens every time I try to shut down my MacBook, please meet my problem.

  • No difference using web optimizer

    so I'm using a very popular web optimizer. But quite honestly I don't see a difference between the optimized version and the non-optimized version. Both versions load the same, look the same, etc. Actually, I even think the optimized version loads a

  • Aperture 2 Export DPI Settings

    I've wrote on this subject before, and I have re-read all the responses. I have yet to have a clear understanding of the "DPI" setting in the export dialog, and the default setting of 72 DPI. I am quite familiar with DPI, PPI, pixel count and dimensi