Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Different behavior of Too_many_rows exception in pl/sql betwe

Re: Different behavior of Too_many_rows exception in pl/sql betwe

From: Tommy Wareing <twareing_at_oup.co.uk>
Date: Fri, 22 Jun 2001 02:55:42 -0700
Message-ID: <F001.003335AD.20010622023524@fatcity.com>

On Fri, Jun 22, 2001 at 12:45:34AM -0800, Amar Kumar Padhi wrote:
> if you are looking for one row only, then A and C will do. Since C involves
> a little bit of more coding and A does the same thing, A would be a better
> choice. But if you are coding to trap too many rows, then you should check
> for exceptions, all depends on your requirement.

Unless, of course, the select statement in question has an order by clause. Since rownum is now generated before the ordering is applied, you'll get the first row of the unordered set, and that row will then be sorted. Not good.

>
> rgds
> amar
>
> -----Original Message-----
> Sent: Friday, June 22, 2001 12:36 AM
> To: Multiple recipients of list ORACLE-L
> betwe
>
>
> I have seen code that depends on the 8.1 behavior. It does bring up a
> question I have always wondered about. The question for the internals
> ubergeeks is: which of the following is best to use? (All should have the
> same result, so which one has the best performance and why?)
>
> A)
> declare
> y number;
> begin
> select x into y from z where rownum = 1;
> foo(y);
> end;
>
> B)
> declare
> y number;
> begin
> begin
> select x into y from z;
> exception
> when too_many_rows then null;
> end;
> foo(y);
> end;
>
> C)
> declare
> y number;
> cursor c is
> select x into y from z;
> begin
> open c;
> fetch c into y;
> close c;
> foo(y);
> end;

-- 
Tommy Wareing
Oxford English Dictionary
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Tommy Wareing
  INET: twareing_at_oup.co.uk

Fat City Network Services    -- (858) 538-5051  FAX: (858) 538-5051
San Diego, California        -- Public Internet access / Mailing Lists
--------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
Received on Fri Jun 22 2001 - 04:55:42 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US