You are on page 1of 2

http://queforum.

com/oracle/

I have a table with 1 million rows. I want to retrieve Nth (let say 100th) row from the table? How can i ge this using a simple sql query in oracle database?
select * from ( select *, rownum r from table_name ) a WHERE r=100

As an example if you want to select the 10th employee based on the salary, then run the below sql query:
select from ( * select emp_id, salary, rownum r from ( select emp_id, salary from employees order by salary desc ) a )b WHERE r=10

Difference between decode and case statements / functions


The differences between case and decode statements are listed below:

DECODE can work with only scalar values but CASE can work with logical operators, predicates and search-able sub queries. CASE can work as a PL/SQL construct but DECODE is used only in SQL statements.CASE can be used as parameter of a function/procedure. CASE expects data type consistency, DECODE does not. CASE complies with ANSI SQL. DECODE is proprietary to Oracle. CASE executes faster in the optimizer than does DECODE. CASE is a statement while DECODE is a function.

The search-able case statement is similar to the decode function. This is shown below: Code:
Case dept_id when 10 then return_value1 when 20 then return_value2 else return_value3 end Decode(dept_id,10,return_value120,return_value2,return_value3)

You might also like