Home » SQL & PL/SQL » SQL & PL/SQL » Counter variables
Counter variables [message #39397] Sun, 14 July 2002 23:34 Go to next message
George V Thomas
Messages: 2
Registered: July 2002
Junior Member
How can i add a counter variable inside a select statement.

Detail
I got a table with some records, while fetching the records using the select statement, i want to add a counter variable, to get the record count
Re: Counter variables [message #39401 is a reply to message #39397] Mon, 15 July 2002 05:06 Go to previous messageGo to next message
Mahesh Rajendran
Messages: 10707
Registered: March 2002
Location: oracleDocoVille
Senior Member
Account Moderator
use rownum
SQL> select rownum,dname from dept;

    ROWNUM DNAME
---------- --------------
         1 ACCOUNTING
         2 RESEARCH
         3 SALES
         4 OPERATIONS
Re: Counter variables [message #39407 is a reply to message #39401] Mon, 15 July 2002 13:38 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
In 8.1.6 and up, you can also use the analytical function row_number():

sql>select dname, row_number() over (order by dname)
  2    from dept;
 
DNAME          ROW_NUMBER()OVER(ORDERBYDNAME)
-------------- ------------------------------
ACCOUNTING                                  1
OPERATIONS                                  2
RESEARCH                                    3
SALES                                       4
Previous Topic: PL/SQL functions and stored procedures
Next Topic: how to read oracle core files
Goto Forum:
  


Current Time: Thu Apr 25 20:04:30 CDT 2024