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

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: Yesterday @ 5:26 PM
Points: 34, Visits: 164
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: Today @ 5:01 AM
Points: 1,014, Visits: 2,113
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 @ 12:14 AM
Points: 36,735, Visits: 31,186
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 Yesterday @ 5:37 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 5:26 PM
Points: 34, Visits: 164
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 Yesterday @ 5:39 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Yesterday @ 5:26 PM
Points: 34, Visits: 164
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 Yesterday @ 6:46 PM


SSC-Insane

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

Group: General Forum Members
Last Login: Yesterday @ 8:50 PM
Points: 23,003, Visits: 31,495
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
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse