?
Solved

NO_DATA_FOUND

Posted on 2006-06-30
6
Medium Priority
?
367 Views
Last Modified: 2012-06-27
Hi,
This code is a pert of PL/SQL proc

str10i := 'select * from RDR_ODS.period_info  where seriesname='||''''||recpr.rseriesname||''''|| ' and  period='||''''||str9i||''''||' and deleted=''N''';

now what all i want if there is no record retuened thwn do
err_status=true
else err_status=false

The problem is i am using exception to do so.

......
.....
begin
execute  immediate str10i;
 exception
 when NO_DATA_FOUND then
                     
err_status := 'TRUE';
                   
end;
even though returned rows are 0 it doesnot go to exception.
It skips the exception why?
Please respond ASAP
0
Comment
Question by:avi_ny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:sathyagiri
ID: 17021674
Try this
declare a record to store your RDR_ODS output

declare
var1 RDR_ODS.period_info%rowtype;

Then
str10i := 'select col1 from RDR_ODS.period_info  where seriesname='||''''||recpr.rseriesname||''''|| ' and  period='||''''||str9i||''''||' and deleted=''N''';

begin
execute  immediate str10i into var1;
 exception
 when NO_DATA_FOUND then
               
err_status := 'TRUE';
                   
end;




0
 
LVL 14

Accepted Solution

by:
sathyagiri earned 2000 total points
ID: 17021678
Or if you just want to to know if your query returns any thing change it as follows

declare
cnt number;

Then
str10i := 'select count(1) from RDR_ODS.period_info  where seriesname='||''''||recpr.rseriesname||''''|| ' and  period='||''''||str9i||''''||' and deleted=''N''';
execute immediate str10i into cnt;
if (cnt > 0) then // records found
//logic
else
//logic
end if
0
 
LVL 19

Expert Comment

by:actonwang
ID: 17022147
see this:

http://www.experts-exchange.com/Databases/Oracle/Q_21904208.html

I would still recommend to use my pl/sql code as:

declare
_count number;
begin
select count(*) into _count from (select * from <your table> where rownum=1);  
if _count = 0 then
DBMS_OUTPUT.PUT_LINE('no record');
else
DBMS_OUTPUT.PUT_LINE('some record');
end if;
end;
/
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 19

Expert Comment

by:actonwang
ID: 17022154
for your case, it would be:
//////////////////////////////////////////////////////////

declare
   _count number;

.....

str10i := 'select * from RDR_ODS.period_info  where seriesname='||''''||recpr.rseriesname||''''|| ' and  period='||''''||str9i||''''||' and deleted=''N''';

execute immediate ' select count(*) from ('||str10i || ' and rownum =1)' into _count;

if _count = 0 then
  err_status := 'TRUE';
else
   err_status := 'FALSE';
end if;

....
0
 
LVL 19

Expert Comment

by:actonwang
ID: 17022157
it would be lot faster if your query return a lot of records.
Also notice I didn't change your original str10i and I am ONLY using a subquery so you don't need to modify your original query.

Acton
0
 

Author Comment

by:avi_ny
ID: 17023481
Hi Satayagri,
Thanks.
You saved the weekend.
it worked.
But still I wonder why doesn't my concept worked.
After all  count 0 means NO_DATA_FOUND exception. Well send me if you got something.
Thanks .
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question