• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1256
  • Last Modified:

SQL to increment number by 1

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
ewang1205
Asked:
ewang1205
5 Solutions
 
mrjoltcolaCommented:
create sequence myseq start with 1 increment by 1;

select myseq.nextval from dual;
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
in what context to you need this?
please clarify.
0
 
ewang1205Author Commented:
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
mrjoltcolaCommented:
select to_char(myseq.nextval, '000') from dual;
0
 
DavidSenior Oracle Database AdministratorCommented:
Or for a table insertion, ... values( myseq.nextval), col b, ....)
0
 
mrjoltcolaCommented:
Not sure what context you mean by "sql" but your requirement limits your sequence to 000 - 999, thats expected, right?
0
 
ewang1205Author Commented:
Thanks for the solution.  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now