Trap Insert error for update

Hi, I've to insert/update records in pretty large table, and require an efficient way to do this. The majority of actions will be inserts, although there will be updates. How can I trap an insert constraint error and then do an update instead. Also, is this the most efficient way to do this??
C.

You can do something like this:
sql >> CREATE TABLE tbl_numbers
2 (
3 num number ,
4 description varchar2(20) ,
5 error varchar2(3) default 'NO'
6 )
7 tablespace index_4m
8 /
Table created.
sql >> insert into tbl_numbers
2 ( num , description )
3 values ( 1 , 'One' )
4 /
1 row created.
sql >> insert into tbl_numbers
2 ( num , description )
3 values ( 2 , 'Two' )
4 /
1 row created.
sql >> insert into tbl_numbers
2 ( num , description )
3 values ( 3 , 'Three' )
4 /
1 row created.
sql >> insert into tbl_numbers
2 ( num , description )
3 values ( 4 , 'Four' )
4 /
1 row created.
sql >> insert into tbl_numbers
2 ( num , description )
3 values ( 5 , 'Five' )
4 /
1 row created.
sql >> insert into tbl_numbers
2 ( num , description )
3 values ( 6 , 'Six' )
4 /
1 row created.
sql >> insert into tbl_numbers
2 ( num , description )
3 values ( 7 , 'Seven' )
4 /
1 row created.
sql >> insert into tbl_numbers
2 ( num , description )
3 values ( 8 , 'Eight' )
4 /
1 row created.
sql >> insert into tbl_numbers
2 ( num , description )
3 values ( 9 , 'Nine' )
4 /
1 row created.
sql >> insert into tbl_numbers
2 ( num , description )
3 values ( 10 , 'Ten' )
4 /
1 row created.
sql >> commit
2 /
Commit complete.
PROCEDURE PR_INSERT_UPDATE
IS
TYPE array_n IS TABLE OF NUMBER ;
TYPE array_v IS TABLE OF VARCHAR2(20) ;
t_num array_n ;
t_description array_v ;
e_ForallError EXCEPTION ;
PRAGMA EXCEPTION_INIT ( e_ForallError , -24381 ) ;
CURSOR cur IS
SELECT num , description
FROM tbl_numbers ;
BEGIN
OPEN cur ;
LOOP
FETCH cur BULK COLLECT INTO t_num , t_description LIMIT 100 ;
BEGIN
FORALL i IN t_num.FIRST .. t_num.LAST SAVE EXCEPTIONS
INSERT INTO tbl_numbers
( num , description )
VALUES ( t_num(i) , t_description(i)||'----------------' ) ;
COMMIT ;
EXCEPTION
WHEN e_ForallError THEN
t_num.DELETE ;
FOR i IN 1 .. SQL%BULK_EXCEPTIONS.COUNT LOOP
t_num.EXTEND ;
t_num(t_num.COUNT) := SQL%BULK_EXCEPTIONS(i).ERROR_INDEX ;
END LOOP ;
FORALL i IN 1 .. t_num.COUNT
UPDATE tbl_numbers
SET error = 'YES'
WHERE num = t_num(i) ;
COMMIT ;
END ;
EXIT WHEN cur%NOTFOUND ;
END LOOP ;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Error Code: '||SQLCODE) ;
dbms_output.put_line('Error Desc: '||SUBSTR(SQLERRM,1,200)) ;
RAISE ;
END PR_INSERT_UPDATE ;
sql >> select * from tbl_numbers;
NUM DESCRIPTION ERR
1 One NO
2 Two NO
3 Three NO
4 Four NO
5 Five NO
6 Six NO
7 Seven NO
8 Eight NO
9 Nine NO
10 Ten NO
10 rows selected.
sql >> exec PR_INSERT_UPDATE
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.00
sql >> select * from tbl_numbers;
NUM DESCRIPTION ERR
1 One NO
2 Two NO
3 Three YES
4 Four NO
5 Five NO
6 Six NO
7 Seven YES
8 Eight YES
9 Nine NO
10 Ten NO
1 One---------------- NO
2 Two---------------- NO
4 Four---------------- NO
5 Five---------------- NO
6 Six---------------- NO
9 Nine---------------- NO
10 Ten---------------- NO
17 rows selected.

