Solved

NO_DATA_FOUND

Posted on 2006-06-30
6
364 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
  • 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 500 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle- set role and grant privileges 6 49
Help on model clause 5 47
create a nested synonym 4 40
Creation date for a PDB 5 60
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

679 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