Solved

SQL to increment number by 1

Posted on 2009-04-02
7
1,128 Views
Last Modified: 2012-05-06
I like a simple Oracle SQL like the following so each run I will get a increment number by 1.  Please help.  It can be a sequence or anything you can think of.  Thanks.

select myseq from dual;

001
002
003
...
998
999
0
Comment
Question by:ewang1205
7 Comments
 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 350 total points
ID: 24051892
create sequence myseq start with 1 increment by 1;

select myseq.nextval from dual;
0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 50 total points
ID: 24051896
in what context to you need this?
please clarify.
0
 

Author Comment

by:ewang1205
ID: 24051919
squence number will be 1, 2, 3 not 001, 002,003.  

in what context to you need this?  This is just a SQL.  

Thanks.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 40

Accepted Solution

by:
mrjoltcola earned 350 total points
ID: 24051941
select to_char(myseq.nextval, '000') from dual;
0
 
LVL 23

Assisted Solution

by:David
David earned 100 total points
ID: 24051971
Or for a table insertion, ... values( myseq.nextval), col b, ....)
0
 
LVL 40

Assisted Solution

by:mrjoltcola
mrjoltcola earned 350 total points
ID: 24051995
Not sure what context you mean by "sql" but your requirement limits your sequence to 000 - 999, thats expected, right?
0
 

Author Closing Comment

by:ewang1205
ID: 31565880
Thanks for the solution.  
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to take different types of Oracle backups using RMAN.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question