Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2016
    Posts
    1

    Answered: How to Create db2 Sequence from 000000 to 999999

    Hi,

    I would like to get a sequence no. generated in the range of '000000' to '999999' which can be used by querying the particular sequence.But on creating the sequence and using it,the sequence starts with single digit 1,2,3,4...and so on is there any way by which I could create sequence like 000000 ,000001,000002,000003 ....and so on uptil 999999.

    I am using DB2 Linux x86_64 and DB version is 10.5 FP3

    Any help with be highly appreciated.

    Regards, Ashish

  2. Best Answer
    Posted by mark.b

    "Hi,

    try this:

    Code:
    create sequence myseq start with 0;
    values digits(dec(nextval for myseq, 7));
    "


  3. #2
    Join Date
    Jul 2013
    Location
    Moscow, Russia
    Posts
    666
    Provided Answers: 55
    Hi,

    try this:

    Code:
    create sequence myseq start with 0;
    values digits(dec(nextval for myseq, 7));

  4. #3
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Sequences use numeric data types. Normally those are not displayed with leading zeros. As a work around, you can use the DIGITS function to do that.

    Andy

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •