GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Oracle  >  PL/SQL

 Print  |  
Question:  In PL/SQL if we write select statement with INTO clause it may return two exceptions NO_DATA_FOUND or TOO_MANY_ROW . To do you avoid these execeptions. How do you write SQL statement in alternative way?



September 09, 2008 13:28:22 #7
 vnraos   Member Since: April 2008    Total Comments: 3 

In PL/SQL if we write select statement with INTO clause it may return two exceptions NO_DATA_FOUND or TOO_MANY_ROW . To do you avoid these execeptions. How do you write SQL statement in alternative way?
 
First, let us understand why these errors cropup.

1) NO_DATA_FOUND - is raised only for "select into" statements when  the where clause of the query does not match any rows.

2)TOO_MANY_rows - is raised if a "select into" statement matches more than one row.

Solution for 1 - In the exception section use a handler like this "when no_data_found then insert into log_error ('no matching data')".

for 2) - This is a result of poor design or programming. One need to use a cursor.
     

 

Back To Question