Question on Sequence..

There is an primary key in my table which is assigned value from a sequence.
For this i first fetch the value from sequence and assign it to the column while inserting.
My question is :
How can i reset the value of the sequence in case if the insertion operation fails..
Regards
Kaustubh

You cannot rollback the sequence value.Don't give up so easily. Here's a very basic example of what you can do. It's not the ideal coding, but it shows the principle.
SQL> create table x (id number, x number);
Table created.
SQL>
SQL> create sequence myseq;
Sequence created.
SQL>
SQL> declare
  2    procedure insertval(x varchar2) is
  3      sq number;
  4    begin
  5      select myseq.nextval into sq from dual;
  6      dbms_output.put_line('attempting to insert sequence : '||sq);
  7      execute immediate ('insert into x values ('||sq||', '||x||')');
  8      dbms_output.put_line('success');
  9    exception
10      when others then
11        dbms_output.put_line('failure');
12        execute immediate ('alter sequence myseq increment by -1');
13        declare
14          dummy number;
15        begin
16          execute immediate ('select myseq.nextval from dual') into dummy;
17          dbms_output.put_line('sequence rolled back by 1 to '||dummy);
18        end;
19        execute immediate ('alter sequence myseq increment by 1');
20    end;
21  begin
22    insertval('1');
23    insertval('2');
24    insertval('a');
25    insertval('3');
26    insertval('4');
27  end;
28  /
attempting to insert sequence : 1
success
attempting to insert sequence : 2
success
attempting to insert sequence : 3
failure
sequence rolled back by 1 to 2
attempting to insert sequence : 3
success
attempting to insert sequence : 4
success
PL/SQL procedure successfully completed.
SQL>
SQL> select * from x;
        ID          X
         1          1
         2          2
         3          3
         4          4
SQL>

