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 -> SELECT INTO Return > 1 rows

SELECT INTO Return > 1 rows

From: jack <jackIt_at_it.com>
Date: Fri, 10 Jun 2005 14:16:50 +0800
Message-ID: <42a9305a_3@rain.i-cable.com>


I am new to PLSQL. Here is a sample code from a textbook. Is the ELSE checking for 'error > 1 rows' necessary ? As far I know if there are > 1 rows returned in the SELECT INTO, an exception would be raised before we can check if %ROWCOUNT >1.

DECLARE
   v_city zipcode.city%type;
BEGIN
   SELECT city

     INTO v_city
     FROM zipcode

    WHERE zip = 07002;
   IF SQL%ROWCOUNT = 1 THEN
     DBMS_OUTPUT.PUT_LINE(v_city ||' has a '|| 'zipcode of 07002');    ELSIF SQL%ROWCOUNT = 0 THEN
      DBMS_OUTPUT.PUT_LINE('The zipcode 07002 is '|| ' not in the database');

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

   END IF;
END; Received on Fri Jun 10 2005 - 01:16:50 CDT

Original text of this message

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