Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

How to create a sequence number?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to create a sequence number?

    I want to have a column as the key field in a table. I like to have the value of the column as a pre-defined sequence number. How to do it in DB2? I know that in Oracle, you can do something like: CREATE SEQUENCE START FROM.... INCREMENT BY 1...... Thanks.

  • #2
    How to create a sequence number?

    I have solved this in the past by using the relative record number as a key field. I.e. UPDATE file SET keyfield = RRN(File)

    Comment


    • #3
      How to create a sequence number?

      Thanks a lot. It's very helpful. Do you have any problems about the uniqueness by using RRN?

      Comment


      • #4
        How to create a sequence number?

        If you use the RRN technique, make certain that you never delete records from the file and then reorg it. You could have duplicates in this case. Here's an example: you have 2 records in a file keyed by the RRN's 1 and 2 respectively. You delete the first record and reorg the file. The only record in the file now is keyed by the number 2. You then add in a 2nd record and *boom* duplicate key because the next RRN is 2 and the first record is already using that key. Chris

        Comment


        • #5
          How to create a sequence number?

          IN the 'INSERT Record' process use Rec_nbr_field = 1 + (select Max(Rec_nbr_field) from file_name) bobh

          Comment


          • #6
            How to create a sequence number?

            When you say reorg a table, are you mean to reset RRN? Actually I was trying to reset RRN, do you are how?

            Comment


            • #7
              How to create a sequence number?

              I have a SQL User-defined function written in C that may suit your needs. There are three different versions of it. One will start at 1 and increment by 1. The second will start at a value that is passed in and increment by one. The last, will start at the passed in value and increment using the second passed in value. The attached document contains the source and can be ftp'd to your AS/400. All Compile Options/Service Programs/SQL Functions are contained within the source/

              Comment

              Working...
              X