Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Error when selecting top N records from oracle Expand / Collapse
Author
Message
Posted Monday, July 14, 2014 6:10 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 9, 2014 6:00 PM
Points: 35, Visits: 170
I am writing a large select statement in MS SQL to select data from linked Oracle 11g server.
Started with this
e.g.
Select top 100 * from
table1
left outer join table2 on table1.id = table2.id
left outer join table3 on table1.id = table3.id

I get the following error

OraOLEDB.Oracle" for linked server "BIS" returned message "ORA-01403: no data found

if i remove one table or if i remove the "top 100" clause it works.

since i am building a rather large select with many left outer joins i'd like to limit the data i retrieve.

Does anyone know what is causing the top 100 to behave like this and what the workaround is ?



Post #1592383
Posted Monday, July 21, 2014 7:55 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 11:17 AM
Points: 1,116, Visits: 2,389
Oracle code uses: "rownum < 100". It does not use TOP command.

Ex: Select * from 'table1' where rownum < 100;
Post #1594600
Posted Monday, July 21, 2014 9:02 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 1:31 PM
Points: 35,372, Visits: 31,918
I'm also pretty sure that, even across a linked server, Oracle defaults to being case-sensitive for all things like table names, column names, etc, ad infinitum (just to cover the next possible error that I see coming up).


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1594639
Posted Thursday, July 24, 2014 5:37 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 9, 2014 6:00 PM
Points: 35, Visits: 170
I'm calling the data through linked tables from SQL2008.
The method 'rownum' is not a SQL term.

If you try to use it in a select statement of data on SQL2008 to retrieve data from Oracle you get this error
Msg 207, Level 16, State 1, Line 3
Invalid column name 'rownum'.

Top n will work on one table

If i do this

select top n 3 from table1

I get 3 rows.
It's only when i start to join the tables and then do a top n that Oracle or the intermediare between SQL and Oracle starts to produce errors



Post #1596047
Posted Thursday, July 24, 2014 5:39 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 9, 2014 6:00 PM
Points: 35, Visits: 170
it's not a syntax or case error.

I dont' change the top select part of the statement.
I simply comment out the last table and the statement works.

As soon as i include more than two tables in a join and use a top n , Oracle returns an error.



Post #1596048
Posted Thursday, July 24, 2014 6:46 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 10:17 AM
Points: 20,739, Visits: 32,524
edit: Never mind, reread the post and saw that if the TOP 100 was removed the query ran.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1596059
Posted Friday, July 25, 2014 9:47 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 10:17 AM
Points: 20,739, Visits: 32,524
Okay, I still have to ask. Are you sure there is data in all three tables?



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1596293
Posted Sunday, July 27, 2014 4:52 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, October 9, 2014 6:00 PM
Points: 35, Visits: 170
Yes.
If i replace the top n with select * and leave the rest of the script the same I get a lot of records back.
The error exist only if i have more than a few tables in the join and use top n
Take top n out and i can join on as many tables as i want.



Post #1596601
Posted Sunday, July 27, 2014 4:58 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 3:13 PM
Points: 6,842, Visits: 13,364
Are all the tables used in the Join located at the Orcle server?
If so, I recommend to change it to a remote Query (at least for all tables located at the Oracle server).
In that remote query yo should use ROWNUM<100 again, since it'll be executed using Oracle syntax.




Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
Post #1596603
Posted Monday, July 28, 2014 12:47 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, October 22, 2014 1:30 AM
Points: 7, Visits: 91
Have you tried this?

Select top 100 * from (
select * from table1
left outer join table2 on table1.id = table2.id
left outer join table3 on table1.id = table3.id
)

Also be notified that rownum < 100 returns 99 rows only. Use rownum <= 100.
Post #1596695
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse