Link to home
Start Free TrialLog in
Avatar of slim7
slim7

asked on

Rownum and Order by

We have a nightly batch process that sqlldr records into a staging table.  When we process the file, we break up the file into chunks i.e. 1000 records at a time.  so our query looks like 'select * from stg where rownum < 1000 order by account_number'.
On occasion the process will skip rows, i.e. it will process 1-150, skip 50 records, and then continue 200-999.  What causes this?
ASKER CERTIFIED SOLUTION
Avatar of catchmeifuwant
catchmeifuwant

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of plamen73
plamen73

thw wrong place of the rownum. rownum is assigned by oracle just before prder by clause to be handled.
so, rewrite the query:

------------------------------------------
select * from
(
  select * from stg where order by account_number
)stg_ordered
where rownum < 1000;
------------------------------------------