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

Home -> Community -> Usenet -> c.d.o.misc -> Re: SELECT INTO Return > 1 rows

Re: SELECT INTO Return > 1 rows

From: Akp <abhishek1999_at_gmail.com>
Date: 9 Jun 2005 23:31:25 -0700
Message-ID: <1118385085.236225.272820@o13g2000cwo.googlegroups.com>


Hi,

Looking at the code that you have supplied, I do not think that "ELSIF SQL%ROWCOUNT = 0 THEN" will also be executed ever. This is because you will get a No_data_found or Too_many_rows exception that needs to be trapped in the exception block. So in nut shell if the SELECT statment is not giving any rows or giving more than one row , the code will nto be able to handle it. A much better way to print the messages will be as stated under.

DECLARE
   v_city zipcode.city%type;
BEGIN
   SELECT city

     INTO v_city
     FROM zipcode
    WHERE zip = 07002;
     DBMS_OUTPUT.PUT_LINE(v_city ||' has a '||    'zipcode of 07002');

EXCEPTION
When Too_Many_Rows then

      DBMS_OUTPUT.PUT_LINE('error > 1 rows'); /*would this be executed at all?*/
When No_Data_Found then

      DBMS_OUTPUT.PUT_LINE('The zipcode 07002 is '|| ' not in the database');
When OTHERS then

      DBMS_OUTPUT.PUT_LINE('Some other erorr'); END;
/ Received on Fri Jun 10 2005 - 01:31:25 CDT

Original text of this message

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