Sequence number to generate an item Code

Dear friend

I want to change my existing master finished painting and want to give a fresh article number in the following way.

ITEM_TYPE ID
----------- --------------------

RAW 100000001
CYLINDER 200000001
300000001 ENGINEERING
VARIOUS 400000001
500000001 PRODUCTS FINISHES

Can you suggest me which application I should give. While in short time I can update my itemmaster with new item code table.

Sandy

First Exchange with the item_type, then a numeric sequence number?

declare
cursor types is
  select distinct item_type, rownum n
    from items ;
begin
  for r in c loop
     update items
       set id = r.n||to_char(rownum,'FM00000000')
     where item_type=r.item_type;
  end loop;
end;
/

Max
[My Italian blog Oracle | http://oracleitalia.wordpress.com/2010/02/07/aggiornare-una-tabella-con-listruzione-merge/]

Tags: Database

Similar Questions

  • Generate the sequence number

    
    create table t
    (id int primary key,
    dt date,
    file_no int,
    batch_no int,
    data varchar2(5)
    );
    
    insert into t values (1,trunc(sysdate),23,113,dbms_random.string('a',5)); -- 1.1.1
    insert into t values (2,trunc(sysdate),23,345,dbms_random.string('a',5)); -- 1.2.1
    insert into t values (3,trunc(sysdate),23,345,dbms_random.string('a',5)); -- 1.2.2
    insert into t values (4,trunc(sysdate),23,543,dbms_random.string('a',5)); -- 1.3.1
    insert into t values (5,trunc(sysdate),23,543,dbms_random.string('a',5)); -- 1.3.2
    insert into t values (6,trunc(sysdate),23,543,dbms_random.string('a',5)); -- 1.3.3
    --
    insert into t values (7,trunc(sysdate),24,333,dbms_random.string('a',5)); -- 2.1.1
    insert into t values (8,trunc(sysdate),24,333,dbms_random.string('a',5)); -- 2.1.2
    insert into t values (9,trunc(sysdate),24,333,dbms_random.string('a',5)); -- 2.1.3
    insert into t values (10,trunc(sysdate),24,222,dbms_random.string('a',5)); -- 2.2.1
    insert into t values (11,trunc(sysdate),24,222,dbms_random.string('a',5)); -- 2.2.2
    insert into t values (12,trunc(sysdate),24,111,dbms_random.string('a',5)); -- 2.3.1
    
    
    

    Oracle 11.1

    How can given this structure and data, I generate sequence at the end of each line numbers? Basically, the sequence number (x.y.z) is such that x (1.n) is awarded for each unique value in file_no. In each x, y (1.n) is assigned for each unique value of batch_no. Within each y, z (1.n) is assigned for all records of this batch. Sample data shows only dt but all sequences must reset and start over when dt changes.

    I tried using row_number() over (partition by dt, file_no) and such but nothing quite gives me what I'm looking for.

    Help? Thank you

    Hello

    HELEN wrote:

    If you look at my CREATE TABLE, the ID column is a primary key and represents the order of the data in the file.

    Done batch_no = 100 come before or after 101?  Batch_no = 100 a ID so much until after the id for batch_no = 101.

    Good point, but that won't happen because of the way the 'record' is generated. All batch_nos will be contiguous. So if batch_no 100 comes earlier in the file as 101, it should get some 2nd highest sequence number. Otherwise, lower. Basically, the 2nd part of the sequence must simialar logical number to the 3rd party (i.e. order by id) but that messes things. Still struggle with it. Any help appreciated.

    I think I understand.  You say that, because of the way that the ID is issued, it wouldn't matter if you used the highest id of the batch_no, or the lowest id, or the average, or if you chose one at random; you would get the correct order in all cases.

    The following query uses the id low in the order file_no and batch_nos.

    WITH got_min_ids AS

    (

    SELECT id, dt, file_no, batch_no, data

    MIN (id) over (PARTITION BY dt

    file_no

    ) AS min_id_file_no

    MIN (id) over (PARTITION BY dt

    file_no

    batch_no

    ) AS min_id_batch_no

    T

    )

    SELECT id, dt, file_no, batch_no, data

    DENSE_RANK () OVER (PARTITION BY dt

    ORDER BY min_id_file_no

    )

    || '.'

    || DENSE_RANK () OVER (PARTITION BY dt

    file_no

    ORDER BY min_id_batch_no

    )

    || '.'

    || ROW_NUMBER () OVER (PARTITION BY dt

    file_no

    batch_no

    ORDER BY id

    ) AS seq

    OF got_min_ids

    ORDER BY dt, min_id_file_no, min_id_batch_no, id

    ;

    The main request is in fact what I posted before, but instead of

    "ORDER BY file_no" and "ORDER BY batch_no", she uses

    "ORDER BY min_id_file_no" and "ORDER BY min_id_batch_no".  These values are calculated in the subquery, got_min_ids.

    Output (including the additional sample data I posted):

    ID FILE_NO DT BATCH_NO SEQ DATA

    ---------- ----------- ---------- ---------- ----- ----------

    1 23 25 April 2014 113 dXAad 1.1.1

    2 345 23 25 April 2014 pumVG 1.2.1

    3 345 23 25 April 2014 jLnbO 1.2.2

    4 23 25 April 2014 543 xKhCL 1.3.1

    5 23 25 April 2014 543 JQoWk 1.3.2

    6 23 25 April 2014 543 YjJeC 1.3.3

    7 24 25 April 2014 333 WjQNE 2.1.1

    8 24 25 April 2014 333 ScWSL 2.1.2

    9 24 25 April 2014 333 pXDSD 2.1.3

    10 222 24 25 April 2014 OSajn 2.2.1

    11 222 24 25 April 2014 QNpix 2.2.2

    12 24 111 OwkjI 2.3.1 April 25, 2014

    91 100 99 25 April 2014 sRWmT 3.1.1

    93 100 99 25 April 2014 IAEFd 3.1.2

    92 101 99 25 April odQxh 2014 3.2.1

    I know you said that this situation is impossible (that is, if ID 91 and 93 have the same batch_no, then id 92 cannot have a different batch_no), but the application works even if this rule is broken.

  • Can someone help me? Here's my problem, I typed my redemption code and got my serial number, but as I get a pen and crushed paper my computer and now I can't have my serial number for the 14 items

    Here's my problem, I typed my redemption code and got my serial number but as I get a pen and crushed paper my computer and now I can't have my serial number for the 14 items.

    All can help me please!

    First, check your Adobe account to see if the serial number is Adobe ID

    Otherwise, you need to contact Adobe directly

    Chat/phone: Mon - Fri 05:00-19:00 (US Pacific time) <===> NOTE DAYS AND TIME
    Don't forget to stay signed with your Adobe ID before accessing the link below

    Serial number and activation support (non - CC)

    http://helpx.Adobe.com/x-productkb/global/Service1.html

  • Generate a unique sequence number

    Hello

    I need generate a unique sequence number. I use Oracle 11.2, here are the details. The idSeq column is specific idType a unique interior. I don't want a sequence for each idType.

    create table tb_test (idSeq number (5), number (5) idType, addr varchar2 (256));

    insert into tb_test
    (to select when idSeq is null then 1 another max (idSeq) + 1 end, 3, "Main street");

    I have an ORA-00937: not a single-group function error, any suggestion?

    Published by: 939569 on February 13, 2013 11:21

    Hello

    939569 wrote:
    Hello

    I need generate a unique sequence number.

    Explain what you're trying to do, and why won't a sequence.

    I use Oracle 11.2, here are the details. The idSeq column is specific idType a unique interior. I don't want a sequence for each idType.

    create table tb_test (idSeq number (5), number (5) idType, addr varchar2 (256));

    insert into tb_test
    (to select when idSeq is null then 1 another max (idSeq) + 1 end, 3, "Main street");

    I have an ORA-00937: not an error of a single group group function,

    Right. Given that the subquery uses an aggregate function (MAX), all in the SELECT clause must be an aggregate, a group of expression, a constant, or something that is entirely up to them. In this example, the CASE expression depends on idSeq, which is not an aggregate, not a group by expression (there is no GROUP BY clause) and not a constant.

    In addition, the subquery must have a FROM clause. All queries and subqueries in Oracle require a FROM clause.

    any suggestion?

    Use a sequence. The numbers are not consecutive in each idType, but matter? Chances are, no matter what you do, you will not be able to maintain consecutive numbers within each idType anyway.

    If you do not use a sequence, then you can try:

    INSERT INTO  tb_test (idSeq, idType, addr)
    SELECT  1 + NVL ( MAX (id_seq)
                  , 0
              )
    ,       3
    ,     'Main street;
    FROM     tb_test
    WHERE   idType  = 3
    ;
    
  • Insert/update of the XML help merge and to generate the sequence number

    Hello

    I'm working on Oracle 11 g.

    I have a doubt with loading XML.
    I get an xml and I need to insert or update data in a table. What I can accomplish by using the MERGE statement.
    But there is a column in A table, I need to fill with a sequence number, based on the data sent in the xml file.
    The XML does not send the data in this column.
    And I have to make sure that sequence is created according to the order in which the records are present in xml.
    For example the MERGER is insert five rows and update two lines and insert again 3 rows of xml in table A. The sequence number must be created in the same order for the column in the table.
    Also for every new XML, the sequence starts with 1 and ends with the number of records in the xml file. I can't create a sequence and use the seq.nextval.

    Please let me know, there is a way to achieve this.

    Thank you!

    Published by: 934451 on 8 August 2012 06:33

    Published by: 934451 on 8 August 2012 06:50

    Hello

    As a result of your previous thread: {: identifier of the thread = 2403469}

    You can use the clause for ORDINALITE in XMLTable to generate the necessary sequence:

    MERGE INTO target_table t
    USING (
      SELECT x.seq_num, x.pk_id, x.col1, x.col2, ...
      FROM XMLTable(
             '/root/record'
             passing my_xml_doc
             columns seq_num FOR ORDINALITY
                   , pk_id   number       path 'ID'
                   , col1    varchar2(30) path 'COL1'
                   , col2    varchar2(30) path 'COL2'
                   , ...
           ) x
    ) src
    ON ( t.pk_id = src.pk_id )
    WHEN MATCHED THEN UPDATE
     SET t.seq_num = src.seq_num
       , t.col1 = src.col1
       , t.col2 = src.col2
       , ...
    WHEN NOT MATCHED THEN INSERT
     (seq_num, pk_id, col1, col2, ...)
     VALUES (src.seq_num, src.pk_id, src.col1, src.col2, ...)
    ;
    
  • How generations for db in the XSLT file sequence number

    Hello gurus SOA,.

    I have a requirement, please see below

    I am using SOA 11.1.1.6

    Insert a webservice to db, XSLT call, I have 10 items next to the source and 11 items next to the target.

    • Source to target first 10 mappings are performed.
    • Now the requirement is, for the 11th element target we must pass a sequence number to the database targeted, means-(sequence number must be generated for each execution of the XSLT execution)

    How do the last point?

    Can someone help me please

    Hello

    You can pass the sequence number in the 11th element to help. "oraext:sequence-next-val("Sequence name as a string", "Datasource as a string") function.

    Kind regards

    Anshul


  • Help on recovering database /Restore - no available controlfiles kccpb_sanity_check_2 control file sequence number mismatch

    Hi all.

    I really need your help on this:

    (1) version: 11.2.0.1 EE / Windows.

    (2) database does not start, don't get database.

    Alert.log info:

    Instance of stopped by USER, pid = 3652

    2015-11-22 15:57:19.763000 - 04:30

    I found this after using adrci:

    2015-11-22 15:49:15.727

    SESSION ID: (191.1) 2015-11-22 15:49:15.727

    CUSTOMER ID :() 2015-11-22 15:49:15.727

    NAME OF THE SERVICE :() 2015-11-22 15:49:15.727

    MODULE NAME: (sqlplus.exe) 2015-11-22 15:49:15.727

    ACTION NAME :() 2015-11-22 15:49:15.727

    Informational message:

    Control file 1 has seq 2713995, low 2713994 file # 0

    Error: kccpb_sanity_check_2

    Control file sequence number mismatch!

    fhcsq: bhcsq 2713995: 2714016 cfn 0

    2015-11-22 15:49:15.758

    USER (ospid: 2504): put an end to the instance

    Verification of MOS Note: 435436.1 I must:

    (1) to restore a backup of a controlfile and recover

    OR

    (2) to recreate the controlfile

    OR

    (3) restore the backup data and recovery

    It is a database, that I was not, up to now administer. But:

    (1) I tried from the database with addressed controlfile (the one located in FRA). No luck. (Create pfile from spfile / startup pfile)

    (2) the database is not mount / open. It hangs on the editing process. So I can not issue an alter database controlfile to trace.

    It seems that my options are:

    (1) manual creation of controlfile with open resetlogs option. This option is viable, but risky if we miss a datafile or something GOLD

    (2) restoration of RMAN backup. The thing is that the most recent copy of automatic backup of controlfile is since a few days early (4 / 5 days).

    I found this link: http://gavinsoorma.com/2009/07/rman-recovery-from-loss-of-all-control-files/

    The procedure seems easy, but since this controlfile is not in the current SNA of database (data files, etc.). I'm not sure it if it would work.

    So in short, I think I have an automatic backup controlfile and it's OK. but a little old. I can restore from this copy of CF?

    Please I'm pressed real here, so help will be greatly appreciated!....

    Thanks in advance!

    Best regards, Luis...!

    Hello

    It seems that my options are:

    (1) manual creation of controlfile with open resetlogs option. This option is viable, but risky if we miss a datafile or something GOLD

    (2) restoration of RMAN backup. The thing is that the most recent copy of automatic backup of controlfile is since a few days early (4 / 5 days).

    It seems that you have few options,

    In my opinion, you should start with option 2), but you have logs archived redo and all and all the backups of catalog and perform a restore.

    After, if not works, you must manually create the control files, but you are right, you must carefully on all the data files. Here a log generated in the last level 0 RMAN backup could help you, don't forget the newspaper are all entries of data for backup files.

    I wish to have more ideas to help you, but I have no other.

    I hope this helps.

    Kind regards

    Juan M

  • Error with groovy expression of sequence number of EO attribute assignment?


    Hello world

    My version of Jdeveloper is 11.1.2.3.0.
    Starting from this post: https://tompeez.wordpress.com/category/adf/page/6/
    I found to add a groovy expression for the sequence number to my attribute. I created a single sequence and added that the groovy expression to my attribute but got the error below:

    Utils > < buildFacesMessage > ADF: addition of the following JSF error message: failed to start, bc4j_model_TestEntityObject_Empno_null_gs.groovy: 1: lack of hook closing ' > ' for generic types.
    solution: Please specify the missing support! @ line 1, column 12.
    1 error

    org.codehaus.groovy.control.MultipleCompilationErrorsException: failed to start, bc4j_model_TestEntityObject_Empno_null_gs.groovy: 1: lack of hook closing ' > ' for generic types.
    solution: Please specify the missing support! @ line 1, column 12.
    1 error

    Note: groovy expresion used in my EO attribute is given below:
    (new class < SPAN > 'skimlinks-fidget' = > oracle.jbo.server.SequenceImpl ("SampleSeq", adf.object.getDBTransaction ())) .getSequenceNumber </span >)

    also used:
    (new class < SPAN > 'skimlinks-fidget' = > oracle.jbo.server.SequenceImpl ("SampleSeq", adf.object.getDBTransaction ()) .getSequenceNumber () </span >

    What can be the problem?
    Please give me your valuable contributions...


    Thank you.

    Sorry, somehow the code in the blog is messed up. Use

    (new oracle.jbo.server.SequenceImpl ("SampleSeq", adf.object.getDBTransaction ()) .getSequenceNumber)

    Where SampleSeq is the name of the sequence defined in the comic book.

    Timo

  • Overview of Dreamweaver device does not generate a QR code

    Always worked suddenly stopped yesterday?

    I changed nothing. Open Dreamweaver an hour or two after working on a project I had be seen very well and now the usual overview of the device (the small icon in the bottom right of window DW) generate a QR code. I left and restarted. Trashed prefs. Uninstalled and reinstalled... still does not... help!

    He was too involved... I run a small business and it took a lot of time... I would like to, but it was more to "type your heels three times and say there is no place like home!"

    Disconnect from all your accounts CC, uninstall, disable the MAC option in my case, reboot, reconnect to CC reinstall... try again. Some small piece of code (unknown) gets stuck in the system preventing the preview to generate a QR code. Nothing to do with any of the items mentioned on the check list of ADOBE. Way on my 'code head' as to what she was. Just once we determined to attempt to remove the "ghost", he returned and worked.

  • Automatic item code

    Hello

    I want to generate an automatic code (created by adding two or more columns).

    for example PO_no ID Po_type company point

    LPO001 001 LPO ABC XYZ
    IPO002 002 IPO ABC XYZ

    po_no = (PO_type + ID)

    Please help, thanks

    Depending on your version of the database unknown/mentioned, you can opt for a virtual column:

    SQL> create table t as
      2  select '001' id, 'LPO' po_type, 'ABC' company, 'XYZ' item from dual union
      3  select '002', 'IPO', 'ABC', 'XYZ' from dual;
    
    Table created.
    
    SQL> select * from t;
    
    ID  PO_ COM ITE
    --- --- --- ---
    001 LPO ABC XYZ
    002 IPO ABC XYZ
    
    2 rows selected.
    
    SQL> alter table t add po_no varchar2(10) generated always as (po_type||id) virtual;
    
    Table altered.
    
    SQL> select * from t;
    
    ID  PO_ COM ITE PO_NO
    --- --- --- --- ----------
    001 LPO ABC XYZ LPO001
    002 IPO ABC XYZ IPO002
    
    2 rows selected.
    

    http://www.Oracle-base.com/articles/11g/virtual-columns-11gr1.php
    If you are not on the version 11.1 of the database, or to leave, you can use a trigger that would insert the po_no insert.

    See the SQL and PL/SQL FAQ if you don't know the version of your database or how do I get.
    The FAQ can be found here: https://forums.oracle.com/forums/ann.jspa?annID=1535
    More precisely:
    {message: id = 9360002}

  • Synthetic Primary Key (sequence number) vs natural primary key

    I wonder if the sequence number is better than the primary key. I found a few tables only use the sequence number, some tables use the primary key only, and a few tables use both. Can someone give me a clue, one that I use when you create a table? TX in advance.

    Published by: 1B, 3 may 2012 21:07

    I'm not sure I understand the question. I do not understand how it is either / or question.

    Virtually every table must have a primary key. You can either use a primary key natural (something in the data that is unique and immutable) or you would use a synthetic primary key which is filled from a sequence. I strongly suggest using synthetic primary keys generated from a sequence for your primary key.

    Justin

  • How to run a same sequence number for the dynamic lines resulting

    Hi friends,

    I have a sequence and the trigger (which will trigger the id for each line insertion).

    My scenario is, if I update more than 5 lines of a way of time, I need to define a same example (1) sequence number for all the 5 rows.

    Next time, if I update another way for 5 rows, then I need to define a sequence of the same number (i.e.) 2 for the next 5 lines.

    So my update will be dynamic (can be 2, 5, 10 rows at a time), but I need a same sequence number for one of the column for all of the lines that I'm updating the value.

    Next time, if I update another series of lines means, then I need to put only the next sequence number (i.e) 2 (assume this sequence previously updated to the front of the set of rows is 1) for another set of lines.

    As this sequence should update in a sequential manner for more than a set of rows in this column.

    How friends.

    example of
    id-----------------name
    1-------------------A
    1-------------------B
    1-------------------C
    1-------------------D
    1-------------------E
    2-------------------D
    2-------------------E
    2-------------------F
    2-------------------G
    3-------------------H
    3-------------------I
    Brgds,
    Mini

    Generate the value of the sequence and store it in a variable and use this variable in the UPDATE.

    varSequence := .nextval;
    
    update  set  = varSequence where 
    
  • Min and Max of the sequence number

    Hello

    I have a table called pins (lot number 4,
    Sequence number (8)
    );

    I have data in the table:
    batch sequence
    386 100
    386 101
    386 102
    386 800
    386 801
    1 387
    2 387

    I want to know by draw the low values and high for sequence number, is the result, I am looking

    batch min (sequence), max (sequence)
    386 100 102
    386 800 801
    387 1 2

    Oracle 10g rel2

    Thank you

    Hello

    You want something like this:

    WITH       got_grp     AS
    (
         SELECT     lot
         ,     seq_num          -- SEQUENCE is not a good column name
         ,     seq_num - ROW_NUMBER () OVER ( PARTITION BY  lot
                                                      ORDER BY      seq_num
                                          ) AS grp
         FROM    pins
    --     WHERE     ...     -- any filtering goes here
    )
    SELECT       lot
    ,       MIN (seq_num)          AS min_seq_num
    ,       MAX (seq_num)          AS max_seq_num
    FROM       got_grp
    GROUP BY  lot
    ,            grp
    ORDER BY  lot
    ,            min_seq_num
    ;
    

    If I understand the probem, you want to GROUP BY, but many does not define groups by itself: each contiguous set of seq_nums in a batch is a separate group. In each of these groups, the difference between seq_num and a meter which reflects the order of seq_num generated in the query (using ROW_NUMBER) will be constant.

    This assumes that seq_num is an integer, and this (lot, seq_num) is unique.
    If this is not the case, the above query will have a small adjustment.

    If you want to display the INSERT statements for your sample data, then I could test this.

  • Re-problem sequence number

    Hi all
    I've created two text form items one number sequence and other for a sequence no, I want to when I add the text element in sequence no 01 then the sequence number does not change and it must remain the same? is it possible please help me thanks in advance.



    Sarah

    Published by: SarahSarahSarah on August 30, 2009 12:37 AM

    That's nice! :)

    And what type of trigger do you? May when-validate-item in ZEDNO?

    begin
    if
      :ins1.EDNO is null
    then
      SELECT sarahseq.NEXTVAL INTO :ins1.serial FROM DUAL;
    end if;
    end;
    
  • Creating a trigger to insert delete update with the sequence number

    Hey all,.
    I have two tables. tbl_main, tbl_temp. Whenever a record is inserted, deleted, updated in tbl_main, I need to insert the records in tbl_temp. All field/column names are exactly the same, except that in tbl_temp, I now have a single column by using a sequence number, a column to determine if the record has been updated, remove, modified(hence the codes) and the date when a record has been added to the table.
    So far, that's what I have:

    create or replace
    audit_trg relaxation
    after update or insert or delete ON tbl_main
    for each line
    Start
    If the update can
    insert into tbl_temp (seq_id, idx, ctl, action_taken, date_added)
    VALUES
    (temp_seq.nextval, idx, mke, ctl, sysdate, 'U');
    ELSif INSERTION then
    insert into tbl_temp (seq_id, idx, ctl, action_taken, date_added)
    VALUES (temp_seq.nextval, idx, mke, ctl, 'n', sysdate);
    ELSIF deletion then
    insert into tbl_temp (seq_id, idx, ctl, action_taken, date_added)
    VALUES (temp_seq.nextval, idx, mke, ctl, would be ', sysdate);
    END IF;
    END audit_trg;

    I tried several combinations, but I get many compilation errors. This code looks good or I am the way of track? Thanks in advance.

    Who looks fine for me. What are the mistakes are you?

    Assuming that MKE and CTL are columns in the base table, your INSERT statements will insert either the: new.mke and: new.ctl values or the: old.mke and: old.ctl values in the table. Presumably, you could insert the: new values for inserts and updates, and the: old values for deletions.

    Justin

    Published by: Justin Cave 27 February 2009 16:08

    DOH! Just noticed the error...

Maybe you are looking for