Similar Messages

  • 'Missing select' error for update statement using WITH clause

    Hi,
    I am getting the below error for update statement using WITH clause
    SQL Error: ORA-00928: missing SELECT keyword
      UPDATE A
      set A.col1 = 'val1'
         where
      A.col2 IN (
      WITH D AS
      SELECT col2 FROM
      (SELECT col2, MIN(datecol) col3 FROM DS
      WHERE <conditions>
        GROUP BY PATIENT) D2
      WHERE
      <conditions on A.col4 and D2.col3>

    Hi,
    The format of a query using WITH is:
    WITH  d  AS
        SELECT  ...  -- sub_query
    SELECT  ...   -- main query
    You don't have a main query.  The keyword FROM has to come immediately after the right ')' that ends the last WITH clause sub-query.
    That explains the problem based on what you posted.  I can't tell if the real problem is in the conditions that you didn't post.
    I hope this answers your question.
    If not, post a complete test script that people can run to re-create the problem and test their ideas.  Include a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Reg: Error for updating info structure S001

    Hi ,
    While creating sales order, delivery and purchase order. iam getting the follwing error:
    "Error 4 updating info structure S001".  Please help me.
    Thanks,
    Bandi

    Hello,
    Updates of these reporting tables are done in asynchronous mode.
    Check transaction SM13 and try to find back the update of table S001 and analyze the error.
    Several OSS-notes explain what can go wrong with updates of LIS and SIS tables like S001.
    Wim

  • Re: Runtime error for updating z table

    Hi all,
    I have a Z table ZABC with 2 following fields
    REC1     type     PERSNO       length    8
    +REC2    type       STRING         length   1000     +
    In my program I declared an internal table like this
    ITAB  TYPE TABLE OF ZABC WITH HEADER LINE.
    At the end of the program, when I have the new info, I passed them into ITAB, and loop at it to update the Z table
    LOOP AT ITAB.
        INSERT ZABC FROM ITAB.
      ENDLOOP.
    Then I got run time error saying
    Runtime Errors         DBIF_RSQL_INVALID_RS
    Exceptn                CX_SY_OPEN_SQL_DB
    An exception occurred. This exception will be dealt with in more detail
    below. The exception, assigned to the class 'CX_SY_OPEN_SQL_DB', was not
    caught, which
    led to a runtime error. The reason for this exception is:
    The maximum length of the long field of the specified table is defined
    in the ABAP Dictionary. The current length of the long field corresponds
    to the value of the preceding field, which consequently
    must be numeric.
    In this case, the value in this field was greater than the maximum value
    defined for the long field in the ABAP Dictionary.
    The term "long field" refers to all fields that are created in the ABAP
    Dictionary with the data type STRING, RAWSTRING, LCHR, or LRAW.
    The problem is at this position
    LOOP AT ITAB.
       INSERT ZABC FROM ITAB.
      ENDLOOP.
    I know something wrong with the string type but I need to update the whole string structure for the whole record type (rather than updating field by field). need help! thanks!

    hi,
    the syntax would be as follows:
    INSERT ZABC FROM TABLE ITAB ACCEPTING DUPLICATE KEYS.
    This will discard the duplicate records & append all the other records from table itab into zabc.
    LOOP ....... ENDLOOP statements are not required.
    Regards,
    Jignesh.

  • Which Oracle error for UPDATE that finds no rows to update

    Can someone please confirm for me what is the Oracle error I will get when trying to do an UPDATE statement with WHERE clauses and no rows are found matching the WHERE clauses? I'm thinking it will be 1403, but want to be sure.
    Thank you.

    Thanks for the answers, and my apologies if I asked in the wrong forum. My program is C++, and I believe the update will produce a DAOSQLException. My intended question was what the error number for that exception would be, and it appears that it would be 1403.
    I am not just writing SQL statements, for which I realize (as many pointed out) that there would be no errors, just zero rows updated.
    Thanks.

  • HT4623 but when i go to the software update its shows error for update

    i could not updates the software its shows error
    even my app store is not getting loaded
    i have restart my phone not problem still .
    kindly suggest

    To update bsee:
    iOS 4: Updating your device to iOS 5 or later
    If your iPad does not have cameras then you have an iPa 1 and need iTunes 10.5 or later on the computer and y can go to iOS 5.1.1.
    For later iPads yo need iTunes 11.1 and yo will go to iOS 7.0.2

  • Shows error for updating applications

    Under Apps in creative cloud , shows Error downloading message, I have a creative cloud membership.

    Simi266 for information on how to resolve download errors please see Error downloading Creative Cloud applications - http://helpx.adobe.com/creative-cloud/kb/error-downloading-cc-apps.html.

  • Access/Privilege required for UPDATE/RELEASE actions

    Hi,
    I am a new user of BPEL 101.3.1. I have configured the identity service to CUSTOM and have given the following roles to the user created
    Roles :-
    1. BPMSystemAdmin
    2. BPMWorkflowAdmin
    3. BPMDefaultDomainAdmin
    4. BPMWorkflowReassign
    5. BPMWorkflowSuspend
    6. BPMWorkflowViewHistory
    The Acquiring/Reassignment of the task is happening successfully but then as an when i am trying to Update the Task or Release the Task then i am getting the following error.
    <2007-12-19 22:08:32,639> <ERROR> <oracle.bpel.services.workflow> <::> Invalid action on workflow task.
    Action RELEASE on task 2f9034534324d8b2:491a42ee:116f2f6cca6:-7b30 is not valid because of User does not have access/privilege to perform the action. .
    Contact oracle support if error is not fixable.
    ORABPEL-30036
    Invalid action on workflow task.
    Action RELEASE on task 2f9034534324d8b2:491a42ee:116f2f6cca6:-7b30 is not valid because of User does not have access/privilege to perform the action. .
    Contact oracle support if error is not fixable.
         at oracle.bpel.services.workflow.task.impl.TaskService.performPreActionValidation(TaskService.java:3408)
         at oracle.bpel.services.workflow.task.impl.TaskService.performPreActionValidation(TaskService.java:3440)
         at oracle.bpel.services.workflow.task.impl.TaskService.releaseTask(TaskService.java:1849)
         at oracle.bpel.services.workflow.task.impl.TaskService.releaseTask(TaskService.java:1840)
         at oracle.bpel.services.workflow.task.ejb.TaskServiceBean.releaseTask(TaskServiceBean.java:794)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at com.evermind.server.ejb.interceptor.joinpoint.EJBJoinPointImpl.invoke(EJBJoinPointImpl.java:35)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
         at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
         at com.evermind.server.ejb.interceptor.system.JAASInterceptor$1.run(JAASInterceptor.java:31)
         at java.security.AccessController.doPrivileged(Native Method)
         at javax.security.auth.Subject.doAs(Subject.java:396)
         at com.evermind.server.ThreadState.runAs(ThreadState.java:622)
         at com.evermind.server.ejb.interceptor.system.JAASInterceptor.invoke(JAASInterceptor.java:34)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
         at com.evermind.server.ejb.interceptor.system.TxRequiresNewInterceptor.invoke(TxRequiresNewInterceptor.java:52)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
         at com.evermind.server.ejb.interceptor.system.DMSInterceptor.invoke(DMSInterceptor.java:52)
         at com.evermind.server.ejb.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:119)
         at com.evermind.server.ejb.InvocationContextPool.invoke(InvocationContextPool.java:55)
         at com.evermind.server.ejb.StatelessSessionEJBObject.OC4J_invokeMethod(StatelessSessionEJBObject.java:87)
         at TaskServiceBean_RemoteProxy_68d4144.releaseTask(Unknown Source)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at com.evermind.server.rmi.RmiMethodCall.run(RmiMethodCall.java:53)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
         at java.lang.Thread.run(Thread.java:595)
    I am getting the same error for Updating as well as Releasing the Task.
    Can any 1 tell me that whether i am missing on some role???
    Thanks
    Prashant N.

    Same problem here...
    Did you find a solution?

  • Trap update error for insert!

    Hi, I have a table approx 2 million records which is updated daily from a staging table that is loaded from file. It's taking approx 7 hours as it searches for a record and if it exists, otherwise it inserts.
    I was thinking that a faster method would be to bulk collect and update, then trap the error if the record to be updated doesn't exist, and insert the record.
    I'm on Oracle 8i.
    Question: Would this be the most efficient way to perform the task?
    If so would anyone out there have some sample code to do it?
    Your help would be very much appreciated.

    Hi,
    There's only one constraint on the target:
    CREATE UNIQUE INDEX XPKGMENT_V ON GMENT_V
    (DATE_START, DATE_END, ORI, FNUMBER,
    CLASS_CD, DOW)
    CURSOR cur IS
    SELECT BEG_DATE,
         END_DATE,
    FNUMBER,
    ORIG,
    CLASS_CD,
    DATA_TYPE_CD,
    DOW,
    TTC,
    PSEUDO,
    PRORATE
    FROM stage_gment_v;
    rec cur%rowtype;
    rowcount      number(7);
    row_exists      number(1);
    BEGIN
    OPEN cur;
    rowcount := 0;
    row_exists := 0;
    LOOP
    FETCH cur INTO rec;
    EXIT WHEN cur%NOTFOUND;
    rowcount := rowcount + 1;
    row_exists := 0;
    BEGIN
    SELECT 1 INTO row_exists          
    FROM gment_v r
    WHERE r.date_start = rec.beg_date
    AND r.orig = rec.orig
    AND r.class_cd = rec.class_cd
    AND ( r.dow = rec.dow
    OR ( rec.dow IS NULL AND r.dow IS NULL) )
    AND ( r.fnumber = rec.fnumber
    OR ( rec.fnumber IS NULL AND r.fnumber IS NULL));
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    row_exists := 0;
    END;
    -- update if a row already exists
    IF ( row_exists = 1 ) THEN
    UPDATE gment_v r
    SET TTC = rec.ttc,
    PSEUDO = rec.pseudo,
    PRORATE = rec.prorate
    WHERE r.date_start = rec.beg_date
    AND r.orig = rec.orig
    AND r.class_cd = rec.class_cd
    AND ( r.dow = rec.dow
    OR ( rec.dow IS NULL AND r.dow IS NULL) )
    AND ( r.fnumber = rec.fnumber
    OR ( rec.fnumber IS NULL AND r.fnumber IS NULL));
    updates := updates +1;
    ELSE
    -- create if does not exist already
    INSERT INTO gment_v(
    DATE_START,
    DATE_END,
              FNUMBER,
              ORIG,
              CLASS_CD,
              DATA_TYPE_CD,
              DOW,
              TTC,
              PSEUDO,
              PRORATE)
    VALUES ( rec.beg_date,
    rec.end_date,
              rec.fnumber,
              rec.orig,
              rec.class_cd,
              rec.data_type_cd,
              rec.dow,
              rec.ttc,
              rec.pseudo,
              rec.prorate) ;
    END IF;
    END LOOP;

  • SELECT FOR UPDATE + INSERT = be careful

    Hi,
    It took me over a day to figure out what was going on with some code I wrote recently. I thought I'd share what I learned with the rest of you in case you encounter the same effect.
    The example below shows the results of two separate SQL*Plus sessions attempting to lock the same resource. In one scenario, a row is updated to itself in Session 1. In the other scenario, the same row is updated to a different value in Session 1. As you'll see, the two updates have different effects on the SELECT statement in Session 2.
    Session 1                                  | Session 2
                                               |
    SQL> select version from v$instance;       |
                                               |
    VERSION                                    |
    -----------------                          |
    10.2.0.1.0                                 |
                                               |
    SQL> create table t1 ( c1 varchar2(10) );  |
                                               |
    Table created.                             |
                                               |
    SQL> create table t2 ( c2 varchar2(10) );  |
                                               |
    Table created.                             |
                                               |
    SQL> insert into t1 values ( 'abc' );      |
                                               |
    1 row created.                             |
                                               |
    SQL> commit;                               |
                                               |
    Commit complete.                           |
    -- Scenario 1
    SQL> select c1,                            |
      2    (select count(*) from t2) t2_count  |
      3  from t1 for update;                   |
                                               |
    C1           T2_COUNT                      |
    ---------- ----------                      |
    abc                 0                      |
                                               |
                                               | SQL> select c1,
                                               |   2    (select count(*) from t2) t2_count
                                               |   3  from t1 for update;
                                               |
    SQL> update t1 set c1 = 'abc';             |
                                               |
    1 row updated.                             |
                                               |
    SQL> insert into t2 values ('x');          |
                                               |
    1 row created.                             |
                                               |
    SQL> commit;                               |
                                               |
    Commit complete.                           |
                                               | C1           T2_COUNT
                                               | ---------- ----------
                                               | abc                 0
                                               |
    -- Reset tables to their original condition
                                               | SQL> rollback;
                                               |
                                               | Rollback complete.
                                               |
    SQL> delete from t2;                       |
                                               |
    1 row deleted.                             |
                                               |
    SQL> commit;                               |
                                               |
    Commit complete.                           |
                                               |
    -- Scenario 2
    SQL> select c1,                            |
      2    (select count(*) from t2) t2_count  |
      3  from t1 for update;                   |
                                               |
    C1           T2_COUNT                      |
    ---------- ----------                      |
    abc                 0                      |
                                               |
                                               | SQL> select c1,
                                               |   2    (select count(*) from t2) t2_count
                                               |   3  from t1 for update;
                                               |
    SQL> update t1 set c1 = 'def';             |
                                               |
    1 row updated.                             |
                                               |
    SQL> insert into t2 values ('x');          |
                                               |
    1 row created.                             |
                                               |
    SQL> commit;                               |
                                               |
    Commit complete.                           |
                                               |
                                               | C1           T2_COUNT
                                               | ---------- ----------
                                               | def                 1
                                               |Does anyone have any suggestions on how to make the queries in Session 2 return a T2_COUNT of "1" in both scenarios. Note that, in reality, Session 2 will need to do its own inserts and updates. I left these steps out for clarity. Note also that I won't have access to do things like add triggers, create new tables/views, or do flashback queries. The simpler the solution, the better.
    Thanks in advance for your help.

    You can use the SERIALIZABLE isolation level to test to see if the data has been updated. If your code is aware of the ORA-08177 exception, then you can trap this error and retry the query:
    SQL> set transaction isolation level serializable; |
                                                       |
    Transaction set.                                   |
                                                       |
    SQL> select c1,                                    |
      2    (select count(*) from t2) t2_count          |
      3* from t1 for update;                           |
                                                       |
    C1           T2_COUNT                              |
    ---------- ----------                              |
    abc                 0                              |
                                                       | SQL> set transaction isolation level serializable;
                                                       |
                                                       | Transaction set.
                                                       |
                                                       | SQL> select c1,
                                                       |   2    (select count(*) from t2) t2_count
                                                       |   3* from t1 for update;
                                                       |
    SQL> update t1 set c1='abc';                       |
                                                       |
    1 row updated.                                     |
                                                       |
    SQL> insert into t2 values('x');                   |
                                                       |
    1 row created.                                     |
                                                       |
    SQL> commit;                                       |
                                                       |
    Commit complete.                                   |
                                                       |
                                                       | select c1,
                                                       | *
                                                       | ERROR at line 1:
                                                       | ORA-08177: can't serialize access for this transaction

  • ORA-01002-Error in Select ... for update

    I would like to insert CLOB in a table (VP_EVENTS) with a primary key (eventid) with the following code:
    String content = "AAAAAAAAAAAAABBBBBBBBBBXXX";
    PreparedStatement cs = this.con.prepareStatement("INSERT INTO vp_events (eventid,term,participant)
    VALUES (?,?,empty_clob())");
    //Register IN-Parameter
    cs.setInt(1, 1);
    cs.setInt(2, 1);
    cs.setTimestamp(3, new java.sql.Timestamp( System.currentTimeMillis() ));
    //Execute statement
    cs.execute();
    cs.close();
    Statement stmt = con.createStatement();
    ResultSet clobLocatorSet = stmt.executeQuery( "SELECT PARTICIPANT FROM VP_EVENTS WHERE EVENTID=1 FOR UPDATE");
    // Get the CLOB-locator
    if (clobLocatorSet.next())
    oracle.sql.CLOB clob =
    ((oracle.jdbc.driver.OracleResultSet)
    clobLocatorSet).getCLOB(1);
    // Write CLOB-Data
    // The first parameter to plsql_write, is // the offset from which to start
    // writing, and the second parameter is the // data to be written.
    // plsql_length(), returns the length of // the data in the CLOB column
    countCLOB = clob.plsql_write(
    0,content.toCharArray());
    At the execution-point of the "Select for Update"-statement the oracle thin driver throws the Error "Fetch out of sequence ORA-01002".
    What's wrong?

    Connection conn = DriverManager.getConnection ("jdbc racle:thin:@myhost:1521:ORCL","scott", "tiger");
    conn.setAutoCommit(false);
    Statement stmt = conn.createStatement ();
    null

  • Error while checking for update

    Lately, when I sync my iPad to iTunes on my mac, when I click on "Check for Updates" I get the following error message...
    "iTunes could not check for an update to the carrier settings for your iPad. An unknown error occurred (1631).
    Make sure your network settings are correct and your network connection is active, or try again"...
    The network is fine, both on the mac and the iPad... And the phrase "...could not check for an update to the carrier settings" doesn't even seem to make sense???? It used to work but this just started recently and now the error pops up every time I try... My iPad is WiFi + 3G but I've never activated the 3G coverage...
    Any thoughts??? thanks... bob..

    I hadn't seen that error either until just recently... I found this post,
    http://discussions.apple.com/message.jspa?messageID=12635600
    where folks with the same problem have appeared to have found an answer...
    All I did was toggled my Cellular Data switch from OFF (where it always was before) to ON for a few seconds... That is not to say I signed up for AT&T service... I just toggled the Cellular Data switch but I was still running in WiFi mode as always...
    And it worked... Message gone... Other folks on that same post talk about inserting non-active SIM cards into their iPads to clear the error??? Don't know about that but the Cellular Data from default OFF, to ON and then back to OFF has, for the moment anyway, cleared the message for me...
    bob...

  • Error in Update Process for optimistic locking

    Hello,
    I tried to create a tabular form according to this How-To:
    http://www.oracle.com/technology/products/database/application_express/howtos/tabular_form.html
    which worked fine until I tried to implement the optimistic locking.
    I use the same update process:
    declare
    l_cks wwv_flow_global.vc_arr2;
    j pls_integer := 1;
    begin
    -- Get original MD5 checksum
    select wwv_flow_item.md5(job,mgr,hiredate,sal,comm,deptno) cks
    BULK COLLECT INTO
    l_cks
    from emp;
    -- Compare the original checksum, l_cks,
    -- with submitted checksum, htmldb_application.g_fcs.
    -- If they are different, raise an error.
    for i in 1..l_cks.count
    loop
    if htmldb_application.g_fcs(i) != l_cks(i) then
    rollback;
    raise_application_error(
              -20001,
         'Current version of data in database has changed '||
              'since user initiated update process.');
    return;
    end if;
    end loop;
    but as soon as I try to apply the changes in the update process I get an error message saying: PLS-00503: RETURN statement required for this return from function
    So, if i delete the row with the "return;" statement, I get no error anymore, but when I test the optimistic locking I get an error as soon as I try to update a row in the first place.
    What am I doing wrong?
    Johnny
    P.S. : I am using Apex 1.6

    Hi Ant, of course......here is the customized pl/sql block I use:
    declare
    l_cks wwv_flow_global.vc_arr2;
    j pls_integer := 1;
    begin
    -- Get original MD5 checksum
    select wwv_flow_item.md5(partition,desig) cks
    BULK COLLECT INTO
    l_cks
    from UNITS;
    -- Compare the original checksum, l_cks,
    -- with submitted checksum, htmldb_application.g_fcs.
    -- If they are different, raise an error.
    for i in 1..l_cks.count
    loop
    if htmldb_application.g_fcs(i) != l_cks(i) then
    rollback;
    raise_application_error(-20001,'Current version of data in database has changed ' || 'since user initiated update process.');
    -- return;
    end if;
    end loop;
    -- update UNITS
    for i in 1..htmldb_application.g_f08.count
    loop
    if htmldb_application.g_f08(i) is not null then
    update UNITS
    set report_id = :P2_REPORT_ID,
    partition = htmldb_application.g_f10(i),
    desig = htmldb_application.g_f11(i)
    where unit_id = htmldb_application.g_f08(i);
    else
    if htmldb_application.g_f10(i) is not null then
    insert into UNITS
    (report_id,
    partition,
    desig)
    values
    (:P2_REPORT_ID,
    htmldb_application.g_f10(i),
    htmldb_application.g_f11(i));
    end if;
    end if;
    end loop;
    end;
    Thanks
    Johnny

  • Getting ORA-22920 Error With 'FOR UPDATE' clause

    Hello all,
    I scanned through all the messages regarding this error and the suggestion posted was to have 'FOR UPDATE' in the SELECT query. I do have that, but I am still getting ORA-22920 (row containing the LOB value is not locked) error.
    I am using JDBC thin driver with 8.0.5. I know the thin driver installation works because I can read data that I inserted using 'INSERT INTO ...' from svrmgr30.
    Can anyone show me some light on this?
    Thanks
    Suresh

    Hi,
    This helped me:
    Before the insert statement:
    connection.setAutoCommit(false);
    ..what you like to do
    at the end..
    connection.commit()
    HTH
    Martin

  • SAP VBA interfacing - error: FI/CO interface: Inconsistent FI/CO document header data for updating

    Hello,
    Currently I'm working with excel SAP interfacing. For this I am using VBA to call different BAPI functions.
    I have already some interface scripts working, however I have also one which I cannot discover what I'm missing.
    The VBA code is to reach BAPI_ACC_DOCUMENT_POST
    My error is ---> FI/CO interface: Inconsistent FI/CO document header data for updating
    So I'm appealing to you SAP bapi VBA gurus whether you have any ideas how to fix my issue.
    I'm attaching below my code for you to review:
    Option Explicit
    ' Declaration for the necessary objects
    Dim objBAPICortrol, objConnection, objCreateMaterial, objReturn As Object
    Dim objPRFCT, objNTXT, objDTXT As Object
    Dim vLastRow, vRows As Integer
    Dim objMaterial1, objMaterial2, retMess As Object
    Sub Batch()
    ' Getting the last filled Row in Column
    vLastRow = Cells(Rows.Count, "A").End(xlUp).Row
    ' Setting the necessary variables for R/3 connection
    Set objBAPICortrol = CreateObject("SAP.functions")
    Set objConnection = objBAPICortrol.Connection
    objConnection.System = "SYSTEM NAME"
    objConnection.Client = "Client number"
    objConnection.user = "USERNAME"
    objConnection.Password = "PASSWORD"
    objConnection.Language = "EN"
    ' Establish a connection
    If objConnection.logon(0, False) <> False Then
    'MsgBox "Connection Established"
    End If
    On Error Resume Next
    ' Assign the Parameters
    Set objCreateMaterial = objBAPICortrol.Add("BAPI_ACC_DOCUMENT_POST")
    Set objMaterial = objCreateMaterial.Exports.Item("DOCUMENTHEADER")
    Set objMaterial1 = objCreateMaterial.Tables.Item("ACCOUNTGL")
    Set objMaterial2 = objCreateMaterial.Tables.Item("CURRENCYAMOUNT")
    'Set Values
    objMaterial.Value("USERNAME") = "USERNAME"
    objMaterial.Value("HEADER_TXT") = "BAPITEST"
    objMaterial.Value("COMP_CODE") = "0001"
    objMaterial.Value("PSTNG_DATE") = "20140506"
    objMaterial.Value("TRANS_DATE") = "20140506"
    objMaterial.Value("DOC_DATE") = "20140506"
    objMaterial.Value("FISC_YEAR") = "2014"
    objMaterial.Value("DOC_TYPE") = "SA"
    objMaterial.Value("REF_DOC_NO") = "BAPITEST"
    objMaterial.Value("FIS_PERIOD") = "00"
    objMaterial1.Rows.Add
    objMaterial1.Value(1, "ITEMNO_ACC") = "1"
    objMaterial1.Value(1, "GL_ACCOUNT") = "0007180000"
    objMaterial1.Value(1, "ITEM_TEXT") = "BAPITEST1"
    objMaterial1.Value(1, "DOC_TYPE") = "SA"
    objMaterial1.Value(1, "COMP_CODE") = "0001"
    objMaterial1.Value(1, "PROFIT_CTR") = "AZ1111" ---->'profit center is normally having 10CHARS but as there are letters I'm not using zeros at the beginning
    objMaterial1.Value(1, "ITEMNO_ACC") = "2"
    objMaterial1.Value(1, "GL_ACCOUNT") = "0007180000"
    objMaterial1.Value(1, "ITEM_TEXT") = "BAPITEST1"
    objMaterial1.Value(1, "DOC_TYPE") = "SA"
    objMaterial1.Value(1, "COMP_CODE") = "0001"
    objMaterial1.Value(1, "PROFIT_CTR") = "AZ1111"
    objMaterial2.Rows.Add
    objMaterial2.Value(1, "ITEMNO_ACC") = "1"
    objMaterial2.Value(1, "CURRENCY") = "EUR"
    objMaterial2.Value(1, "AMT_DOCCUR") = "-1.00"
    objMaterial2.Value(1, "ITEMNO_ACC") = "2"
    objMaterial2.Value(1, "CURRENCY") = "EUR"
    objMaterial2.Value(1, "AMT_DOCCUR") = "1.00"
    ' Function call
    objCreateMaterial.call
    Set objReturn = objBAPICortrol.Add("BAPI_TRANSACTION_COMMIT")
    objReturn.call
    Set retMess = objCreateMaterial.Tables.Item("RETURN")
    If retMess Is Nothing Then
    MsgBox retMess.Value(1, "MESSAGE")
    End If
    ' Get return parameters & display in excel
    Set objReturn = objCreateMaterial.Tables("RETURN")
    ActiveSheet.Cells(5, 1) = retMess.Value(2, "MESSAGE")
    End Sub

    after some searching I've discovered that once I'm creating next line for accounting document it is not working properly.
    When I debug the BAPI in SE37 after inserting new line it is asking for GL account input, however if I run it using VBA and delete the account from the code, the return message is not giving me any error that GL account is missing.
    I appreciate any ideas.

Maybe you are looking for

  • Document Splitting Function in 6.0 dectvt & reactvt

    Dear All, At our client site, some user with access to customisation, deactivated the Document Splitting by checking the Inactive Tick for the Company Code. This came to light after some days. This directly affected out Business area balance sheet. N

  • Input xml from output xml with reverse transformation

    I have the transformation and the output xml file. Is there any way I get the input message using the trasformation and output message with minor manual changes? Is there any tool for that?

  • Fatal exception while log in to the RPM 14.1

    I have installed the rpm successfully and its configured to work with OID. Application is launching from the JNLP file but when i m trying to log in,it throws the following fatal exception. com.retek.platform.exception.RetekUnknownSystemException: ja

  • Register my printer

    i cant register my printer as it wont take my postal code. it keeps asking for my zip i am in canada . now i have lost the form. No too computer literate

  • Oracle 8i and PHP4

    A quick one for anyone who uses php with oracle i've just recently managed to install 8i properlly and have tried to rebuild apache139 and php4 beta2 with oracle support trouble is it worked great with 8 but the compile of php fails with 8i if anyone