Monday 8 August 2011

SQL Commands for Retrieving Row Number


Issue:
     To Retrieve the Row Number for a particular record in the database.

Soln:
     Create table temp (name varchar(30));

     insert into temp values('ashok');
     insert into temp values('king');
     insert into temp values('tekken');
     insert into temp values('manik');
     insert into temp values('DayLight');

     ALTER TABLE temp
     ADD rownumber number null;

     UPDATE temp SET rownumber= ROWNUM;

     SELECT rownumber, NAME FROM temp WHERE NAME LIKE 'tekken';

     ALTER TABLE temp DROP COLUMN rownumber;

No comments:

Post a Comment