Reset a sequence

Hi,
This is the requirement. WE have a code which creates an outbound file containing the posted journal entries. These are named in a way that there is a sequence at the end of the name.
We need to reset the sequence used in that code every month so that it starts from one at the beg. of the month.
Any help is appreciated.
Thanks,
Ash

possible solutions:
1. create a procedure that drop and create the sequence dynamically
       create or replace procedure prc_recreate_sequence(pSeqName varchar2, pStartNum Number, pIncrementNum Number) as
       begin
          execute immediate 'Drop Sequence '||pSeqName;
          execute immediate 'Create Sequence '||pSeqName||' Start With '||pStartNum||' Increment By '||pIncrementNum;
       end;
       /2. create a table that logs the current value as a sequence bypassing the use of the actual sequence
       create table sequence_log
         (sequence_name  varchar2(40),
          start_with     number,
          increment_by   number,
          current_val    number);
       insert into sequence_log
       values ('trans_dtl_seq',1,1,1);in your code call this table to utilize it
       declare
         vSeqNum     number := 0;
       begin
         select (current_val)+1
           into vSeqNum
           from sequence_log
          where sequence_name = 'trans_dtl_seq';
         update sequence_log
            set current_val = vSeqNum
          where sequence_name = 'trans_dtl_seq';
        end;

