?
Solved

SQL to increment number by 1

Posted on 2009-04-02
7
Medium Priority
?
1,158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 40

Assisted Solution

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

select myseq.nextval from dual;
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 40

Accepted Solution

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

Assisted Solution

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

Assisted Solution

by:mrjoltcola
mrjoltcola earned 1400 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to recover a database from a user managed backup
Suggested Courses

771 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