Sequence and insert failure

In a PRE-INSERT trigger, I query my sequence in order to increment my id :
SELECT seq_DocVente.NEXTVAL into :NEW.Code FROM dual;
But when my insertion fails due to a unique constraint (for sample), I loose a value because my sequence is queried but my record not inserted.
Is there a way to prevent this problem ?

Hellow PERRET,
There is a better approach you can follow by Placing the code on a database trigger.
First: Create a Function Called
Get_Seq_Id
like this:
Function Get_Seq_ID Returns NUMBER
IS
Seq NUMBER;
Begin
SELECT seq_DocVente.NEXTVAL
into Seq
FROM dual;
Return Seq;
End Get_Seq_ID;
At this Moment you may do one of the following:
1-Place the Code:
:New.Code in "When-Create-Record"
and not pre-insert ...
2-Or Place it in a DB Trigger:
(And this is better)
Cut this function and then paste it into Stored Procedure node under Database Objects, and then under ur Schema.
Do The Following:
Go to
Database Objects -> schema Name -> Tables ->
Table Name.
double Click on Triggers Node.
you will create a databse Trigger:
1-Click New
2-Choose Triggering: "Before"
3-Then chose "insert" as a Statement.
4-For each - > choose "Row"
in Trigger Body write the folowing
:New.ID := Get_Seq_ID;
click save.
You will see if trigger has been compiled successfully.
To Adjust This Trigger for High Performance, Write the following in the above "When" Box:
New.ID IS NULL.
This Will Prevent concurrent users from inserting any value unless ID IS Null.
Hope This Helps.
Regards,
Tariq
null

Similar Messages

  • Sequence and INSERT ALL INTO with parallelism problem

    I want to use the INSERT ALL INTO style of multiple-inserts (with 10gR2) to normalize a wide table into a skinny table. The large table has a few fk columns and 100 numeric columns. I want to insert them into another table as 100 rows in a single SQL pass.
    CREATE TABLE WIDE_SOURCE(
    FKEY_1 INTEGER,
    FKEY_2 INTEGER,
    FKEY_3 INTEGER,
    AMT001 INTEGER,
    AMT002 INTEGER,
    AMT100 INTEGER);
    CREATE TABLE SKINNY_DEST(
    PKEY INTEGER NOT NULL,
    FKEY_1 INTEGER,
    FKEY_2 INTEGER,
    FKEY_3 INTEGER,
    AMT INTEGER,
    CONSTRAINT PK_SKINNY_DEST PRIMARY KEY(PKEY)
    CREATE SEQUENCE KEY_GEN MINVALUE 1 INCREMENT BY 100 START WITH 1;
    INSERT ALL
    INTO SKINNY_DEST VALUES(KEY_GEN.NEXTVAL+001, FKEY_1, FKEY_2, FKEY_3, AMT001)
    INTO SKINNY_DEST VALUES(KEY_GEN.NEXTVAL+002, FKEY_1, FKEY_2, FKEY_3, AMT002)
    INTO SKINNY_DEST VALUES(KEY_GEN.NEXTVAL+003, FKEY_1, FKEY_2, FKEY_3, AMT003)
    INTO SKINNY_DEST VALUES(KEY_GEN.NEXTVAL+100, FKEY_1, FKEY_2, FKEY_3, AMT100)
    SELECT * FROM WIDE_SOURCE;
    With this query, each row in WIDE_SOURCE will generate 100 rows in SKINNY_DEST. I know that works. Unfortunately, it appears that the sequence isn't working the way I thought it should- with multiple nodes and parallel insert, there's some overlap in the generated key.
    Is there a better way? I've considered 100 separate sequences, but that just seems plain silly. Am I trying to have my cake (the parallelism) and eat it too (by disregarding limitations of Oracle's sequence construct)?

    Have not tested this on a RAC, but it seems to work fine - as expected without any overlaps. (version 10.2.0.1.0)
    SQL> create sequence seq_id start with 1 increment by 10 nomaxvalue nocycle;
    Sequence created.
    SQL> create table skinny ( id number, fk_key1 number );
    Table created.
    SQL> create table wide( fk_key1 number, name varchar2(32) ) parallel( degree 2 );
    Table created.
    SQL> insert into wide select object_id, object_name from all_objects where rownum < 100000;
    51853 rows created.
    SQL> commit;
    Commit complete.
    SQL> exec DBMS_STATS.Gather_Table_Stats( USER, 'WIDE' );
    PL/SQL procedure successfully completed.
    SQL> alter session enable parallel dml;
    Session altered.
    SQL> set autotrace on
    SQL> insert all
    2 into skinny values( seq_id.nextval+0, fk_key1 )
    3 into skinny values( seq_id.nextval+1, fk_key1 )
    4 into skinny values( seq_id.nextval+2, fk_key1 )
    5 into skinny values( seq_id.nextval+3, fk_key1 )
    6 into skinny values( seq_id.nextval+4, fk_key1 )
    7 into skinny values( seq_id.nextval+5, fk_key1 )
    8 into skinny values( seq_id.nextval+6, fk_key1 )
    9 into skinny values( seq_id.nextval+7, fk_key1 )
    10 into skinny values( seq_id.nextval+8, fk_key1 )
    11 into skinny values( seq_id.nextval+9, fk_key1 )
    12 select
    13 /*+ FULL(o) PARALLEL(w,2) */
    14 fk_key1
    15 from wide w
    16 /
    518530 rows created.
    Execution Plan
    Plan hash value: 1585486391
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
    | 0 | INSERT STATEMENT | | 51853 | 253K| 37 (14)| 00:00:01 | | | |
    | 1 | MULTI-TABLE INSERT | | | | | | | | |
    | 2 | INTO | SKINNY | | | | | | | |
    | 3 | INTO | SKINNY | | | | | | | |
    | 4 | INTO | SKINNY | | | | | | | |
    | 5 | INTO | SKINNY | | | | | | | |
    | 6 | INTO | SKINNY | | | | | | | |
    | 7 | INTO | SKINNY | | | | | | | |
    | 8 | INTO | SKINNY | | | | | | | |
    | 9 | INTO | SKINNY | | | | | | | |
    | 10 | INTO | SKINNY | | | | | | | |
    | 11 | INTO | SKINNY | | | | | | | |
    | 12 | SEQUENCE | SEQ_ID | | | | | | | |
    | 13 | PX COORDINATOR | | | | | | | | |
    | 14 | PX SEND QC (RANDOM)| :TQ10000 | 51853 | 253K| 37 (14)| 00:00:01 | Q1,00 | P->S | QC (RAND) |
    | 15 | PX BLOCK ITERATOR | | 51853 | 253K| 37 (14)| 00:00:01 | Q1,00 | PCWC | |
    | 16 | TABLE ACCESS FULL| WIDE | 51853 | 253K| 37 (14)| 00:00:01 | Q1,00 | PCWP | |
    Statistics
    37168 recursive calls
    26542 db block gets
    7610 consistent gets
    0 physical reads
    12696752 redo size
    498 bytes sent via SQL*Net to client
    1084 bytes received via SQL*Net from client
    6 SQL*Net roundtrips to/from client
    3 sorts (memory)
    0 sorts (disk)
    518530 rows processed
    SQL> set autotrace off
    SQL> commit;
    Commit complete.
    SQL> select
    2 id, count(*)
    3 from skinny
    4 group by id
    5 having count(*) > 1
    6 /
    no rows selected
    SQL>
    I checked the PQ V$ views and PQ slaves were used.

  • Database Adapter: Insert, relationships, sequences and problems of course

    Hello Everyone!!
    I'm trying to do an insert in an Oracle Express Database with a database adapter. I'm trying to do the insert in two tables: SOLICITUDES with a column called NUMSOLICITUD that is also the primary key of the table and it's populated from its own sequence and the other table whose name is DOCJUST with a field NUMSOL. SOLICITUDES has a 1:M relationship with DOCJUST and the fields used in this relationship are NUMSOLICITUD and NUMSOL. The problem is that when the adapter do the insert, the first insert made on SOLICITUDES is correct, but when it tries to insert in the DOCJUST table, when it's supposed to insert in NUMSOL the same value inserted in NUMSOLICITUDES instead of that, a NULL value is inserted in NUMSOL so the process fails. Is it because the NUMSOLICITUDES column is populated from a sequence? How can I resolve that?
    Thanks!!

    Hi,
    OK, I found the following article: http://soa-bpel-esb.blogspot.com/2010/04/understanding-catch-and-catchall.html
    Using the info from that article I have created a test flow, which contains the same insert database adapter as the production flow. I have placed the Invoke within its own scope and attached a "CatchAll" block to this scope. To this block I have added a "empty" step (do nothing).
    In my tests, I see the desired results i.e. the second time I initiate the flow with the same data, the CatchAll block executes, which does nothing, and processing continues after the scope.
    So far so good - my query is how would I catch the specific error of unique index violation rather than general catchall?
    As before, and assistance/comments greatly appreciated.
    Anit

  • Activate or skip "Record Results" and "Step Failure Cause Sequence Failure" for all steps of a step type

    Hello all,
    I am using teststand 3.1
    Is it possible to skip or activate ´"Record Results" and "Step Failure Cause Sequence Failure" for all steps of a step type.
    It is very much work to do this for all steps, because I have hundred of steps
    regards
    samuel

    hi,
    here is an example that will change the TS.NoResult. You just have to change this area of the sequence to suit your needs
    I haven't added any fancy stuff, such as adding a filedialog to get the seq file to change, you will find the various variables in the Locals.
    Hope it helps
    There is a version for 3.1 and 3.5.
    Regards
    Ray Farmer
    Regards
    Ray Farmer
    Attachments:
    ChangeStepTypeRunMode.zip ‏30 KB

  • Sequence and Hot spot questions in Capt 5

    I am trying to set up a questionary in capt 5, there are two options that i have not idea how to edit or what would be the best way of using (sequence and hotspot)
    any helps is greatly appreciated

    You just insert both questions using the Quiz, Question slide option. I would recommend to use the workspace Quizzing, because you'll need both the Quiz Properties and the Properties panel. In the Quizzing workspace those panels are in different docking stations.
    In the Quiz Properties panel: choose the number of items for the Sequence question, and the points to be attributed. You have the choice also to have the user drag the items or to use a dropdown list (Answer Type) and the numbering style. You can choose the buttons to add, eventually actions to be performed on Success/Failure and reporting (which will be checked by default). Then you have to edit all the text captions, you can use the Properties panel if you want to change their style.
    For hotspot: in Quiz Properties panel choose the number of hotspots you want to have and the score. The hotspots are by default the blue rectangles, all checked as correct (watch the small tick at the bottom right). You can drag the hotspots over the image or wherever you want them to be. You can indicate the hotspot to be incorrect in the Properties panel of that hotspot (uncheck Correct answer), where you also can indicate if a hand cursor should appear, and the style of the hotspot.
    Hope this helps?
    Lilybiri

  • Problem with overwrite and insert keyboard commands

    I'm a new user, switching from FCP. I edited one project successfully with no trouble a couple of weeks ago. Now I'm in a second project and having a weird difficulty. Using a pretty new Mac 8 core tower.
    The insert and overlay keyboard commands (comma and period keys) don't work. They still work in the old project but not this one. If I start a new sequence and copy my timeline to it, the commands will work for awhile but ONLY with video, not with the audio tracks. Drag and drop works fine but that really slows me down.
    The clips I'm using are all the same format (H.264 from Canon 5DII and some still photos) as the first project. Only difference in this project is lots of chroma keying and some resizing of background still photos. Nothing unrendered.
    I started a new project just now and imported the problem project into it, started a new sequence, copied old sequence, and I get the same problem. I can drop in video with a keyboard command but not audio. Earlier it was not even doing video. Yesterday when I'd start a new sequence and do the same thing, it would give me video on the keyboard command but then eventually that would stop and it would do nothing. At one point the cursor would move over the width of the clip, as if it had been dropped into the timeline, but then that stopped as well.
    I've trashed preferences and that didn't work. I did that according to a procedure I found online. It said open up PP while holding down the Shift and Option keys. I did that twice. Nothing.
    To summarize: Keyboard commands for overwrite and insert edit do not work in this project but do in an older project.
    Any ideas?
    Thanks.
    Bill Pryor
    [email protected]

    Well, thanks to an email from another person who was having the same problem, it's all solved not.
    Operator error. Dang. Who knew--in FCP you select a track by clicking on the V or A buttons to the far left. In Premiere Pro you have to make sure BOTH the far left button and the one to the right that says Video 1, Audio 1, etc. are also clicked. They BOTH have to be light gray. In my first project, everything was properly activated but in the next project apparently they were not and that carried over to succeeding projects (even though I didn't change anything...at least consciously).
    So all as well now. No glitch, no bug. Just good ol' fashioned operator error. I will wear the dunce hat today.

  • How do I create a 1d array that takes a single calculation and insert the result into the first row and then the next calculation the next time the loop passes that point and puts the results in thsecond row and so on until the loop is exited.

    The attached file is work inprogress, with some dummy data sp that I can test it out without having to connect to equipment.
    The second tab is the one that I am having the problem with. the output array from the replace element appears to be starting at the index position of 1 rather than 0 but that is ok it is still show that the new data is placed in incrementing element locations. However the main array that I am trying to build that is suppose to take each new calculation and place it in the next index(row) does not ap
    pear to be working or at least I am not getting any indication on the inidcator.
    Basically what I am attempting to do is is gather some pulses from adevice for a minute, place the results for a calculation, so that it displays then do the same again the next minute, but put these result in the next row and so on until the specifiied time has expired and the loop exits. I need to have all results displayed and keep building the array(display until, the end of the test)Eventually I will have to include a min max section that displays the min and max values calculated, but that should be easy with the min max function.Actually I thought this should have been easy but, I gues I can not see the forest through the trees. Can any one help to slear this up for me.
    Attachments:
    regulation_tester_7_loops.vi ‏244 KB

    I didn't really have time to dig in and understand your program in depth,
    but I have a few tips for you that might things a bit easier:
    - You use local variables excessively which really complicates things. Try
    not to use them and it will make your life easier.
    - If you flowchart the design (very similar to a dataflow diagram, keep in
    mind!) you want to gather data, calculate a value from that data, store the
    calculation in an array, and loop while the time is in a certain range. So
    theres really not much need for a sequence as long as you get rid of the
    local variables (sequences also complicate things)
    - You loop again if timepassed+1 is still less than some constant. Rather
    than messing with locals it seems so much easier to use a shiftregister (if
    absolutely necessary) or in this case base it upon the number of iterations
    of the loop. In this case it looks like "time passed" is the same thing as
    the number of loop iterations, but I didn't check closely. There's an i
    terminal in your whileloop to read for the number of iterations.
    - After having simplified your design by eliminating unnecessary sequence
    and local variables, you should be able to draw out the labview diagram.
    Don't try to use the "insert into array" vis since theres no need. Each
    iteration of your loop calculates a number which goes into the next position
    of the array right? Pass your result outside the loop, and enable indexing
    on the terminal so Labview automatically generates the array for you. If
    your calculation is a function of previous data, then use a shift register
    to keep previous values around.
    I wish you luck. Post again if you have any questions. Without a more
    detailed understanding of your task at hand it's kind of hard to post actual
    code suggestions for you.
    -joey
    "nelsons" wrote in message
    news:[email protected]...
    > how do I create a 1d array that takes a single calculation and insert
    > the result into the first row and then the next calculation the next
    > time the loop passes that point and puts the results in thsecond row
    > and so on until the loop is exited.
    >
    > The attached file is work inprogress, with some dummy data sp that I
    > can test it out without having to connect to equipment.
    > The second tab is the one that I am having the problem with. the
    > output array from the replace element appears to be starting at the
    > index position of 1 rather than 0 but that is ok it is still show that
    > the new data is placed in incrementing element locations. However the
    > main array that I am trying to build that is suppose to take each new
    > calculation and place it in the next index(row) does not appear to be
    > working or at least I am not getting any indication on the inidcator.
    >
    > Basically what I am attempting to do is is gather some pulses from
    > adevice for a minute, place the results for a calculation, so that it
    > displays then do the same again the next minute, but put these result
    > in the next row and so on until the specifiied time has expired and
    > the loop exits. I need to have all results displayed and keep building
    > the array(display until, the end of the test)Eventually I will have to
    > include a min max section that displays the min and max values
    > calculated, but that should be easy with the min max function.Actually
    > I thought this should have been easy but, I gues I can not see the
    > forest through the trees. Can any one help to slear this up for me.

  • Creation of sequence and trigger for each table!!!!!!!1

    Hi
    I am new to trigger and Sequence field. In one of my database we have many tables with fields for specifing ID numbers. Iam planning to insert the ID field with help of a Sequence and trigger...that trigger fires by adding the sequence value from the dual table. Now the point is here we r having around *60* table with ID field. And i am planning use the above process for each table by creating sequences and trigger for each table.
    Will this affects the performance of database.
    Is there any other option other than the above process, I mean other than creating sequences and trigger for each table.
    PLzz help to resolve this issuee......
    Shiyas
    Edited by: user13170361 on Jun 7, 2010 12:37 AM

    Tiger, I didn't mind about your comment, but the point is try to use
    select NVL(max(a) + 1,1) into i from p1_temp;This line in your trigger code and see what is happening. The problem is with your trigger. You are using group by function and you will not get no_data_found !
    For more help, this is some modification of your code.
    SQL> create table p1_temp (a number(10) primary key, b number(10));
    Table created.
    SQL> create or replace trigger trg_p1_temp
      2  before insert on p1_temp for each row
      3  declare
      4  i number(10);
      5  begin
      6  begin
      7  select NVL(max(a) + 1,1) into i from p1_temp;
      8  exception
      9  when no_data_found then
    10  i := 1;
    11  end;
    12  :new.a := i;
    13  end;
    14  /
    Trigger created.
    SQL> insert into p1_temp(b) values (1);
    1 row created.
    SQL> insert into p1_temp(b) values (2);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from p1_temp;
             A          B
             1          1
             2          2
    SQL> Edited by: Saubhik on Jun 7, 2010 2:30 AM

  • Best practices with sequences and primary keys

    We have a table of system logs that has a column called created_date. We also have a UI that displays these logs ordered by created_date. Sometimes, two rows have the exact same created_date down to the millisecond and are displayed in the UI in the wrong order. The suggestion was to order by primary key instead since the application uses an oracle sequence to insert records so the order of the primary key will be chronological. I felt this may be a bad idea as a best practice since the primary key should not be used to guarantee chronological order although in this particular application's case, since it is not a multi-threaded environment, it will work so we are proceeding with it.
    The value for the created_date is NOT set at the database level (as sysdate) but rather by the application when it creates the object which is persisted by Hibernate. In a multi-threaded environment, thread A could create the object and then get blocked by thread B which is able to create the object and persist it with key N after which control returns to thread A it persists it with key N+1. In this scenario thread A has an earlier timestamp but a larger key so will be ordered before thread B which is in error.
    I like to think of primary keys as solely something to be used for referential purposes at the database level rather than inferring application level meaning (like the larger the key the more recent the record etc.). What do you guys think? Am I being too rigorous in my views here? Or perhaps I am even mistaken in how I interpret this?

    >
    I think the chronological order of records should be using a timestamp (i.e. "order by created_date desc" etc.)
    >
    Not that old MYTH again! That has been busted so many times it's hard to believe anyone still wants to try to do that.
    Times are in chronological order: t1 is earlier (SYSDATE-wise) than t2 which is earlier than t3, etc.
    1. at time t1 session 1 does an insert of ONE record and provides SYSDATE in the INSERT statement (or using a trigger).
    2. at time t3 session 2 does an insert of ONE record and provides SYSDATE
    (which now has a value LATER than the value used by session 1) in the INSERT statement.
    3. at time t5 session 2 COMMITs.
    4. at time t7 session 1 COMMITs.
    Tell us: which row was added FIRST?
    If you extract data at time t4 you won't see ANY of those rows above since none were committed.
    If you extract data at time t6 you will only see session 2 rows that were committed at time t5.
    For example if you extract data at 2:01pm for the period 1pm thru 1:59pm and session 1 does an INSERT at 1:55pm but does not COMMIT until 2:05pm your extract will NOT include that data.
    Even worse - your next extract wll pull data for 2pm thru 2:59pm and that extract will NOT include that data either since the SYSDATE value in the rows are 1:55pm.
    The crux of the problem is that the SYSDATE value stored in the row is determined BEFORE the row is committed but the only values that can be queried are the ones that exist AFTER the row is committed.
    About the best you, the user (i.e. not ORACLE the superuser), can do is to
    1. create the table with ROWDEPENDENCIES
    2. force delayed-block cleanout prior to selecting data
    3. use ORA_ROWSCN to determine the order that rows were inserted or modified
    As luck would have it there is a thread discussing just that in the Database - General forum here:
    ORA_ROWSCN keeps increasing without any DML

  • Help on Sequence and Procedure

    Hi all,
    I have a situation like this
    I have 10 different tables like a,b,c,d,e,f
    But i have same columns in all tables
    like
    id
    Created_date,
    Current_user,
    updated_by,
    updated_date
    I created a sequence and triggers on a table like below
    CREATE SEQUENCE x_SEQUENCE START WITH
    150001 INCREMENT BY 1 MAXVALUE 999999
    CYCLE;
    CREATE TRIGGER xi_trigger
    BEFORE INSERT ON x_table FOR EACH ROW
    BEGIN
    SELECT x_SEQUENCE.NextVal,USER,SYSDATE INTO :NEW.CTUT_ID,
    :NEW.CURRT_USER_ID,:NEW.CREATED_DATE FROM DUAL;
    :NEW.CREATED_BY := :NEW.CTUT_ID;
    END;
    CREATE TRIGGER xU_trigger
    BEFORE UPDATE ON x_table FOR EACH ROW
    BEGIN
    SELECT USER,SYSDATE INTO :NEW.CURRT_USER_ID,:NEW.UPDATED_DATE FROM DUAL;
    :NEW.UPDATED_BY := :NEW.CTUT_ID;
    END;
    everything is working fine for one table
    1) Can anybody help me how to create a procedure with Trigger code
    so that i can call that procedure in all tables
    like
    CREATE TRIGGER xi_trigger
    BEFORE INSERT ON x_table FOR EACH ROW
    BEGIN
    x_procedure;
    end;
    2) When sequence is completed i mean when it reach max value how to display message
    Thanks for your help

    Here's one way of doing it:
    CREATE PROCEDURE audit_action
      ( pn_id OUT NUMBER
        , pv_by OUT VARCHAR2
        , pd_on OUT DATE )
    IS
       ln_seq NUMBER;
       ld_on DATE;
       lv_by VARCHAR2(30);
       x_seq exception;
       pragma exception_init(x_seq, -8004);
    BEGIN
       SELECT my_seq.NEXTVAL, USER, SYSDATE
       INTO   ln_seq, lv_by, ld_on
       FROM   dual;
       pn_id := ln_seq;
       pv_by := lv_by;
       pd_on := ld_on;
    EXCEPTION
       WHEN x_seq
       THEN
          RAISE_APPLICATION_ERROR(-8004, 'MY_SEQ has run out of numbers!');
    END audit_action;
    /and here's how you call it:
    CREATE TRIGGER xi_trigger
    BEFORE INSERT ON x_table FOR EACH ROW
    BEGIN
        audit_action (:NEW.ctut_id, :NEW.currt_user, :NEW.created_date);
    END xi_trigger; Warning: I have not run this code (can't be bothered with the set-up) but it is logically correct, so it should work with (at worst) minor syntactical tweaking.
    Cheers, APC
    P.S. CURRENT_USER is a misleading column name, it ought to be called CREATED_BY.
    P.P.S. It is very bad practice to have sequences run out at all. Unless you have a very good reason I strongly urge you not to set MAXVALUE when you create your sequences.

  • Does the sequence of Insert/Update matter?

    Dear friends
    I wanted to know whether there is any difference in results if I change the sequence of Insert/Update statements. For example, if I'm inserting / updating records in a table, normally I write my code as below
    <code>
    Begin
    Insert Into Table Name(...)
    Values(...);
    Exception
    When Dup_Val_On_Index Then
    Update Table Name Set
    Column_Name = Value;
    When Others Then
    Sqlerrm;
    End;
    </code>
    Lets assume, if I change the order of statements as below:
    <code>
    Begin
    Update Table Name Set
    Column_Name = Value;
    If Sql%NotFound Then
    Begin
    Insert Into Table Name(...)
    Values(...);
    End;
    Exception
    When Others Then
    Sqlerrm;
    End;
    </code>
    So does this change make any difference in net results?

    Yes...till before today morning, it had no difference to me too, but today I was facing an insertion problem in a procedure in which insert statement had to go into when_dup_val exception part after first record and execute update statement. But surprisingly, it was going into when_dup_val only for 2nd record, i.e. 1st record was inserted as new record, then 2nd record had same primary key values, so when_dup_val caused to execute update statement, and lastly for 3rd record, having same primary key values, instead of executing update statement, insertion was going into when_others exception part and raising error ORA-01008.
    After very detailed hit n trial, I just reversed the operations, took udpate statement before insert in my code and then all the things got right. Procedure is executing finely.
    Although I've resolved the issue but I couldn't digest this change, thats why asking you peeps the operations behind.

  • Contradiction: SEQUENCE and AUTO_INCREMENT

    Most recommendations tell: You have to use SEQUENCE instead of an auto_increment column. In contradiction to this I found the following AUTO INCREMENT feature in Oracle® Database Lite SQL Reference 10g (10.2.0):
    4.3.18 CREATE TABLE
    auto increment      Set the column to auto increment column... The value of an auto increment column is auto incremented and inserted, so that the user does not have to provide the value...
    [Oracle Lite 10g Documentation|http://download.oracle.com/docs/cd/B19188_01/doc/B15917/sqcmd.htm#sthref478]
    What now? Can someone explain this?
    * In which Oracle versions is auto increment available, in which not?
    * Is "auto increment" (with space inside) the correct spelling, indeed?
    * If "auto increment" is available, should one better use this feature or SEQUENCE?
    I know that SEQUENCE doesn't concern to a specific table, but to the database itself.
    Thank you for answer! Juergen
    PS. I myself don't use Oracle DB, but Firebird. I'm an author of a German Wikibook "Introduction to SQL" and want to describe correct context.

    1. Is it a Database Lite feature. ( It's forum is @ Database Mobile Server (inc. legacy Database Lite) )
    In Oracle RDBMS you'll need a sequence.
    2. Seems correctly spelled to me.
    3. use an Oracle Sequence.
    You will rather want to check the RDBMS documentation as well:
    http://www.oracle.com/pls/db102/homepage
    http://www.oracle.com/pls/db112/homepage

  • Sequence in insert all

    Hi,
    I'm using a sequence in INSERT ALL statement. I want to insert multiple rows using a sequence number which will be generating the unique values for my table. But as far as i know, Oracle treats all occurances of a seq.nextval as a single reference and all of them retains the same value and not different one. My query is as below.
    insert all
    into t1(c1, c2) values (seq_1.nextval, 'A')
    into t1(c1, c2) values (seq_1.nextval, 'B')
    select * from dual;
    select * from t1;
    C1     C2
    8     A
    8     B
    Can some one tell me how can i have different values for each row in insert all statement?

    Create a function:
    SQL> create or replace
      2  function get_seq_1
      3  return number
      4  is
      5  v_ret number;
      6  begin
      7      select seq_1.nextval into v_ret from dual;
      8      return v_ret;
      9  end;
    10  /
    Function created.
    SQL> insert all
      2  into t1(c1, c2) values (seq_1.nextval, 'A')
      3  into t1(c1, c2) values (seq_1.nextval, 'B')
      4  select * from dual;
    2 rows created.
    SQL>
    SQL> select * from t1;
            C1 C2
             1 A
             1 B
    SQL> insert all
      2  into t1(c1, c2) values (get_seq_1, 'A')
      3  into t1(c1, c2) values (get_seq_1, 'A')
      4  select * from dual;
    2 rows created.
    SQL> select * from t1;
            C1 C2
             1 A
             1 B
             2 A
             3 A
    SQL> SY.

  • Help with Sort sequence and reset preferences

    Hi,
    I have checked the "sort" checkboxes and the "sort sequence" in my first 5 columns of the sql report. The sequence are straight 1,2,3,4,5.
    I have also create two buttons. The first one that will trigger a pl/sql that would execute RESET_USER_PREFERENCES built-in package, and a second button that just submit. The page submit to itself by default.
    It appears that the Reset Preferences does not follow the "sort sequences". Take a look at: http://htmldb.oracle.com/pls/otn/f?p=15031:2:
    Check what happen with the second column OBJECT NAME: I expect to see CUSTOM_AUTH first and then CUSTOM_HASH second once you Reset User Preferences. Interesting is that when I just press the refresh button, then i get what I want, but i think that is just coincidence as there is not guarantee that the data are going to be displayed in that order once you start deleting and inserting in the middle.
    Any help in order to understand the "sort sequences" concept is appreciated.
    Thanks

    Anybody?

  • Oracle jdbc creating a table, sequence and trigger

    I'm trying to create a table with a sequence and with a trigger for that sequence. When I do this within Oracle Express edition I have the following SQL statements. Which DO run correctly inside Oracle Express using the same user I log in with JDBC.
    CREATE table "TEST" (
    "ID" NUMBER(10) NOT NULL,
    "NAME" VARCHAR2(20),
    constraint "TEST_PK" primary key ("ID")
    CREATE sequence "TEST_SEQ"
    CREATE trigger "BI_TEST"
    before insert on "TEST"
    for each row
    begin
    if :NEW."ID" is null then
    select "TEST_SEQ".nextval into :NEW."ID" from dual;
    end if;
    end;
    So now what I do is put each of these into a List of Strings and execute 1 by one like this:
    List<String> commands = new ArrayList<String>(4);
    commands.add("Create table ...");
    commands.add("Create sequence ...");
    commands.add("Create trigger...");
    st = con.createStatement();
    for (String command : commands) {
    st.execute(command);
    etc...
    But I get an error with the trigger statement. "Error with Oracle command: ORA-00942: table or view does not exist"
    It seems to me that Oracle has not yet seen the new table at this point. or maybe my user can create tables but not triggers? If that's the case why did it work in the express application itself?
    TIA

    SproketBoy wrote:
    But I get an error with the trigger statement. "Error with Oracle command: ORA-00942: table or view does not exist"Keep in mind: Oracle is not lying to you.
    >
    It seems to me that Oracle has not yet seen the new table at this point. or maybe my user can create tables but not triggers? If that's the case why did it work in the express application itself?No, DDL commands cause an explicit commit. As soon as you invoke them, the change is permanent. If it was a rights problem, you'd get a different ORA error stating that, it won't silently fail.
    Lets not assume it is anything difficult, perhaps there is simply a typo in a name somewhere?

Maybe you are looking for

  • Unable to convert the sender service to an ALE logical syst

    Hi, My scenario is IDOC to File. SLD:Configured Correctly ,ABAP Business System. Imported the same in ID,under Adapter specific Identifiers gava the Logical system as in WE20. In the Receiver Agreement,Header mapping tried giving the sender service,R

  • Urgent : Change in displayed column name of the Metadata

    Hi friends, I am required to dispaly a field called "Ansprechpartner" in my layout set. As I did not get any corresponding Metadata for it in the ContentManagement, I used the owner field instead. But the Deutche name for it on doing language change

  • Dual-Boot Macbook

    I'm trying to dual boot OS X and arch on my macbook, but whenever I try and boot into arch I just get a "Missing Operating System" error that I can't seem to fix. Any ideas? EDIT: I think it's a problem with the way refit is syncing the gpt/mbr parti

  • Two services under one roadmap

    Dear All, Here we have a requirement that  to bring two or more standard ESS Services and one custom service under one roadmap Is it possible? thanks in advance sera

  • APD erases old ODS data

    I am using an APD to load a ODS from a query. However, the old data gets deleted every time I execute the APD and do a new load. How can I overcome this and keep the old data as well?