Rowid: ROWID Is A Pseudo-Column Which Will Be Present For Every Table in Oracle
Rowid: ROWID Is A Pseudo-Column Which Will Be Present For Every Table in Oracle
For each row in the database, the ROWID pseudo-column returns the address of the row. Oracle
Database rowid values contain information necessary to locate a row:
Usually, a rowid value uniquely identifies a row in the database. Values of the ROWID pseudo-
column have the datatype ROWID
NOTE:
2. we can use the ROWID pseudo-column in the SELECT and WHERE clause of a query, these
pseudo-column values are not actually stored in the database. You cannot insert, update, or
delete a value of the ROWID pseudo-column.
EXAMPLE:
NOTE:
1. We can use the rownum pseudo-column in where clause in-order to limit the number of
records to be selected by a query.
Example:
2. Condition checking for rownum values greater than a positive integer will always return false to
where clause and the query select no record from the table.
Example:
It gives no records.
3. If an order-by clause follows rownum in the same query, then the rows will be reordered
by the order-by clause after assigning rownum.
select rownum,ename,sal
from emp
order by sal;
Queries on Rownum:
Select *
From emp
Where rownum <=&N ;
Select *
From emp
Where rownum <=( select count(*)/2 from emp);
Select *
From emp
Where rownum <= &N
Minus
Select *
From emp
Where rownum < &N ;
4. To display bottom N records from the table.
Select *
From emp
Minus
Select *
From emp
Where rownum <= (select count(*) - &N from emp) ;
Example : 1. To obtain details of employee who earn 1st max salary in emp table.
Select *
From emp
Where sal in (Select sal
From ( select distinct sal from emp where sal is not null order by sal desc)
Where rownum = 1);
2. To obtain details of employee who earn 2nd max salary in emp table.
Select *
from emp
where sal in (Select sal
From ( select distinct sal from emp where sal is not null order by sal desc)
Where rownum <=2
Minus
Select *
From ( select distinct sal from emp where sal is not null order by sal desc)
Where rownum <2);
Therefore, the query to display employee details who earn Nth max salary.
Select *
from emp
where sal in (Select sal
From ( select distinct sal from emp where sal is not null order by sal desc)
Where rownum <=&N
Minus
Select *
From ( select distinct sal from emp where sal is not null order by sal desc)
Where rownum <N);
Therefore, the query to display employee details who earn Nth max salary.
Select *
from emp
where sal in (Select sal
From ( select distinct sal from emp where sal is not null order by sal asc)
Where rownum <=&N
Minus
Select *
From ( select distinct sal from emp where sal is not null order by sal asc)
Where rownum <&N);