Similar Messages

  • Resetting the Sequence operator in OWB

    I have a Sequence operator for one column in the mapping. It correctly increments by 1 for each row (nextval) . I have done some testing and now I want to reset the next increments. Like I want to start from 1 instead of some 588 like that which is result of my testing.
    How to reset the sequence operator so that it starts from 1 again.
    Thanks

    Hi Tom,
    First you should create a store procedure that resets the last_number of a specified sequence w/ parameters sequence_name and start value. Then just call the stored proc from OWB to reset your sequence.
    --stored proc ex:
    create or replace PROCEDURE reset_sequence (
    seq_name IN VARCHAR2, startvalue IN PLS_INTEGER) AS
    cval INTEGER;
    inc_by VARCHAR2(25);
    BEGIN
    EXECUTE IMMEDIATE 'ALTER SEQUENCE ' ||seq_name||' MINVALUE 0';
    EXECUTE IMMEDIATE 'SELECT ' ||seq_name ||'.NEXTVAL FROM dual'
    INTO cval;
    cval := cval - startvalue + 1;
    IF cval < 0 THEN
    inc_by := ' INCREMENT BY ';
    cval:= ABS(cval);
    ELSE
    inc_by := ' INCREMENT BY -';
    END IF;
    EXECUTE IMMEDIATE 'ALTER SEQUENCE ' || seq_name || inc_by ||
    cval;
    EXECUTE IMMEDIATE 'SELECT ' ||seq_name ||'.NEXTVAL FROM dual'
    INTO cval;
    EXECUTE IMMEDIATE 'ALTER SEQUENCE ' || seq_name ||
    ' INCREMENT BY 1';
    END reset_sequence;
    --calling stored proc ex:
    --sequence name is employees_seq; reset value to 1
    DECLARE
    SEQ_NAME VARCHAR2(200);
    STARTVALUE PLS_INTEGER;
    BEGIN
    SEQ_NAME := 'EMPLOYEES_SEQ';
    STARTVALUE := 1;
    RESET_SEQUENCE(
    SEQ_NAME => SEQ_NAME,
    STARTVALUE => STARTVALUE
    END;
    Hope it works! Cheers!=)
    Regards,
    Carlo

  • Reset the sequence

    Hi,
    I have a set of statements in the procedure as below :
    This is a daily job. we are planning to reset the Sequence on daily basis.
    Is there any other way instead of resetting the sequence?  We are resetting because todays number may come tomorw also.
    select SEQ_NAME.nextval into No_Col from dual;
    insert into table
        (No,NoDAYWISE,Method)
        values ( No_Col, to_char(sysdate, 'DD') || to_char(sysdate, 'MM') ||
               to_char(sysdate, 'YY') || No_Col, 10)
    This is the table structure
    No
    NoDAYWISE
    Method
    181
    300813181
    421
    161
    160813161
    421
    201
    160913201
    421
    Thanks in advance.

    I agree with Paul's comment. Sequences are meant to generate unique numbers.
    If you are bend to implement this, below script might help you:
    drop sequence test_seq;
    create sequence test_seq start with 1 nocycle nocache;
    select test_seq.nextval from dual;
    select test_seq.nextval from dual;
    select test_seq.nextval from dual;
    select test_seq.nextval from dual;
    select test_seq.nextval from dual;
    set serveroutput on;
    declare
      v_num number;
    begin
      select 1 - test_seq.nextval into v_num from dual;
      dbms_output.put_line('Before reset Seq val :: ' || v_num);
      execute immediate 'alter sequence test_seq increment by ' || v_num;
      select test_seq.nextval into v_num from dual;
      dbms_output.put_line('After reset Seq val ::' || v_num);
      execute immediate 'alter sequence test_seq increment by 1';
    end;
    An easier way to achieve is, drop the sequence and create it again; this and even the above, I do not recommend.

  • Timecode panel resets when sequence switching

    Hello guys and girls.
    I am finding the timecode panel near useless at the moment cause whenever i switch sequences (i usually have more than 4 open at a time) it resets to "sequence timecode", and who needs that when there are already 2 other references to draw from. I wish it would stay on the selected setting whatever that may be.
    Does anyone know how to change the timecode panel settings so it stops resetting after a sequence switch?
    I've already sent a report to adobe, wasn't till after i thought to ask the community.
    All goods though, if i get the answer is here, they'll probably just ignore my report, (though i also asked for optional multible lines of timecode).
    Thank you all
    Regards
    Te Rurehe

    Yes thats the same for me too.
    But did you know, in the timecode panel from the dropdown setting on the top right of the panel, you can set the timecode panel to reference the clips timecodes on a specific video track from your sequence? I think that is awsome, especialy for my workflow! Though the darn thing keeps resetting to the plane old sequence timecode (when switching sequences) which is useless cause its already there in the sequence panel and the program out panel.
    I'm looking to somehow set the timecode panel to a specific setting and not change when i switch sequences. Or even better remember the setting it was on for specific sequences.
    That is what i'm talking about, i'm sorry if my first message was a bit confusing, i hope this one is clearer.

  • 785GTM-E45 MOBO BIOS V 8.80 RANDOMLY RESETS BOOT SEQUENCE

    785GTM-E45 MOBO W/ PHENOM 9750 QUAD CORE CPU/4 GB WINTEC DDR2 PC6400 (2 x 2 GB) / WINDOWS XP SP3
    PROBLEM:  BIOS V 8.80 RANDOMLY RESETS BOOT SEQUENCE
    I HAVE 4 HARD DRIVES (2 SATA II - 1 USB 2.0 1 USB 3.0) ALL OF WHICH HAVE MULTIPLE PARTITIONS WITH 1 ACTIVE ON EACH DRIVE
    SATA II DRIVES / DEVICES:
    ON SATA 1: HITACHI 1TB SATA II DRIVE
    ON SATA 2: MSI DVD-CW RW
    ON SATA 3: MAXTOR 320GB SATA II DRIVE
    USB DRIVES:
    1. SEAGATE FREE AGENT EXTERNAL USB 2.0 1TB HD
    2. FANTOM EXTERNAL USB 3.0 2TB HD (VIA DIABLOTEK USB 3.0 PCI-E CARD)
    EXPLANATION OF PROBLEM AND FIXES ATTEMPTED TO DATE
    IN BIOS BOOT SEQUENCE I SELECT THE HITACHI HD AS 1ST DEVICE AND ALSO SET IT 2ND 3RD AND 4TH AND BOOT OTHER DEVICE DISABLED.  SAVE/EXIT BIOS AND WHEN SYSTEM REBOOTS IT RANDOMLY SELECTS ANY OF THE 4 DRIVES TO BOOT FROM. WHEN I ENTER BIOS AGAIN IT SHOWS WHATEVER DRIVE IT HAD SELECTED TO BOOT FROM AS 1ST, 2ND, 3RD AND 4TH DEVICE. ENABLING OR DISABLING BOOT FROM OTHER DEVICE MAKES NO DIFFERENCE.
    ORIGINALLY MY HITACHI WAS ON SATA 3 AND THE MAXTOR ON SATA 1 - I SWITCHED THESE AND NO DIFFERENCE.  BIOS SWITCHES BOOT DEVICE NOT ONLY TO THE MAXTOR SATA DRIVE BUT ALSO TO THE USB DRIVES. USUALLY WHEN I REENTER BIOS AND CHANGE THE BOOT SEQUENCE BACK FROM WHATEVER HD IT SHOWS TO THE HITACHI IT WILL USUALLY THEN BOOT FROM THE HITACHI SOMETIMES THOUGH IT TAKES 2 OR 3 TRIES TO GET IT TO BOOT FROM THE DRIVE I HAVE SELECTED AS 1ST BOOT DEVICE.
    I HAVE TESTED ALL DRIVES EXTENSIVELY USING ONTRACK EASY RECOVERY PROFESSIONAL SOFTWARE AND ALL DRIVES SHOW NO PROBLEM.
    MSI LIVE UPDATE 5 REPORTS THAT THE BIOS IS 8.80  HOWEVER IT ALSO SHOWS MY OS AS WINDOWS 2000 WHICH IS INCORRECT.  MY CURRENT OS IS WINDOWS XP SP3. MY XP INSTALLATION WAS AN UPGRADE FROM WINDOWS 2000.
    PROBLEM IS NOT DEVASTATING JUST ANNOYING IF ANYONE KNOWS OF A FIX I'D LOVE TO HEAR ABOUT IT.  IF THIS IS A BUG IN THIS VERSION OF THE MOBO BIOS I SURE HOPE THEY EXTERMINATE IT AND RELEASE AN UPDATED VERSION IN THE NEAR FUTURE.

    Quote from: Bas on 26-August-11, 18:07:03
    How do you know it's randomly booting a different drive?
    What are the messages you get?
    As this:
    That looks like a broken drive to me, where it can't find the bootsector/mbr in time to boot from, so the BIOS moves to the next drive and tries again.
    I built this box about 2 months ago or so and this is the version of BIOS that came with the MOBO.  I have not flashed the bios in this board.
    As for knowing that it is randomly booting from a different drive as I stated each of my 4 drives has at a minimum 1 active partition.  The Hitachi has a dual boot setup in Windows and if it is booting from the Hitachi drive I will get the Window giving me a choice of booting from either the Hitachi or the Seagate.  If I select the Hitachi I also have it setup for two hardware profiles so it then gives me that screen to select profile 1 or 2.  If I get these screens no problem - I select the Hitachi and profile 1 and it boots without any further problem.
    If it has switched lets say to the maxtor (remember I have selected the Hitachi as 1st, 2nd, 3rd and 4th for boot sequence and the boot from other device is NO) I get no multi boot option it just automatically starts Windows from the active partition on the MAXTOR  (I can tell because the last time I used the Maxtor didn't shut down Windows properly so I get the option screen to boot normally or use safe mode etc).  The active partition on the Maxtor is a duplicate of the Hitachi but about 2 months old - basically a backup of the Hitachi active partition but out of date and without the multi boot option.
    In addition if it has switched boot drives and I hit my reset button and del to open up bios again and go to the boot sequence menu it will no longer show my hitachi as all 4 choices but sometimes it will show all 4 drives in varying order (including the hitachi but not as first device), sometimes 1 drive in all 4  (as in the seagate or the maxtor or the fantom drive in all 4 of the boot sequences) this seems to occur randomly and each time the list of boot sequence is different. 
    Keeping in mind that I had initially selected the Hitachi drive in all 4 of the boot sequences and selected NO to boot from other device - If the Hitachi drive was not ready or had a bad bootsector/mbr should I not get a message similar to "cannot boot from selected device so and so is missing etc??  I was under the impression that when one disabled the boot from other device as in NO then the bios should not attempt to go any further then attempting to boot from the selected device(s)????
    As for the broken drive and bios moving to the next drive and trying again I could understand that 1.  If I had not supposedly disabled its ability to do that  2.  I could perhaps understand this going to the next drive if I had selected the Seagate USB drive as my initial drive because of it's so called sleep mode which I have now turned off as it was causing errors in windows.  In addition I have run numerous and rigorous tests on the drives and they all passed with flying colors.
    Yesterday after a couple of tries I booted from the Hitachi drive (it was listed as 1,2,3,and 4 in bios and the boot from other device was NO) and was using that all day and was on it when I posted my help request here.  Shortly thereafter I properly shut down my computer.  Now I would think that when I turned it on again this morning the BIOS would have maintained its previous settings of the Hitachi in all 4 of the boot sequences and the No on enabling it to boot from other device?  However when I booted up again this morning it tried to boot from the Maxtor (I can tell because I get the option screen to boot normally or use safe mode etc) so I hit the reset button and then entered bios and boot sequence and now it showed the Seagate as 1 (it had just tried to boot from the Maxtor when I hit the reset button), the Fantom as 2, the Maxtor as 3 and the Hitachi as 4 and boot from other device still said NO - changed them once again to show the Hitachi in all 4 positions and exited bios and it did then boot from the Hitachi and here I am writing this message using Windows XP located in the active partition of my Hitachi drive.
    I'm not exactly a novice as my computer experience goes all the way back to mainframe days of the IBM 360 series computers.  I have built so many boxes I have lost count including numerous one using MSI mobos and I have never encountered a problem similar to this.  As I said it is not devastating just annoying - the only thing I can think of to totally eliminate the possibility of it being the mbr/bootsector of the Hitachi drive is to back up the drive and rewrite those sectors even though no errors have been reported.
    I could be wrong but after messing with this for sometime it really seems to be a bios bug or perhaps just my bios is defective - I was able to dl a copy of v8.8 from another post in the forums - and have not used it yet.  Sent all of this info in a Tech support request and posted it here to see if there were any solutions I may have overlooked before flashing the bios with a dl copy of the same version I have installed. 
    As for downloading the current v of bios from the forums here it was apparently the only way I could get a copy as Liveupdate 5  shows that I have the current version installed and only gives me a message that my mobo bios is current and no download is needed or something like that and the MSI site no longer gives one the ability to download the mobo bios without using liveupdate 5 or at least I couldn't find one.  Guess they got tired of people killing their boards with bad flashes. 
     

  • Reset a Sequence at Midnight on New Years Eve

    Hi,
    How can I reset a sequence generator at midnight on New Year’s Eve?
    Using SQL script and SQL-Plus, I know how to set the sequence increment to a negative number large enough to return the “Next Val” to 1 (then re-set increment to 1).
    But, ‘need help to understand how to cause this action to happen automatically. I’m thinking along the lines of a trigger or stored procedure.
    Thank you

    I have some thing to add to John's idea.
    You could use a negative INCREMENT BY. Typically most sequences are created without reference to minvalue. Oracle sets a value for the minvalue. If the original sequence was not created with 'nominvalue' then, the error like the following will show up.
    ORA-08004: sequence sequencename.NEXTVAL goes below MINVALUE and cannot be instantiated
    Hence you are better off doing the following in order.
    1. Alter the sequence and set the appropriate negative INCREMENT BY and also specify 'nominvalue'.
    2. Use a select statement to get the next value.
    3. Alter the sequence a second time to set INCREMENT BY to the original value.
    Some one could put this in a script and run it only once.

  • How to reset all sequence to 0 or 1 at time?

    Friends,
    OS: RHEL AS 3
    DB: 9iR2
    I have some 187 sequences. i want to reset all the sequences to "0" or "1" at a time.
    how can i do that?
    i its a single sequence, then i will do the below...
    for example if i have the x.nextval is 4
    alter sequence x increment by -4;
    alter sequence x increment by 1;
    the above is only for x but i have x,y,z,.......upto 187 sequences...
    how can i do that?
    any triggers or procedures? or any quick method.
    thanks

    A similar situation: there are tables having a group_column with group_column_values having each it's own sequence to feed a sequence_column
    Adding data requires the sequences to be reset to new maximum values (it's our development environment not production)
    procedure reset_sequences(p_table_name in varchar2) is
    /* sequence names are like: table_name || '_' || to_char(group_column_value)
      name_for_sequence varchar2(30) := upper(substr(p_table_name,instr(p_table_name,'.') + 1)) || '_';
      sql_for_sequence_max varchar2(250) := 'select group_column,max(sequence_column) the_max from ' || p_table || ' group by group_column';
      the_result sys_refcursor;
      local_group number;
      local_max number;
    begin
      for the_row in (select sequence_name
                        from user_sequences
                       where sequence_name like name_for_sequence || '%')
        loop
          execute immediate 'drop sequence ' || the_row.sequence_name;
        end loop;
      open the_result for sql_for_sequence_max;
      loop
        fetch the_result into local_group,local_max;
        exit when the_result%notfound;
        execute immediate 'create sequence ' || name_for_sequence || to_char(local_group) ||
                          ' start with ' || to_char(local_max + 1) || ' nocache';
      end loop;
      close the_result;
    end reset_sequences;Regards
    Etbin

  • Reset Field Sequence Value based on Insert OR update on that field

    Hi Experts,
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> WITH TAB AS
      2  (
      3      SELECT 1 ID,2 SEQ FROM DUAL UNION ALL
      4      SELECT 2 ID,1 SEQ FROM DUAL UNION ALL
      5      SELECT 3 ID,4 SEQ FROM DUAL UNION ALL
      6      SELECT 4 ID,3 SEQ FROM DUAL
      7  )SELECT * FROM TAB ORDER BY SEQ
      8  ;
            ID        SEQ
             2          1
             1          2
             4          3
             3          4
    SQL>If i insert or update any of the existing field (SEQ) value, the other values in the field (SEQ) has to
    be resetted, like
    INSERT INTO TAB VALUES(5,1);
    Expected Result:
            ID        SEQ
          5         1     
             2          2
             1          3
             4          4
             3          5
    SQL>
    How can i achieve this?
    Thanks,

    looks like you might be looking for a custom sequence manager.
    you might want to consider using a trigger to do this.
    unfortunately if you use just one trigger you will probably get a mutating exception.
    so you may need to do a multiple trigger approach
    make a place to hold the rows you want to look at
    i called mine tad_mgr
    CREATE OR REPLACE PACKAGE TAD_MGR IS
    *  This package spec holds the row ids of the tad table to be  used in the 3 trigger approach
    type ridArray is table of tab.ID%type index by binary_integer;
    newRows ridArray;
    empty ridArray;
    END;
    /your 1st trigger clears out any left over rows you have.
    CREATE OR REPLACE TRIGGER TAB_1ST
        before INSERT  of ID ON TAB
    declare
    *  This is the 1st trigger in 3 trigger approach to manage seq cds on the tad table
    begin
                    TAD_MGR.newRows :=  TAD_MGR.empty;
    end;
    /your second triggers puts your new or updated row into the container
    CREATE OR REPLACE TRIGGER TAB_2ND
    BEFORE INSERT
    OF ID ON TAB  REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    declare
    This is the 2nd trigger in 3 trigger approach to manage seq cds on the tad table
    begin
                 TAD_MGR.newRows( TAD_MGR.newRows.count+1 ) := :new.id;
    end;
    /finally your last trigger does the updates.
    CREATE OR REPLACE TRIGGER TAB_3RD
    AFTER INSERT OF ID ON TAB
    declare
    This is the 3RD trigger in 3 trigger approach to manage seq cds on the tad table
    aSEQ  tab.seq%type;
    aId   tab.id%type;
    begin
      for i in 1 ..TAD_mgr.newRows.count loop
        select ID, SEQ into aId, aSeq from tab where id = taD_mgr.newRows(i);
        for c in (select  id, seq  FROM tab where seq >= aSeq and id != aid ) loop
            update tab
            set seq = c.seq + 1
            where id = c.id;
        end loop;
    end loop;
               taD_mgr.newRows := taD_mgr.empty;
       end;
    /I just did this for the insert just as an example but you can change the triggers to insert or update and change the logic accordingly
    Edited by: pollywog on Apr 12, 2010 7:14 AM

  • Resetting column sequence in SQL

    Hi All, I have a simple requirement but I cant think of the solution...
    to simplify the problem, I have a master field and its child field, I need another column to bring back a sequence starting from 1...n and resetting itself back to 1 when a new master records starts eg...
    Master_id child_id seq
    200 100 1
    200 105 2
    200 120 3
    205 151 1
    205 159 2
    300 170 1
    ect
    If a solution can be done using purely SQL, that would be ideal
    also please note there is no arithmetic relationshp between the master rec and its child rec
    Kind Regards
    Satnam

    SQL> select m,c,row_number() over(partition by m order by rownum) r from sqn;
          M       C       R
        200     100       1
        200     105       2
        200     120       3
        205     150       1
        205     160       2
        210     300       1
        210     305       2
    7 rows selected.
    "sorry Avinash, not seen your post you already suggested the same"Message was edited by:
    Jameel

  • How to insert a record & reset the sequence for all record

    Hi All,
    I am using Oracle Form 6i. In one of my forms,
    I need to delete all records id and reset the ids in a sequence when i do a new insert
    id value
    1 x
    2 y
    3 z
    when i insert a record 4 between 2 & 3 records with value 'A'
    id value
    1 x
    2 y
    3 z
    4 A
    what i need to modify
    id value
    4 x
    5 y
    6 A
    7 z
    i tried pre-insert trigger by going to first record & looping . no luck.
    Could anyone suggest me.
    thanks
    Red
    Edited by: Red on Sep 15, 2008 7:11 AM

    Would it not be fine if you ensure that all your commit actions are coded as,
    Do_Key ('COMMIT_FORM') correction: In regards to u3's response
    You would also have to override relevant key trigger behavior to check for form changes.
    KEY-ENTQUERY, KEY-EXECQUERY, ....
    If your form is a master detail form, On-Clear-Details (This is a tricky one to maintain :-))
    Edited by: easot on Sep 16, 2008 6:32 PM
    correction

  • Reset Task Sequence Variables cached in WinPE - Possible ?

    Hi All,
    We are currently receiving prestaged computers from vendor, the image on the disk is out of date. I have added logic to detect old prestaged images, upon detection it will download latest wim from DP and deploy. This automatically wipes the disk before applying
    the wim. 
    During the os build an error occurs when installing the sccm client, this is because in the prestaged build i specified that the SCCM Client should be cached onto the disk. Because the contents of the disk is wiped due to the latest wim being downloaded
    and applied the task sequence still looks for the cached package which has been deleted... i imagine this is due to the information being cached in a TS Variable...
    Is there any way i can remove this variable, or perhaps all variables relating to the prestaged build if an old prestaged image is detected...?
    "note: going forward i will not be caching any packages into a prestaged build"
    Many thanks.. 

    I don't work with pre-staged media much so don't know if what you want is actually stored in a variable that can be overwritten or not; however, you can overwrite the value of any (non-read only) variable at run-time by using the standard methods
    including the set task sequence variable task or a script that uses the Microsoft.sms.ysenvironment com object.
    Jason | http://blog.configmgrftw.com | @jasonsandys

  • Resetting sequences....

    Hi all,
    I have this table which uses sequence as pk and somehow it went out-of-sync....i try to reset it using something like...
    alter sequence <seq_name>
    increment by 1
    minvalue <maxvalue_at_present>
    my question is
    --how a sequence went out-of-sync all of a sudden when it has the maxvalue set to 999999999999999999999999999 ???
    -- can i reset the sequence back to some mid-number....example
    say if the seq was 9000 and it got reset by next 9000 (my mistake). Now the nextval from dual is 18000. since 9000 was incremented by another 9000 which are not used, can we reset it back to 9000 and then increment it by 1 again???
    Any help is highly appreciated...thanks in advance....

    Totally agree with everyone that there really shouldn't be a need to reset sequences, but I do know when doing testing there can be circumstances when you want the sequence to start at a particular value in order to bring disperate things back into sync... so in answer to...
    can i reset the sequence back to some mid-numberYes you can...
    e.g. I want to reset my sequence to 50...
    SQL> select test.nextval from dual;
       NEXTVAL
           125
    SQL> var v_inc number;
    SQL> var v_resetno number;
    SQL> exec :v_resetno := 50;
    PL/SQL procedure successfully completed.
    SQL> exec execute immediate 'select -(test.nextval-:x)-1 from dual' into :v_inc using :v_resetno;
    PL/SQL procedure successfully completed.
    SQL> exec execute immediate 'alter sequence test increment by '||:v_inc;
    PL/SQL procedure successfully completed.
    SQL> select test.nextval from dual;
       NEXTVAL
            49
    SQL> alter sequence test increment by 1;
    Sequence altered.
    -- JOB DONE.  The sequence is now ready to use... and will start at 50...
    SQL> select test.nextval from dual;
       NEXTVAL
            50
    SQL> select test.nextval from dual;
       NEXTVAL
            51
    SQL>

  • Creation of sequence in etext template

    Hi All,
    I am creating a custom etext template for a invoice payment which will be forwarded to bank.
    The file will be generated for each invoice payment made one at a time.
    So, I have a requirement where in need to generate a sequence number in of the fields of the extext template. When the first file is send to bank, the sequence should be 1, for the second run the sequence should display 2 and so on.
    Here we cannot use the <RESET AT LEVEL> as RECORD or LEVEL as we need to control the sequence outside the etext template and in the database. So, I believe we should use PERIODIC_SEQUENCE that controls the value in database level.
    My question is how to achieve the relation between the database value and the etext template value.
    ex:
    <DEFINE SEQUENCE> allrecordsequence
    <RESET AT LEVEL> PERIODIC_SEQUENCE
    <INCREMENT BASIS> /outboundtransaction/paymentsequence[sequencename=allrecordsequence]/lastvalue + 1
    <END DEFINE SEQUENCE> allrecordsequence
    In the etext template
    sequence(allrecordsequence)
    The value in the etext template is always generation as 1, as the database record paymentsequence/lastvalue is null.
    Here is the user guide notes:
    Reset at Level
    The reset at level subcommand defines where the sequence resets its starting number. It is a mandatory subcommand. For example, to number the payments in a batch, define the reset at level as Batch. To continue numbering across batches, define the reset level as RequestHeader.
    In some cases the sequence is reset outside the template. For example, a periodic sequence may be defined to reset by date. In these cases, the PERIODIC_SEQUENCE keyword is used for the reset at level. The system saves the last sequence number used for a payment file to the database. Outside events control resetting the sequence in the database. For the next payment file run, the sequence number is extracted from the database for the start at number (see start at subcommand).
    But the sequence value in the database is not getting incremented.
    Appreciate an early response as it is really urgent.
    Thank you in advance.

    I have developed the solution using the below approach-
    Requirement - ( My requirement was a little different to what was mentioned above)
         To generate a sequence number in the e-text template of a invoice payment file.
         In a day when the first file is send to the bank, the sequence should be 1, for the second file the sequence should be 2.
         For the next day run the sequence value should be reset to 1.
    Approach 1) Use the IBY_FD_EXTRACT_EXT_PUB hook and Use sequence in the e-text template.
    GET_INS_EXT_AGG procedure is called once only for the payment instruction.
    It will add XML data element under OutboundPaymentInstruction tag.
    Add a new XML tag with the successful count of the formatted payments in a day.
    SQL query.
    SELECT COUNT (1)
    INTO v_payment_count
    FROM iby_payments_all a
    WHERE UPPER (a.org_name) = <org_name>
    AND UPPER (a.payment_profile_sys_name) =
    'profile system name'
    AND TRUNC (a.creation_date) = TRUNC (SYSDATE)
    AND a.payment_service_request_id <
    (SELECT MAX (b.payment_service_request_id)
    FROM iby_payments_all b);
    In the e-text template use the sequence number
    <DEFINE SEQUENCE>     RecordSeq1
    <RESET AT LEVEL>     OutboundPaymentInstruction
    <INCREMENT BASIS>     LEVEL
    <START AT>          1
    <END DEFINE SEQUENCE >     RecordSeq1
    While referring to the sequence use :- SSPN_PAYMENT_COUNT + SEQUENCE_NUMBER(RecordSeq1)
    to get the latest count of payment files.
    Approach 2) Using payment system
    <DEFINE SEQUENCE>      RecordsSeq1
    <RESET AT LEVEL>      PERIODIC_SEQUENCE
    <INCREMENT BASIS>      LEVEL
    <START AT> /PaymentSequence[SequenceName=’RecordsSeq1’]/LastValue + 1
    <END DEFINE SEQUENCE > RecordsSeq1
    By using a PERIODIC_SEQUENCE it will periodically generate the numbers.
    SEQUENCE_NUMBER(RecordsSeq1) is used to generate the number.
    I believe we need to have a payment system defined and associate the same to a Payment Process Profile.
    Only then can it have association with the last sequence number in the database.
    Please correct me if the Approach#2 set up is incorrect.
    Since Payment system was not necessary for the payment profile that we have used I have used approach 1
    Approach 2 can be used as a guideline :)

  • Select from table in group of columns and generate a sequence number

    I have to select data from a table in group of columns and generate a sequence for every group resetting the sequence to start from 1 onwards.
    For example:
    Data:
    Col1 Col2 Col3 Col4
    A NA KA 2009-08-13
    B NA KA 2009-08-13
    C NA KA 2009-08-13
    A NA KA 2009-08-13
    B NA KA 2009-08-13
    A NA KA 2009-08-13
    Expected output from Select Statement:
    Col1 Col2 Col3 Col4 Seq_No
    A NA KA 2009-08-13 1
    A NA KA 2009-08-13 2
    A NA KA 2009-08-13 3
    B NA KA 2009-08-13 1
    B NA KA 2009-08-13 2
    C NA KA 2009-08-13 1
    How can this be possible with a SELECT statement? Is it possible to assign seq numbers for a group of columns and reset it when it changes? In the above example, all columns form the key to generate the seq number
    I know it can be done using Stored procedures and that is how I am doing it now by introducing a temporary table.
    Can anyone help me in this regard? Please let me know if the question is vague to understand!
    Thanks,
    Nachi

    with t as(select 'A' col1,'NA' col2 ,'KA' col3,'2009-08-13' col4 from dual
    union all
    select 'B' col1,'NA' col2 ,'KA' col3,'2009-08-13' col4 from dual
    union all
    select 'C' col1,'NA' col2 ,'KA' col3,'2009-08-13' col4 from dual
    union all
    select 'A' col1,'NA' col2 ,'KA' col3,'2009-08-13' col4 from dual
    union all
    select 'B' col1,'NA' col2 ,'KA' col3,'2009-08-13' col4 from dual
    union all
    select 'A' col1,'NA' col2 ,'KA' col3,'2009-08-13' col4 from dual)
    select t.*,row_number() over (partition by col1,col2,col3,col4 order by col1,col2,col3,col4) from tYou can replace partition by col1,col2,col3,col4 with only columns that you need for grouping condition
    and also order by you can just do on the column you need.

  • Daily sequence number

    Hi,
    I need a clean solution for a daily sequence number (starts from 1 everyday). Clean in the sense that upon initial setup, I do not have to do anything and I can get my number everyday by just one jdbc call/query.
    Thank you in advance.

    What is the business justification for this requirement? Normally, you should just use a regular non-resetting sequence. If users want to see a "pretty" sequence number, simply generate something for them when you query the data using the row_number, rank, or dense_rank analytic functions. If users want to see sequences reset, they probably also want to see gap-free sequences, which is not something that you can ever guarantee in a scalable system where multiple users are allowed, though you can present gap-free sequences of values at query time.
    You can have a job that either drops and recreates the sequence every day or that goes through some logic to reset the sequence to 1 by changing the increment. This gets rather hairy, though, because the job will fail (or fail to run) on occasion and requires that no one be processing data at the time.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

Maybe you are looking for

  • FI data extraction help

    HI All, I have gone thorugh the sdn link for FI extarction and founf out to be very  useful. Still i have some doubts.... For line item data extraction...........Do we need to etract data from 0FI_GL_4, 0FI_AP_4, 0FI_AR_4, into ODS0FIGL_O02(General L

  • CS5 Importing Split EX files

    Premiere CS4 I have just done a shoot of a church service. I have 4 EX takes, the first 3 are single clips and the forth is spanned over 8 files. How do I import these into Premiere so that the 8 split files are recombined into 1 clip? If I use 'impo

  • Can I import a playlist over home sharing?

    I have my main music collection on my iMac running iTunes 12.  It includes some playlists I would like to have in an older Macbook Pro, running iTunes 11.4.  I have my Home Sharing turned on, and can import the items in the playlist, but have not fig

  • The latest update of the 17 2.5 & 2.6GHz has a good 8600 processor. right?

    ie. Apple aren't putting in faulty NVIDIA 8600 graphics processors Any ideas?

  • DB2 connection in IDT

    Hi All, I'm on BI 4.1 SP03 and trying to create a connection to DB2 V7 using IDT. When i go to the database middleware driver section and did the following. * Selected DB2 for i v7 * Entered username and password and Alias (database name) 1. What is