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?



July 07, 2008 12:46:05 #6
 binurajnair   Member Since: February 2008    Total Comments: 13 

RE: 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?
 
If you don't want an excpetion to be raised on a SELECT statement, you can avoid executing the statement by having a count just before the SELECT as shown below

SELECT count(rowid)
into v_count
from tables
where conditions.

if(v_count = 1) then
  SELECT column
  into v_column
  from tables
  where conditions;
else
  --Select statement not executed because it will throw exception
  v_column=dummy_value;
end if;

However it is a much better practice to handle these errors using exceptions


     

 

Back To Question