Auto sequencing

Hi,
I am new to Oracle but have experience with the procedural languages in MS SQL Server and Sysbase and in the past have used these languages extensively.
I often use a number for my PK and get the database to increment that for me. In MS SQL Server you denote this field as [Identity=Yes] and you can set the seed (ie where to start the sequence) as well. Now in oracle as far as I can see I have to do this, as follows:
DROP SEQUENCE INDEM_SIGS_SEQ;
CREATE SEQUENCE INDEM_SIGS_SEQ MINVALUE 1 MAXVALUE 999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE;
CREATE TABLE INDEMNITY_SIGNATORIES (
IS_NO NUMBER(6) NOT NULL ENABLE,
... more fields
CONSTRAINT PK_INDEMNITY_SIGNATORIES primary key (IS_NO),
CONSTRAINT ... more constraints
CREATE OR REPLACE TRIGGER BI_INDEM_SIGS
before insert on INDEMNITY_SIGNATORIES
for each row
begin
select INDEM_SIGS_SEQ.nextval into :NEW.IS_NO from dual;
end;
ALTER TRIGGER BI_INDEM_SIGS ENABLE;
Now this seems a long-winded way of doing something that in SQL Server I just need to change a property value to do. But fair enough I only have to do it once for each table that has a sequential prime key, but if anyone is looking at this and can think of an easier way then please let me know.
The next thing is that you sometimes get the situation when you insert a record and that you need the vaue of the prime key of the record you have just inserted. So you can then insert or update records in another tables that have this number possibly as a FK in other tables.
In SQL Server I would do this as follows:
INSERT INTO contacts (contact_type, first_name, surname, secretary, salutation, title, email, tel, mobile, fax, xmas_card, notes, created, modified)
VALUES (@contact_type, @first_name, @surname, @secretary, @salutation, @title, @email, @tel, @mobile, @fax, @xmas_card, @notes, GetDate(), GetDate());
SELECT contact_no FROM contacts WHERE (contact_no = @@IDENTITY);
I hope this is clear and that someone can help.

If you want the primary key column to be populated automatically, the trigger you've posted is correct. Lots of folks prefer just to put the sequence in the actual insert statement, i.e.
INSERT INTO indemnity_signatories( is_no, other_columns )
  VALUES( indem_sigs_seq.nextval, other_values );You can get that sequence value back either using the RETURNING clause or using the CURRVAL of the sequence, i.e.
INSERT INTO indemnity_signatories( other_columns )
  VALUES( other_values )
  RETURNING is_no INTO my_local_is_no_variable;or
SELECT indem_sigs_seq.currval
  INTO my_local_is_no_variable
  FROM dual;Justin

Similar Messages

  • Auto sequence ???

    hello all,
    from the browse form in uix , i am calling a new empty input form, how can i generate the auto-sequence number and assign it to the empid in the new form?? and the user can see but cannot edit it , its an oracle sequence using nexval or else.
    {urgent}
    zaibi.

    One way you could do it is to allow your database to assign the value to empid. If you were using an Oracle database you would use a "Before Insert Trigger" in combination with a "DB Sequence". Then in the Jdeveloper "Entity Object Editor" you would assign the type of your attribute "empid" to DBSequence. Also note the Tabs near the bottom of the editor. There is one for "Database Column" and one for "Sequence". These both need to be filled out as well and should be once you assign the type to DB Sequence. If their not, then for the Database Column the "name" and "type" are the actual name and type that you created in your database. The Sequence tab needs the name of the Sequence that you created in your database and usually starts at 1.
    One reason that you let the database assign the value to your id's and not the application is that you may have more than one application using that data, and in other cases the application technology may be different.
    BG...

  • Auto Sequencing in column list

    Hi,
    I want to create a column with sequence.
    My Scenario is
    -India                            1
              01/02/1992         1.1
              02/04/2000          1.2
    -America                      2
                05/08/2011      2.1
                 02/02/2001      2.2

    Hi,
    You have to write event receiver to achieve this auto increment.
    The following is the example code to increment the value by 1.  You can tweak the code the meet your requirements like condition based on country etc.
    public override void ItemAdded(SPItemEventProperties properties)
    SPWeb web = properties.OpenWeb();
    bool allowUpdates = web.AllowUnsafeUpdates; //store original value
    this.EventFiringEnabled = false;
    try
    web.AllowUnsafeUpdates = true;
    /*get the current list*/
    SPList list = web.Lists[properties.ListId];
    var highestvalue = 0;
    var objQuery = new SPQuery
    Query ="<OrderBy><FieldRef Name='" + ColumnName
    +"' Ascending='False' /></OrderBy><RowLimit>1</RowLimit>",
    Folder = list.RootFolder
    SPListItemCollection colItems = list.GetItems(objQuery);
    if (colItems.Count > 0)
    highestvalue = int.Parse(colItems[0][ColumnName].ToString());
    var currItem = properties.ListItem;
    currItem[ColumnName] = highestvalue + 1;
    currItem.SystemUpdate(false);
    catch (Exception ex)
    Trace.WriteLine(ex.Message);
    finally
    this.EventFiringEnabled = true;
    web.AllowUnsafeUpdates = allowUpdates; //restore original value
    And also refer to the following article, if you are not going to use the event receiver.
    Add a Unique Auto-Incrementing Column to a SharePoint List
    Please mark it answered, if your problem resolved.

  • Suppress auto sequence and trigger DDL for surrogate keys?

    Is there a way to suppress trigger and sequence creation for surrogate keys when export to DDL file?
    I know most of the time the automatic sequence and trigger creation is welcome and very handy.
    However I'm migrating from an old Designer model and there only the needed sequences are created.
    They have a different name and trigger logic is custom (and  generated outside designer).
    There is a lot of package code depending on this. So I prefer to create and use different sequences.
    Is there a way to achieve this? Any tips are welcome.Create

    Hi,
    Note that generating the DDL for Oracle 12c means that it will attempt to use your Oracle 12c Physical model.  So if you normally use Oracle 10g or 11g, you will find that any details from your Oracle 10g or 11g Physical Model will not be included.  So this approach may have other implications for you.
    If you are not using Oracle 12c, there are some relevant properties on the Auto Increment tab of the Relational Model properties dialog for the Column which may help:
    Sequence Name - allows you to specify the name of the Sequence (which can be the name of a Sequence defined in the relevant Physical Model).
    Trigger Name - allows you to specify the name of a Trigger (which can be the name of a Trigger that is defined for the Table in the Physical Model).
    Generate Trigger - unsetting this will stop the Trigger being generated.
    David

  • Auto sequence settings

    how can I navigate to a file on disc and choose it to then make FCP sequence settings based on file properties automatically.

    this worked
    http://www.proapptips.com/proapptipsvideotutorials/194F4DC2-ACBB-4DD6-A1D0-F46D7 D8DCAFC/53B46BA3-E23E-4ACD-888F-1E931224596B.html
    but i still want keep the screencap full size and pan/scan in normal 1080 timeline

  • How can we generate auto Sequence Number in DFF attribute

    Dear
    We are on r12,rignt now we have an issue to generate sequence number in site Level(DFF) on Supplier window,actully we want
    to generate sequence number on site leve while inserting new record on site level,so how could i achvie this or any way which can help us.
    --thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    You can consider writing a before-insert trigger.
    The trigger generates the next value of the sequence and makes :new.attributen = the sequence value.
    Hope this helps,
    Sandeep Gandhi

  • Problem inserting auto-sequence for PK value using trigger - ORA-02287

    I have a query where the sub-query is working. I created a table to receive the results of the query. I created a Sequence:
    CREATE SEQUENCE SEQ_RPT_H2_LOOPS
    MINVALUE 1
    START WITH 1
    INCREMENT BY 1
    NOMAXVALUE;
    Then I created a trigger:
    CREATE OR REPLACE TRIGGER TRG_RPT_H2_LOOPS
    BEFORE INSERT ON RPT_H2_LOOPS
    FOR EACH ROW
    BEGIN
    SELECT SEQ_RPT_H2_LOOPS.NEXTVAL INTO :NEW.RECORD_ID FROM DUAL;
    END;
    And here is the Insert query.
    accept month_year;
    accept prior_month_year;
    insert into rpt_h2_loops (
         RECORD_ID,
         MKT_CODE,
         MKT_NAME,
         ECCKT,
         VENDOR_ID,
         ECCKT_VENDOR_ID,
         OCN,
         FAC_TYP,
         ALOC,
         ZLOC,
         STATE,
         OCN_STATE,
         OCN_STATE_COLO,
         SRVC_TYP,
         CUR_PERIOD,
         PRIOR_PERIOD,
         TIME_STAMP )
    select seq_rpt_h2_loops.nextval
    ,substr(r.sub_acct,4,3)
    ,m.market
    ,rr.ckt
    ,rr.vendor_id
    ,rr.ckt||rr.vendor_id
    ,rr.ocn
    ,rr.srvc_typ
    ,'N/A'
    ,rr.zloc
    ,rr.st_cd
    ,rr.ocn||rr.st_cd
    ,rr.ocn||rr.st_cd||rr.zloc
    ,rr.srvc_typ
    ,'&month_year'
    ,'&prior_month_year'
    ,sysdate
    from rco.rate_route rr
    ,rco.cogs_resource r
    ,rco.cogs_mkt m
    where rr.cvbi_key = r.cvbi_key
    and     m.subacct = r.sub_acct
    and     to_char(rr.period, 'mm/yyyy') = '&month_year'
    and     to_char(r.period, 'mm/yyyy') = '&month_year'
    and     rr.srvc_typ = 'CUNE'
    group by    substr(r.sub_acct,4,3)
    ,m.market
    ,rr.ckt
    ,rr.vendor_id
    ,rr.ckt||rr.vendor_id
    ,rr.ocn
    ,rr.srvc_typ
    ,rr.zloc
    ,rr.st_cd
    ,rr.ocn||rr.st_cd
    ,rr.ocn||rr.st_cd||rr.zloc
    );The problem is that I am getting a ORA-02287: sequence number not allowed here on the NEXTVAL keyword.
    The sequence and trigger compiled without problem. I just can't seem to insert that value into the query. Any help would be appreciated.

    you are defeating the purpose of trigger which is before insert so just rewrite the query and remove the column for which value will be inserted using the created sequence and your code will work.
    Regards,
    Vikas Kumar

  • Auto Sequence create on Supplier Site  DFF

    Dear,
    We are on r12, Requirment is that we have DFF on supplier site level, now i want to generate auto squence on Segment1,
    which should be generated on every site creation through Fron-END,
    So how can i acheive This.
    Thanks

    I assume you meant attribute1 (not segment1).
    Have you considered a before-insert database trigger?
    Hope this helps,
    Sandeep Gandhi

  • Auto Sequence Generator

    I create a table with a key and anytime I create a new row I
    would like the the key to be updated by one. I want a sequence
    generator to kick off without me doing a nextval. Does anyone
    have a specific example.

    As an example, we consistently uses sequences and triggers of
    the following type. And then we never bother about creating the
    primary key in inserts.
    CREATE SEQUENCE Q_BILL_OF_MATERIALS
    INCREMENT BY 1
    NOMAXVALUE
    NOMINVALUE
    NOCYCLE
    NOCACHE
    CREATE OR REPLACE TRIGGER BOM_INSERT_ID
    BEFORE INSERT
    ON BILL_OF_MATERIALS
    FOR EACH ROW
    WHEN (new.id IS NULL)
    BEGIN
    SELECT     q_bill_of_materials.nextval
    INTO     :new.id
    FROM     dual;
    END;

  • Subform auto-sequencing with alpha chars

    Hi, can anyone help with my problem?  I need to generate autosequence in a repeated subform with alpha chars ('a)', 'b)', etc.) instead of numeric.  Thanks in advance!

    Hi,
    this is not that difficult.
    Assuming you have a repeatable subform names "SF" which contains a text field named "SFindex" then you can use the following script in the indexChange event of "SF".
    var aChars = "abcdefghijklmnopqrstuvwxyz".split("");
    SFindex.rawValue = this.index < aChars.length ? aChars[this.index] : "n/a";

  • How to create a sequence based on name, country, city, year, month, number

    Hello,
    I am using Application Express 4.2.1.00.08
    I am new to apex and i need some help in creating a sequence.
    I am creating an application where i profile people and i need to create an auto sequence that when the person is added to the database he will have his own sequence based on his name, country, city, year he was added, month he was added and his number.
    This is a bit tricky because each person will have a different name, country city etc.
    How can this be done ?

    Hello,
    I have to create a sequence so that when for example an employee is added using a form his ID will be saved based on his name, country, city, year he was created, month he was created and his number.
    However, each employee is diff, so when you add another employee to the form his ID will be different, different name, country, city etc..
    This has to be automatically generated.. is this possible?

  • Automatice sequence creater for image sequence

    Hi Friends,
    I got doubt where there is an option for creating an auto sequence, what i mean by is in avid when we load the source in the source monitor or viewer in FCP and when we want to overwrite it in the composer window or record monitor in avid it creates an automatice untitled sequence with the content since i no need to specify the format and blah blah blah.
    I have an image sequence and i dont no the format and frame size etc and i imported the sequence thru qt ref andi want it in an sequence without redering shown in my timeline.
    I hope u understand what i want to tell.
    thanx
    g.balaji

    With image sequences, probably the biggest thing to address is the pixel x pixel sizes of the stills. For maximum performance (and quality in my book), I like to have those Scaled to match the Frame Size of the Project Sequence. The PNG format should be just fine, but size DOES matter. What are the pixel x pixel dimensions of your stills?
    I do a lot of work with stills, but not usually in image sequences. For my work, I usually just leave the stills as PSD's, and never have any issues. These are Scaled to the Project, or only slightly larger (when I need to Pan on a Zoomed out image), and my Scaling is always done in Photoshop, prior to Import.
    Good luck,
    Hunt

  • Manual vs Auto Transitions

    If I want to automate the application of default transitions between numerous clips into a sequence, I can highlight the clips and drag them to the Automate To Sequence icon, make my transition selections (overlay edit) and it is done.  This process will apply the transitions on original unedited clips without handles and without repeating frames.  Thus the auto sequence process must create the handles (that were not a part of the original clip) and apply the transitions without repeating frames.   However, if I were to manually insert the same unedited original clips without handles into a sequence, select all the clips, then choose Sequence > Apply Transitions to Selection...   the process will NOT create the handles necessary to apply the transitions without repeating frames.  Default transitions will be applied but WITH repeated frames.....
    Is there some method to set up the In and Out handles ahead of time for unedited clips that would automate the manually method of applying transitions?  I am assuming repeating frames are bad and it is quite tedious and time consuming to manually create handles at the end and beginning of numerous frames prior to manually applying a transition...   I am using PP CS5.5 and working with AVCHD m2ts files.   Thanks
    Greg

    Hi Greg, I think I have read this correctly. You cannot expect transitions to to be able to make up frames that are not there, so instead they use duplicates of Early or late frames from that clip and preceeding clip to fill the transition timescale.
    If your clips have unused frames before and after the in and out points then the transition effect will use those clips as opposed to repeating clips. Try a little experiment by starting a new project and add one clip with NO handles from the source monitor (ie no in point or out point Use the entire file) Then set some in and out points and see the difference. Just a little bit of experimenting in another project works wonders and keeps it simple.
    I hope I have not mislead you, (but will soon be put into place no doubt if I have) but starting to get a bit bleary eyed now with my own problem in hand.
    Regards
    Dave.

  • Auto-syncing audio using tod TC

    hey there,
    i was just editing a presspackage for a documentary, 25min out of more than 15h of rushes.
    it was shot on a sony ex3 1080i 50 and the audio seperatly, both with the same tod timcode.
    now my client wants me to sync the 25min sequence to the seperate audio files, but
    i wouldn't have a clue where to start. i tried a little program called 'sequenceliner' but the new
    version running on 10.6 seems to work only with ntsc footage and we are on pal, apparently
    the older version did work (using xml), but i have no way of trying as i run on 10.6.
    someone else was recommending pluraleyes, but i could not make that work either...
    so what can i do? manually syncing would be... well let's just say a lot of work!
    thanks for your help
    andy

    well thanks, but i know how to match TCs and add video and audio together, in germany we call
    it 'anlegen'don't know what the english term is...
    anyway, i was told that there is an AUTOMATIC way of doing that!! as there are thousands of little
    clips your method of manually doing it is not an option, unfortunately. in avid there is something
    called 'auto sequence' that doesn't really do the job, but it matches the videoclips with their according
    audiofiles. not what i need, but at least a start....
    it's not a no-budget project, but a 'we have budget for one day of edit and were told everything will work,
    but now it doesn't and you have to help us sort out the mess' kind of project.
    i kind of attract this kind of jobs a lot...

  • Can't advance photos in slideshow

    I have a slideshow of 325 photos to illustrate a lecture; some are timed series and others manually advanced. In several slideshows I have experienced the problem of being unable to advance the slides manually after about two-thirds of the show. When I try to advance, the photo goes back to a previous image (sometimes repeatedly), then eventually after several presses, moves to the next image. This problem starts at the same point every time I play the slideshow and continues for 15 or 20 images, until I conclude the show with an auto-timed series.
    I've unchecked the custom time box for selected images (so the default is shown), and I've been careful to pause the preceding auto sequence at its end.

    Hello Bela Feher,
    It may be that Aperture's database needs repairing or rebuilding, as database inconsistencies can cause images to appear incorrectly. I do strongly recommend verifying a backup of your data prior to proceeding.
    Aperture 3.x: An Overview of the Backup Workflow
    http://support.apple.com/kb/PH7812
    Aperture 3.x: Repairing and Rebuilding Your Aperture Library
    http://support.apple.com/kb/PH7821
    Cheers,
    Allen

Maybe you are looking for