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
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 160 of 240    Print  
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?

  
Total Answers and Comments: 7 Last Update: September 06, 2008     Asked by: ddkdhar 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
March 05, 2007 06:55:55   #1  
Nikhil_4_Oracle        

RE: In PL/SQL if we write select statement with INTO c...


hi all

there is no other way for NO_DATA_FOUND and TOO_MANY_ROWS
Exception. Just handle them by using Oracle Exception Handler

i.e
-------------
------------
----------
Exception
when NO_DATA_FOUND then
Dbms_output.put_line('No Record');
---------
-----------
-------------

Regards

Nikhil.

 
Is this answer useful? Yes | No
March 06, 2007 01:08:58   #2  
Nikhil_4_Oracle        

RE: In PL/SQL if we write select statement with INTO c...
HI All

There is no solution for NO_DATA_FOUND else you handle it using Exception block as i

do above...

well TOO_MANY_ROWS is programming fault when
your select query

uses operator then may be there is Too_many_rows exception to avoid this

always use IN operator in u r select Query.


i.e

select empno ename into eid enam from emp

where deptno IN (select deptno from emp where sal>3000);

Thanks

Nikhil.

 
Is this answer useful? Yes | No
March 17, 2007 16:24:45   #3  
mala        

RE: In PL/SQL if we write select statement with INTO c...
Hi All

Yes you can handle Too_Many_Rows exception when you are writing into a PL/SQL block SELECT...INTO statement.


Just write the SELECT...INTO statement in a CURSOR.

Regards.
Mala

 
Is this answer useful? Yes | No
February 05, 2008 15:42:48   #4  
g_sidhu Member Since: August 2007   Contribution: 122    

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?

PL/SQL manages these errors by raising standard exceptions which you can trap in the exception section of the block with the NO_DATA_FOUND and TOO_MANY_ROWS exceptions. Code SELECT statements to return a single row.


 
Is this answer useful? Yes | No
May 08, 2008 06:54:43   #5  
krishnaindia2007 Member Since: September 2007   Contribution: 854    

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?
You may avoid too_many_rows exception using CURSORS.

In cursors if NO_DATA_FOUND then it will not raise any exception. In cursors you need to handle it using FOUND or NOTFOUND cursor attributes.


 
Is this answer useful? Yes | No
July 30, 2008 12:46:05   #6  
binurajnair Member Since: February 2008   Contribution: 15    

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



 
Is this answer useful? Yes | No
September 05, 2008 13:28:22   #7  
vnraos Member Since: April 2008   Contribution: 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.

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape