Sequence ID generator

Hello world

I have Forms 6i and a colleague you have send me the following code to generate IDs and I insert this code in my program unit

like a function body, but when I compile the program I get the following error:

BDP-PPU017 the source of program unit must define a body of subprogramme or packaging.

FUNCTION to CREATE or REPLACE generated_id (p_table VARCHAR2) NUMBER of RETURN IS

l_generated_id NUMBER;

l_table_name VARCHAR2 (30): = SUPERIOR (p_table);

BEGIN

BEGIN

ID SELECT INTO l_generated_id

FROM my_table

WHERE NOMBRE_TABLE = l_table_name

UPDATE; -it blocks the current line

l_generated_id: = l_generated_id + 1;

UPDATE my_table

SET id = l_generated_id

WHERE NOMBRE_TABLA = l_table_name;

EXCEPTION

WHEN NO_DATA_FOUND THEN

l_generated_id: = 1;

INSERT INTO my_table (NOMBRE_TABLA, id)

VALUES (l_table_name, l_generated_id);

END;

RETURN l_generated_id;

END;

Can someone please help me solve this problem?

BDP-PPU017 the source of program unit must define a body of subprogramme or packaging.

Moreover, the reason why you get this error is because you cannot use the CREATE or REPLACE in a program unit Oracle Forms syntax.  It's only the syntax of database.  If you want to use this method, set the function in the database if you make several trips to the forms database.

This solution has a specific purpose - to make a gapless sequence, if you need (Oracle sequences will never generate a free sequence space of numbers).

It is very good for a value which must be gapless, but I would not use it as the primary key for a table ID.  In addition, how well this code takes in a multi-user environment?  Since there is no COMMIT in the service, I assume that the validation will come from the routine by calling the Generate_ID function.  That being the case, it is possible that another session might call this function and get the same ID as a session that did not err again and validate before the previous session, making the ID generated by this session a duplicate.  (This makes sense?).

Just my thoughts on this...

Craig...

Tags: Oracle Development

Similar Questions

  • The use of sequence and generate the number in a table that has data

    Hello

    There is a custom table that has a column Rowid (NULL).
    This table already has 10 k with rowid as null lines, now the user asks me to enter a unique number for the Rowid.
    I created a sequence, but don't know how to use this sequence and generate numbers for the Rowid.

    Could you suggest.

    Thank you.

    "rowid" is an oracle reserved word and should be avoided. Perhaps "Rowid" between quotes or something.

    Here's how to "fill" a column by a sequence:

    SQL> create table t (id number, value varchar2(100));
    
    Table created.
    
    SQL> insert into t (value) select object_name from all_objects where rownum <= 10000;
    
    10000 rows created.
    
    SQL> create sequence idgen_sequence;
    
    Sequence created.
    
    SQL> update t set id = idgen_sequence.nextval;
    
    10000 rows updated.
    

    Given that the sequence was used all the 'id's will be unique.

  • How to create a sequence that generates in the form of intellectual property?

    Hello

    I want to create a sequence that can generate an IP numbers. as

    224.0.0.1
    224.0.0.2
    .
    .
    .
    224.255.255.255

    Is this possible?


    Thank you very much

    KinsaKaUy? wrote:

    Then, just the format of address IP (exercise left to you)

    Hint please :)

    Enter the socket interface ntoa - simple enough to reproduce in the SQL and PL/SQL.

    PS. Look in the section "+ dotted IP number +"-it should run to the top of implementation details.

  • Alphanumeric sequence numbers generator

    How to generate an alphanumeric sequence number in oracle?

    Like this:
    0000
    0001
    0002
    ......
    9999
    A000
    A001
    A002
    .....
    A999
    B000
    B001
    B002
    .....
    .....
    Z999
    AB00
    AB01
    AB02
    .....

    I forgot to say, if you want to wrap back to 0000 when it reaches ZZZZ, then you will need to mod the first element of 36 too...

    SQL> ed
    Wrote file afiedt.buf
    
      1  with b36 as (select '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' as b36 from dual)
      2      ,num as (select rownum+1679600 as num from dual connect by rownum <= 50)
      3  --
      4  select num.num,
      5         substr(b36.b36, mod(trunc(num.num/(36*36*36)),36)+1, 1)||
      6         substr(b36.b36, mod(trunc(num.num/(36*36)),36)+1,1)||
      7         substr(b36.b36, mod(trunc(num.num/36),36)+1,1)||
      8         substr(b36.b36, mod(num.num,36)+1,1)
      9* from num, b36
    SQL> /
    
           NUM SUBS
    ---------- ----
       1679601 ZZZL
       1679602 ZZZM
       1679603 ZZZN
       1679604 ZZZO
       1679605 ZZZP
       1679606 ZZZQ
       1679607 ZZZR
       1679608 ZZZS
       1679609 ZZZT
       1679610 ZZZU
       1679611 ZZZV
       1679612 ZZZW
       1679613 ZZZX
       1679614 ZZZY
       1679615 ZZZZ
       1679616 0000
       1679617 0001
       1679618 0002
       1679619 0003
       1679620 0004
       1679621 0005
       1679622 0006
       1679623 0007
       1679624 0008
       1679625 0009
       1679626 000A
       1679627 000B
       1679628 000C
       1679629 000D
       1679630 000E
       1679631 000F
       1679632 000G
       1679633 000H
       1679634 000I
       1679635 000J
       1679636 000K
       1679637 000L
       1679638 000M
       1679639 000N
       1679640 000O
       1679641 000P
       1679642 000Q
       1679643 000R
       1679644 000S
       1679645 000T
       1679646 000U
       1679647 000V
       1679648 000W
       1679649 000X
       1679650 000Y
    
    50 rows selected.
    
    SQL>
    
  • Generate the '@' character ascii with an ATL sequence on a T60p laptop?

    Greetings,

    I have a Lenovo T60p laptop. How to emulate a full 102 key keyboard when it comes to composing as ATL-64 sequences to generate the '@' character ascii. I read the documentation and did not.

    Kind regards

    Jean-Pierre

    After you activate the number lock the box red is the num pad and the characters and numbers in the lower right corner of the surface of the key is activated.

    If the "M" button is now a '0 '.

    The zero on the left while typing in the ASCII code for the '@' is required for windows - so you ask Microsoft, but not me

  • documentation for the sequence file report does not display the parameters of the step

    The parameters of the step is missing in this report. Is it possible to add this just as you have included the sequence settings. Thank you.

    Sequence: MainSequence
    Type: Normal
    Disable the results for all stages: false
    Goto cleanup in case of failure: use the Station Option
    Number of installation steps: 2
    Number of steps: 10
    Number of steps of cleaning: 2
    Parameters:
    PartNumber String (by reference)

    -Stage: Installation Instruction
    StepType, adapter: Message Popup. 
    Description: NameOf (Step)
    Module loading and unloading Options: preload the beginning of execution, discharge the closure of movie file
    Record results: disabled
    Flow properties: Post Action:
    If)
    GoTo
    Record result: disabled

    I agree that it's frustrating.  I had the same problem recently.

    You should post it in the forums of idea: http://forums.ni.com/t5/NI-TestStand-Idea-Exchange/idb-p/teststandideas

    Or you can change the sequence that generates these and include parameters.  The source so that it is in: \Components\Tools\DocGen

    Hope this helps,

  • Generation of multiple reports in subdirectories with the calls of the nested sequence

    I would like to generate different paths for multiple sequences, which are each managed in respect of execution of their own.  The following text displays the desired hierarchy:

    YYYY. MM DD. HH.mm.ss_MainSequenceFileName\Test [email protected]
    YYYY. MM DD. HH.mm.ss_MainSequenceFileName\YYYY. MM DD. HHmm.ss_SequenceGroup1\Sequence group [email protected]
    YYYY. MM DD. HH.mm.ss_MainSequenceFileName\YYYY. MM DD. HHmm.ss_SequenceGroup1\Test tswan.html
    YYYY. MM DD. HH.mm.ss_MainSequenceFileName\YYYY. MM DD. HHmm.ss_SequenceGroup2\Test tswan.html

    where:

    Summary of the test contains only steps of the MainSequence of the MainSequenceFile
    SequenceGroup1 is a step of calling in MainSequence with new execution sequence (to generate a separate report).
    Note: The subsequences of the SequenceGroup are stored in a different sequence file.

    Example of a hierarchy:
    MainSequence-> SequenceGroup1-> SubSequence1, SubSequence2, SubSequence5
    MainSequence-> SequenceGroup2-> SubSequence2, SubSequence3, SubSequence4

    Would result in the following files:
    2010.08.18.10.00.00_MainSequenceFile\Test [email protected]
    2010.08.18.10.00.00_MainSequenceFile\2010.08.18.10.05.00_SequenceGroup1\SequenceGroup1 [email protected]
    2010.08.18.10.00.00_MainSequenceFile\2010.08.18.10.05.00_SequenceGroup1\Test1.html
    2010.08.18.10.00.00_MainSequenceFile\2010.08.18.10.05.00_SequenceGroup1\Test2.html
    2010.08.18.10.00.00_MainSequenceFile\2010.08.18.10.05.00_SequenceGroup1\Test5.html
    2010.08.18.10.00.00_MainSequenceFile\2010.08.18.10.40.00_SequenceGroup1\SequenceGroup2 [email protected]
    2010.08.18.10.00.00_MainSequenceFile\2010.08.18.10.40.00_SequenceGroup1\Test2.html
    2010.08.18.10.00.00_MainSequenceFile\2010.08.18.10.45.00_SequenceGroup1\Test3.html
    2010.08.18.10.00.00_MainSequenceFile\2010.08.18.10.45.00_SequenceGroup1\Test4.html

    My plan was to specify the base path using the StationGlobals (for support through several files), and then use the ReportOptions reminder in the file of the main sequence and the sequence of group file.  However, the recall of ReportOptions occurs only in the file in the main sequence.  If I create a ReportOptions reminder in the sous-suite file, it will never be called.  The ReportOptions of the MainSequenceFile callback is only called (since that's where the new run is launched I guess).

    In my view, that this hierarchy could be created using what follows:
    In the ReportOptions callback, get a reference to the sequence of the appellant step and determine if it is a SequenceGroup_SequenceCall (a type of special stage that I created), if so then use a different expression to generate the name of the subdirectory and report.  If this isn't the case, then use the expression of the main sequence.

    It would take to what follows the ReportOptions in MainSequence reminder:

    1 get the reference to MainSequence path of the report generated from the process template.  This could be done by storing the RunState.Root.Locals.ReportPath in a StationGlobals variable before the new sequence.

    • Is it possible to do without StationGlobals?  A SequenceCall parameter is most appropriate?

    2 get the reference to the call of the sequence step

    • Not sure what the best way to achieve this.  Please notify.

    3. date format
    The statement to get the start time of the SequentialModel is not called that after ReportOptions recall and the path of the file Expression determine report.  This is why the name of the report file timestamp may be different from the header of the report.

    • Why the statement to get the start time is not called as the first step of the sequence, and what are the consequences of this change in the sequential model?

    My questions are indicated by bullets that precedes.  Any help would be greatly appreciated!

    Hello

    I created a small example that should full fill your requests.

    Note: I have only tested in Mode Single Pass (No. Serialnumber request!)

    No StationGlobals when used. To get the parent folder data two queues when used in ReportOption callback

    Hope this helps

    Jürgen

  • sequence value recycle

    Hello

    Just a question about the operation of sequences. If its used for the primary key and I remove a line (say ID: 1058), a sequence would generate 1058 again? Or would it just continue upward to MAXVALUE?

    Thank you

    11 G R2 using Linux

    >
    Just a question about the operation of sequences. If its used for the primary key and I remove a line (say ID: 1058), a sequence would generate 1058 again? Or would it just continue upward to MAXVALUE?
    >
    Whenever you call NEXTVAL continues upward to the MAX VALUE.

    A sequence is an object of independent schema. He is not aware of any other object, a table, or if its value is always used.

    See CREATE SEQUENCE in the doc of SQL language
    http://docs.Oracle.com/CD/B28359_01/server.111/b28286/statements_6015.htm
    >
    Use the CREATE SEQUENCE statement to create a sequence, which is an object database where several users can generate unique integers. You can use sequences to automatically generate primary key values.

    When a sequence number is generated, the sequence is incremented, independent of the transaction validation or restoration. If two users concurrently increment the same sequence, sequence numbers acquired by each user may have gaps because sequence numbers are generated by the other user. A user can never acquire the sequence number generated by another user. When a sequence value is generated by a user, that user can continue to access this value, regardless of whether if the sequence is incremented by another user.

    Sequence numbers are generated independently of tables, so the same sequence can be used for one or more tables. It is possible that individual numbers will be seem to be ignored, as they were generated and used as part of an operation which finally cancelled.
    In addition, a single user may not realize that other users are in the same sequence.

    Once a sequence is created, you can access its values in SQL statements with the virtual CURRVAL, which returns the current value of the sequence, or the virtual NEXTVAL, which increments the sequence and returns the new value.

  • With regard to the update of the sequence

    Hello

    We have OGG 11.1.1.1 and 11.2.0.3 DB.

    I have a small question about the improved Support of sequence
    According to the documentation:
    Installing new Oracle sequence support 
    Oracle GoldenGate version 11.1.1.1 contains improved sequence support. To enable this 
    support, you must install some database procedures that support the new FLUSH 
    SEQUENCE command. 
    Follow these instructions on the sourceand targetsystems. 
    1.  On the source and target Oracle systems, connect to SQL*Plus as SYSDBA. 
    2.  If you already assigned a database user to support the Oracle GoldenGate DDL 
    replication feature, you can skip this step. Otherwise, on both systems create a 
    database user that can also be the DDL user. 
    SQL> CREATE USER DDLuser IDENTIFIED BY password; 
    SQL> GRANT CONNECT,RESOURCE,DBA TO DDLuser; 
    3.  In the GLOBALS file on the source and target systems (create one if needed), add 
    the following parameter to designate the DDL schema. (If you already have this 
    parameter, skip this step.) 
    GGSCHEMA <schema> 
    4.  On both systems, run the sequence.sqlscript from the root of the Oracle 
    GoldenGate installation directory. This script creates some procedures for use by 
    Oracle GoldenGate processes. (Do not run them yourself.) You are prompted for 
    the schema information that you created in the first step. 
    SQL> @sequence.sql 
    5.  On the source system, grant EXECUTE privilege on the updateSequence
    procedure to a database user that can be used to issue the DBLOGIN command. 
    Remember or record this user. You use DBLOGIN to log into the database prior to 
    issuing the FLUSH SEQUENCE command, which calls the procedure. 
    SQL> GRANT EXECUTE on DDLuser.updateSequence TO DBLOGINuser; 
    6.  On the target system, grant EXECUTE privilege on the replicateSequence
    procedure to the Replicat database user. 
    SQL> GRANT EXECUTE on DDLuser.replicateSequence TO Replicatuser; 
    Immediately after you start the Oracle GoldenGate processes for the first time, issue the 
    FLUSH SEQUENCE command for each sequence (or with a wildcarded name). This 
    command alters the sequence to generate redo data. Replicat uses this redo to create an 
    initial synchronization point. You are prompted for this command in the upgrade steps.
    He mentions several times that you should have 2 users (e.g., DBLOGIN & DDLUser). But we only use a "GGS" to do anything. We have arrays of heartbeat, we use in the dblogin controls everything. It will be a problem during setup of this? Should we change our Setup to support this? I'm asking is because I have no environment to test it myself, so I'd be happy to have some feedback before you ruin my production environment.

    Thank you
    NACEUR

    It can be even given it required privileges.

    -Koko

  • How can I increment a sequence

    I have this sequence that generates the ID in our system
       START WITH 10002
      MAXVALUE 999999999
      MINVALUE 1
    How do I change then. Our starting number should be 1109849

    Thank you

    Published by: 893973 on June 1, 2012 08:23

    >
    then increment by 1109849-10275 = 1099574?
    >
    Who's going to do. Then just take a sequence number

    SELECT mySeq.nextval FROM DUAL;
    

    Then set the increment by back to 1 or whatever it was before.

    See ALTER SEQUENCE in the language SQL doc, if you need assistance.
    http://docs.Oracle.com/CD/E14072_01/server.112/e10592/statements_2012.htm

  • Replication sequence values of Golden Gate?

    Hi all

    I searched on the web and read the Golden Gate, but I found mixed answers.

    I try just to check, for some, it is possible to automatically reproduce the sequence values in a two-way configuration. The two databases will be identical and both will be GR 11, 2 with the latest version of GG.

    If it is not possible to increment automatically sequences in a bi-directional configuration, what are best practices for rest with them?

    One option is sequences of alternatives on each database, with the same values (for example) and an uneven values, but this requires the deployment of new sequences on two databases, something that we hoped would be supported by replication. (Yes the creation of the sequence can be supported, but the value is not incremented on the target database).

    Another way we thought on top of our heads is to have an insert trigger on (we only use sequences to generate surrogate keys) who will choose the database nextval target via a link db, but this seems a bit heavy.

    What is the best practice?

    GoldenGate forum is here:
    GoldenGate

  • Sequences

    Is it possible to reset the sequence to its original value?


    Sanjay

    Hi, Sanjay

    user12957777 wrote:
    Actually I had imported a dump in a schema / user. But I want to reset to the original footage in this scheme, because there the last sequences cached the previous image or user.

    Sanjay

    You import the lines, or simply the table structures?
    If you imported the data, then porbably you want to keep the old values. If a sequence used to fill a column id, then you want the sequence to generate unused numbers. If the sequence of numbers 1, 2, 3,..., 25 in the old database and lines with ID 1, 2, 3,..., 25 exist in the imported table, you do not want to generate 1, 2, 3,... for new lines.

  • Getting error during d incrementing sequences by 10000... required emergency help

    Hi, I'm getting below error during the race the slot type increment of 10,000 on some sequences:

    Example query
    alter sequence increment 10000 AC1_CONTROL_SUMMARY_1SQ;

    The error;
    +++++++++
    change the sequence of increment AC_CONTROL_FILE_ID by 10000
    *
    ERROR on line 1:
    ORA-04005: INCREMENT must be less than MAXVALUE less MINVALUE

    alter sequence increment 10000 BL1_CHARGE_ADJ_1SQ
    *
    ERROR on line 1:
    ORA-04013: number of CACHE must be less than a cycle
    +++++++++
    My situation:
    Other teams are waiting for my task ends so that they can continue. I have to do something very quickly and provide the environment for them...

    +++++++++
    My questions at all:
    1. What can I do so that I'm increment these sequences of + 10000?
    2. changes as alter sequence MAXVALUE or alter the nocache sequence will have any negative impact on the database?
    3. the amendments referred to step reversible back. ??

    My questions at all:
    1. What can I do so that I'm increment these sequences of + 10000?
    2. changes as alter sequence MAXVALUE or alter the nocache sequence will have any negative impact on the database?
    3. the amendments referred to step reversible back. ??

    Answers to your questions:

    1 ALTER SEQUENCE sequence_name
    INCREMENT OF 10000
    NOMAXVALUE
    NOCYCLE
    CACHE 20;

    2. the NOCYCLE option indicates that the sequence cannot generate more values after reaching its maximum or minimum value.

    3. the amendments referred to step reversible back. ??
    INCREMENT OF ;

    Published by: rajeysh on July 21, 2010 23:46

  • Creation of the sequence

    Hello

    I have need of a sequence to be generated as follows.

    X 00
    X 01
    .
    .
    X 99
    Y00
    Y01
    .
    .
    Y99
    Z00
    Z01
    .
    .
    Z99
    XY0
    XY1
    .
    .
    XY9
    YZ0
    .
    .
    YZ9
    ZX0
    .
    .
    ZX9
    ZZZ

    Do we not have a built-in function to generate sequences like this, or something like that?

    Akhil N K wrote:
    Hello

    I have need of a sequence to be generated as follows.

    X 00
    X 01
    .

    Do we not have a built-in function to generate sequences like this, or something like that?

    Oracle sequences only generate numbers. You will need to write your own function to get the alpha characters added.

    I'd be curious to know the rational business for such a requirement. There could be a more elegant solution if we knew that.

  • What is the problem with the sequences on RAC environments?

    Version: 10 g, 11G

    I've never worked on CARS. But I keep seeing discussions about the problems with the sequences on CCR environments. What exactly is the
    basic question?

    Can be performance issues if you have a large number of sequences of nocache as it may cause heavy IO for the system tablespace.

    Given that each instance will have its own cache seqeuence that some sites are unhappy with significant gaps in the values, this can cause.

    There was also a blocking problem caused by heavy simultaneous new connection activity requiring the issuance value audsid for the session of v$. To solve this just to the top of the cache size to 1,000 or 10,000 by default if you are on a version where the value was not moved upward by Oracle already.

    As far as the first two numbers go that my view is if the sequence does not need to be cached you need not use a sequence to generate value. If you need a value without interval then you need to get your value from a table column value that is part of the transaction and do not use a sequence in a first time.

    Sequences are designed for speed and concurrentcy, and this competition is priced at gaps.

    HTH - Mark D Powell.

Maybe you are looking for