SQL to increment number by 1

Posted on 2009-04-02
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;

Question by:ewang1205
LVL 40

Assisted Solution

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

select myseq.nextval from dual;
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.

Author Comment

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.  

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

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

Assisted Solution

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

Assisted Solution

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?

Author Closing Comment

ID: 31565880
Thanks for the solution.  

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help with Oracle syntax 4 56
oracle query help 18 99
PL/SQL - Leading zeros 7 60
passing parameters to sql script oracle 4 27
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
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.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Via a live example, show how to take different types of Oracle backups using RMAN.

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now