Similar Messages

  • Question regarding sequences and fragmented data

    Hi all,
    I plan to implement two identical database schemas on two different oracle database servers. The two databases will then be linked via a Database Link and a View will be used to show the data from both db's using 1 sql statement.
    My question is this:
    If 5 records are inserted into the table on the first database and then 10 records are inserted into the matching table on the second database, how would the sequence for the table in the first database know that the next value should be 16 and not 6.
    I hope this makes sense, any questions just ask.
    Thanks,
    Martin

    Ok, I am not sure if I fully undserstand the question but let's give it a go. In the first place a sequence is stored in the data dictionary of a database. Te fact that you have two servers (and two databases : is that correct ?) means that you have two sequences also. The sequence is local to each db.
    If you want the tables to be aware of each other so that the next record takes into account also the records in the other db you may have to manually generate the sequence. I don't know if you can share the sequence between two dbs but let's see if anyone else does.
    Regards

  • Four fundamental questions on Sequences

    DB version:11G
    Question *1* and *2*:
    To determine the current value of a Sequence i try
    SQL> SELECT  SEQ_SHP_HDR.CURRVAL FROM DUAL;
    SELECT  SEQ_SHP_HDR.CURRVAL FROM DUAL
    ERROR at line 1:
    ORA-08002: sequence SEQ_SHP_HDR.CURRVAL is not yet defined in this
    sessionI know that if i use
    SELECT  SEQ_SHP_HDR.NEXTVAL FROM DUAL;i can get CURRVAL from the sequence. But that will increment the sequence.
    So I tried looking at user_sequences.last_number . But user_sequences.last_number was showing 552 when the actual currval was 545 !
    Why am i getting the above error (SEQ_SHP_HDR.CURRVAL is not yet defined in this session) and how can one accurately determine
    the currval of a sequence without incrementing it using NEXTVAL?
    Question *3*.
    To Increment a sequence, one should use
    alter sequence <sequencename> increment by n ;Right?
    Do you guys use
    SELECT  <sequencename>.NEXTVAL FROM DUAL;to increment SEQUENCES?
    Question *4*.
    I was trying to increment a sequence. After the ALTER statement, the sequence didn't get incremented. I had to issue a NEXTVAL call to actually get this reflected. Why is this happening?
    SQL> select * from v$version where rownum=1;
    BANNER
    Oracle Database 11g Release 11.1.0.7.0 - 64bit Production
    SQL> CREATE SEQUENCE myseq
      2    START WITH 1
      3    NOMAXVALUE;
    Sequence created.
    SQL> select myseq.nextval from dual;
       NEXTVAL
             1
    SQL> alter sequence myseq increment by 7;
    Sequence altered.
    SQL> select myseq.currval from dual;
       CURRVAL
             1
    SQL> select myseq.nextval from dual;
       NEXTVAL
             8
    SQL> select myseq.currval from dual;
       CURRVAL
             8
            

    Steve_74 wrote:
    DB version:11G
    Question *1* and *2*:
    To determine the current value of a Sequence i try
    SQL> SELECT  SEQ_SHP_HDR.CURRVAL FROM DUAL;
    SELECT  SEQ_SHP_HDR.CURRVAL FROM DUAL
    ERROR at line 1:
    ORA-08002: sequence SEQ_SHP_HDR.CURRVAL is not yet defined in this
    sessionI know that if i use
    SELECT  SEQ_SHP_HDR.NEXTVAL FROM DUAL;i can get CURRVAL from the sequence. But that will increment the sequence.
    So I tried looking at user_sequences.last_number . But user_sequences.last_number was showing 552 when the actual currval was 545 !
    Why am i getting the above error (SEQ_SHP_HDR.CURRVAL is not yet defined in this session) and how can one accurately determine
    the currval of a sequence without incrementing it using NEXTVAL?You cant get the CURRVAL unless you execute the NEXTVAL alteast once in your session. And you cant use the user_sequences.last_number if the CACHE is enabled.
    Question *3*.
    To Increment a sequence, one should use
    alter sequence <sequencename> increment by n ;Right?WRONG!! You have actually altered the structure of your sequence. With ALTER comand you are actually setting the increment value. Here "n" sets the increment size. If set as 1 it will increment by 1. If set as 2 will increment by 2.
    Do you guys use
    SELECT  <sequencename>.NEXTVAL FROM DUAL;to increment SEQUENCES?YES that is the correct way to increment a sequence. Use NEXTVAL to increment a sequence.
    Question *4*.
    I was trying to increment a sequence. After the ALTER statement, the sequence didn't get incremented. I had to issue a NEXTVAL call to actually get this reflected. Why is this happening?
    SQL> select * from v$version where rownum=1;
    BANNER
    Oracle Database 11g Release 11.1.0.7.0 - 64bit Production
    SQL> CREATE SEQUENCE myseq
    2    START WITH 1
    3    NOMAXVALUE;
    Sequence created.
    SQL> select myseq.nextval from dual;
    NEXTVAL
    1
    SQL> alter sequence myseq increment by 7;
    Sequence altered.
    SQL> select myseq.currval from dual;
    CURRVAL
    1
    SQL> select myseq.nextval from dual;
    NEXTVAL
    8
    SQL> select myseq.currval from dual;
    CURRVAL
    8
    Answer for the question 3 answers this one as well!!

  • HOWTO QUESTION: inout sequences from client

    Does anyone understand how to handle inout sequences in Java. I have to call a CORBA server method that accepts an inout sequence of structures. I can invoke the method, but how do I access the return values?

    As far as I understand this topic, this is the task of
    the holder objects. For example, if you have a method
    in IDL
    void foo(inout MyObject obj);
    It will be converted to Java
    void foo(MyObjectHolder obj);
    You would use it by invoking
    MyObject obj = new MyObject();
    MyObjectHolder objHolder = new
    new MyObjectHolder(obj);
    myXYServer.foo(objHolder);
    // now do something with obj
    objHolder.value.doSomething()
    I believe the question is to manipulate the inout variable. An 'inout' is a variable that originate from the
    client, but can be altered by the server and sent back to the client
    struct inItem
         string key;
         string value;
    }; // inItem
    struct outItem
         string key;
         string value;
    }; // outItem
    struct inoutItem
         string key;
         string value;
    }; // outItem
    typedef sequence <inoutItem> inoutResponse;
    interface InfoRoamServer
         long processData(in Intype inreq, out outType, inout inoutResponse response);
    The java code generated should include Helper and Holder for each of the struct, use them to
    set/get data from response object
    If we initialize
    inoutResponseHolder response = new inoutResponseHolder();
    Set value
    response.value =...
    to get Value
    = response.value ;

  • App-V 4.6 - A question about sequencing Add-ons

    Hello,
    just a short question about app-v and add-ons:
    I want to sequence and publish an add-on for Microsoft Excel in app-v 4.6. But is it right that (if i want to use an add-on later) i have to use a virtual (sequenced) primary program?
    I do not find these information during my research and I am not really shure about it.
    It would be nice if it is possible to use a sequenced add-on with a local installation of e.g. Excel.
    Thank you very much!
    Gruß ST_Jan

    Hello,
    No, you can sequence the add-in and then create a shortcut to Excel.
    See this generic guide;
    http://blogs.technet.com/b/gladiatormsft/archive/2012/09/02/app-v-4-6-oldie-but-goodie-using-url-shortcuts-to-simply-user-experience-when-running-virtualized-ie-plug-ins-plus-a-bonus-tip.aspx
    and this topic;
    http://blogs.technet.com/b/virtualvibes/archive/2013/05/01/sequencing-a-shortcut-in-app-v-4-6-local-and-virtual-interaction.aspx
    Nicke Källén | The Knack| Twitter:
    @Znackattack

  • Question Type 'Sequence' with thumbnails?

    Hi all,
    I would like to know, if there is a work around in Captivate 3 to build a 'Sequence' question using images rather than text.
    Would be great, if the solution (if any) was applicable to other question types like 'Multiple Choice' as well.
    I checked, if this feature is supported in Captivate 4 (trial), but apparently it is not.
    Can anyone of you guys help me here?
    Thanks a lot,
    Tina

    Hi there
    I'm guessing you mean to have the ability to click and drag the image? If so, I'm sorry but the answer is no. There is no ability to click and drag images in any version of Captivate to date.
    If I correctly interpreted that, please file a feature request to add your voice to others that have asked for it. (link is in my sig)
    You are able to insert images into Question slides. But they will simple be visible and not interactive in any way.
    Cheers... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • Questions regarding sequence settings, render, and export

    Just a couple of questions:
    1. Will my sequence settings and render quality affect my final output? I am thinking it does, and it may seem elementary to most of you, but it would be nice to get a definite answer. If so, then should I be rendering @ the best quality possible? In turn, should I too be switching my codec? Which correlates with my next question....
    2. What codec should I be using? As it is I've been just getting footage off of mini dv. For best possible quality what should my workflow look like? Should I change my sequence settings codec to uncompressed? Which one? Uncompressed-8bit or 10 or animation? Or is okay to leave that setting at DC NTSC PRO?
    Then, most importantly, when exporting what is my best possible output with the least amount of quality loss? For mediocore quality i've been exporting through h.264 or sorenson 3 - for a bit higher DV NTSC PRO, for max uncompressed 8 bit.... how about the other settings? deinterlace? cbr or vbr? etc..
    Much thanks - I'm a lot confused concerning the technical usage of the program. B)

    Hi David, thank you for the reply and welcome.
    Just to clarify my workflow a bit more - I'm importing mini dv footage, but i'm altering that pretty much extensively with many overlays, in program effects, and various exterior plugins such as boris red, magic bullet, twixtor, etc.. Would mantaining a sequence suited for dv ntsc make sense if mantaining those effect's and overlay's vibrancy, motion, and color is key? Or should I then change my sequence settings to animation or uncompressed 8 or something other?
    What I want for final output is a pristine master (basically I want what I see is what I get) that I can then downcompress for either internet (h264?) or dvd without too much headache. I think Animation only plays on computers? Would it hurt quality badly moving it to a dvd that is playable on dvd players? Or is another setting that I don't know the solution?
    Does it hurt quality if I render it at lower draft settings and dv ntsc and then when i'm done change my sequence settings to higher settings and change it to, say, animation, AND THEN re-render and export to my sequence codec? I'm assuming no, because I'm still working with my original capture source, but just checking.
    thanks again David, and to anyone that may be able to help! B)
    Message was edited by: eric sanpablo

  • A few general questions about sequences, framerates (fps), audio sources

    If I create a sequence in Pro that is 23.976fps, matching my audo from Canon T2i shot with 24fps... and an audio with 48hz... and then if I import an audio (music) with 44hz..
    does it affect my output settings?
    Another question. If i have 23.976fps sequence, and I output it for Vimeo (which they say should be 30fps) does it have ANY effect on video/audio synchronzation?

    PrPro can handle most common Audio Sample Rates, like 44.1KHz @ 16-bit, and will Conform those Assets to edit in a 48KHz 16-bit Project. Other than an extra moment of the Conforming process, should not be an issue. This ARTICLE will give you some background on Conforming and Indexing.
    Good luck,
    Hunt

  • Field Dominance Question for Sequence

    I shot my video in DVCPro50 format at 30p. I have edited my video in a DV50 sequence. I am ready to take to a production house to be transferred to BetaSP. In the past with other videos I take the finished sequence and nest it into a Uncompressed 8-bit NTSC sequence and that is what I give to production house. In this Uncompressed 8-bit sequence should I select Field Dominance: None or Field Dominance: Lower (even)?
    Thanks for your help!

    If someone could help me out to confirm this. I would rather do this right than find out when my commercial is broadcast that I messed up the field dominance.
    My final sequence is being transferred to BETASP. I take to the production house an uncompressed 8 bit NTSC sequence.
    If I understand this correctly my uncompressed sequence will have a field dominance of lower if the original footage was SD.
    If my original footage was HD than my uncompressed sequence should have the field dominance set to upper.
    So the uncompressed sequence that is transferred to BETASP has a field dominance set by the original footage?
    Thanks for taking the time with this.
    Darrin

  • Question on Sequences and how best to use them

    Hi all,
    I am used to Premiere Pro v6 and I have recently moved to CS4.1.
    Could you explain to me how best and why to use multiple sequences for a single project in Premiere Pro CS4.1?  I understand that you can have different formats on each, but I was wondering if there was a technique for using multiple sequences for a large project, eg a wedding where each scene could have a different sequence.  Am I on the right track.
    If so, then how does one preview edited footage that spans multiple sequences?
    Your help and advice would be appreciated.
    Cheers

    It all depends on your workflow, but personally when doing large projects, I prefer to work on smaller pieces first. Your example of a wedding could easily be broken down into sequences like intro, preparation, ceremony, reception, party and background material. Then make a master sequence where you combine all the sequences into this master sequence. It also makes it easy to place chapter markers at the beginning of each smaller sequence and it makes the overview of the project a lot easier. It also makes it easier to maintain a semblance of organization in the project bins.
    When I did a sailing movie last year (http://vimeo.com/1122531) I had different sequences for St. Maarten, Jost van Dijke, Virgin Gorda, The Baths, The Bitter End, Saba and again St. Maarten, plus the intro and the end sequence. When all of these parts were finished, it was simply a matter of putting all in a master sequence and go to Encore.

  • Question about sequence table

    hello
    when i set up the sequence table within the mapping work bench,i DON'T select write it to database,i wonder if i need to generate the class code for the sequence table,and put it in my project source files package with all of the other table class code?
    otherwise,as i have said,during my creating the sequence table,i don't select to write it to the database,but now,i want to write it to the database,how can i do?
    which one is the better solution?writing the sequence table to database?or not?
    thank you

    I would recommend writing the sequence table to the database from the Mapping Workbench. If you export a DDL file for all of the tables, the sequence table will be included in this definition as well.
    I might mention one more point however. After creating the sequence table, it will need to be initialized for each descriptor which uses a sequence. You can do this either by manually inserting rows of data or by using TopLink's SchemaManager:
         SchemaManager manager = new SchemaManager(session);
         manager.createSequences();          
    The SchemaManager (from package oracle.toplink.tools.schemaframework) must be initialized with a logged in TopLink DatabaseSession.
    JIM

  • Question about Sequence

    Hello,
    I'm not clear about sequence with table. since Sequence are use to genrate unique values for primary keys and any other coloumn.
    I want to know how sequence is tied up with coloumn of a table or in other words how table get know or sequence get know that this sequence is for this particular table or a table has this sequence.
    I'm not clear about this relation. Is it the responsibility of programmer to tied a sequnce with table or Oracle DB server done on itself.
    Looking for reply,
    Regards,
    D.Abbasi

    The Oracle database maintains no mapping of a sequence to a table. It is the responsibiltiy of the programmer to use the right sequence to populate the right table. Of course, assuming you have triggers or a procedural API that is interacting with each table, the programmer should only have to code this mapping once.
    Justin

  • Question about sequence size (anamorphic) and image distortion.

    If I create a sequence with sizes 1920x810 is there a way to bring footage into the sequence and not not have it get distorted? I would prefer just to crop the top and bottom off the image. In the end have the video file be original, but just the sequence size remain the same. Is this possible?

    Right-click the clip on the timeline and see if "Scale to Frame Size" is checked. If so, turn it off. This can be done globally in Edit > Prefs, but only affects clips upon import, does not affect those already in the project.
    This should provide the effect you want of cropping the top and bottom, but still curious how this will be output. If you want to go to Blu-ray or anything that is a "video standard", then you are better off to use the full HD frame size and add black bars to get the "look" you want
    Thanks
    Jeff

  • Question on sequencing

    Heres my problem. I have an xml which looks like this
    <myfile>
    <parent num=1.00>
    <child num=1.01>
    <child num=1.02>
    <child num=1.03>
    </parent>
    <parent num=1-a.00>
    <child num=1-a.01>
    <child num=1-a.02>
    <child num=1-a.03>
    </parent>
    <parent num=A>
    <child num=a>
    <child num=b>
    <child num=c>
    </parent>
    </myfile>
    You will notice that the numbering structure changes for every element. How
    can I find out
    1. What the sequence is for each element
    2. If there are any numbers missing in the each of the sequences
    Can my XML parser help me get this info. I dont know where to start

    see java.text.MessageFormat

  • Silly question: stop sequence from looping

    Hi there, I think I hit a key to make the sequence loop at the end and I don't know how to disable it, any help would be appreciated, thanks!

    At some point in editing, you pressed Control-L to activate Loop Playback.
    Press Control-L again to toggle that function off.

Maybe you are looking for

  • Ipod touch won't connect to itunes?

    I have tryed two different wires and none of them work. The computer makes the connecting noise then nothing shows up. Why is this?

  • Raid Setup 990FXA-GD65

    I have been running 2 drives as raid 1. I added a third drive that I want to use for storing files but not as a raid drive, just as a SATA drive.  Now when I boot I get a critical warning because it set itself as raid 1, LD2. How can I change it to j

  • List of Objects(UDO)

    Hello, I'm working in a project where I want to make a form for Route entry-- eg-- Mumbai to Goa, Kolkata to Digha etc. like Business Partner Entry form. Then I need to have a list of routes in another form where a field for Route entry is, like BP l

  • Trying to set up new I Pad 3- how to do it?

    How do I set up a new I pad 3-- new user here.

  • Catalog Activities

    Hello, I have created Code and code groups under the catalog. I have used B - Object parts, C - Overview of damage, 5 - Causes and A - Activities (PM) I have dfined 10 objects and for each object I have defined overview of damage, causes and acitivit