Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

No data found problem

Posted on 2006-04-07
8
Medium Priority
?
1,436 Views
Last Modified: 2012-06-27
In the following code I am retreiving a value (finished good item) and check to see if a Bill Of Material has the finished good assigned to it. I then want to print that finished good item number to the screen (ultimately insert it into the interface table).

However when it hits an item that isn't in a BOM the query fails with 'no data found'. How do I get around this so it doesn't break on the error but instead drops into the IF statement and prints the record?


OPEN get_fg (bom_v);
         LOOP
         FETCH get_fg INTO fg_v;
               EXIT WHEN get_fg%NOTFOUND;
-- check to see if fg item exists in BOM
               select distinct segment1 into comp_exist_v
               from mtl_system_items_b mtl,APPS.BOM_INVENTORY_COMPONENTS comp,apps.BOM_BILL_OF_MATERIALS bom
               where mtl.inventory_item_id = comp.COMPONENT_ITEM_ID (+)
               and mtl.organization_id = 402
               and comp.bill_sequence_id = bom.bill_sequence_id (+)
               and mtl.segment1 = fg_v;
-- if item is missing from BOM, print to screen              
                         if comp_exist_v != fg_v
                         THEN
                    DBMS_OUTPUT.PUT_LINE(bom_v||'    '||'MISSING: '||fg_v);  
                         end if;
 END LOOP;
CLOSE get_fg;
0
Comment
Question by:feign3
6 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 16404520
OPEN get_fg (bom_v);
        LOOP
        FETCH get_fg INTO fg_v;
              EXIT WHEN get_fg%NOTFOUND;
-- check to see if fg item exists in BOM

         BEGIN
              select distinct segment1 into comp_exist_v
              from mtl_system_items_b mtl,APPS.BOM_INVENTORY_COMPONENTS comp,apps.BOM_BILL_OF_MATERIALS bom
              where mtl.inventory_item_id = comp.COMPONENT_ITEM_ID (+)
              and mtl.organization_id = 402
              and comp.bill_sequence_id = bom.bill_sequence_id (+)
              and mtl.segment1 = fg_v;
       EXCEPTION
          WHEN NO_DATA_FOUND THEN
               -- if item is missing from BOM, print to screen            
               DBMS_OUTPUT.PUT_LINE(bom_v||'    '||'MISSING: '||fg_v);  
       END;
 END LOOP;
CLOSE get_fg;
0
 
LVL 12

Expert Comment

by:catchmeifuwant
ID: 16404527
Have an explicit Error Handler for NO_DATA_FOUND

OPEN get_fg (bom_v);
LOOP

FETCH get_fg
INTO fg_v;

EXIT WHEN get_fg%NOTFOUND;

-- check to see if fg item exists in BOM
begin

select distinct segment1
into comp_exist_v
from mtl_system_items_b mtl,APPS.BOM_INVENTORY_COMPONENTS comp,apps.BOM_BILL_OF_MATERIALS bom
where mtl.inventory_item_id = comp.COMPONENT_ITEM_ID (+)
and mtl.organization_id = 402
and comp.bill_sequence_id = bom.bill_sequence_id (+)
and mtl.segment1 = fg_v;

exception
when no_data_found then
comp_exists_v := 'Dummy Value';  -------------- Assign some dummay value or do your printing here etc..
end;

-- if item is missing from BOM, print to screen            
if comp_exist_v != fg_v
THEN
DBMS_OUTPUT.PUT_LINE(bom_v||'    '||'MISSING: '||fg_v);  
end if;

END LOOP;
CLOSE get_fg;
0
 

Author Comment

by:feign3
ID: 16405238
Hmmm, I tried an exception within the loop but it threw an error when I tried executing it. I'll try it again... maybe my placement was wrong.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16406168
>Hmmm, I tried an exception within the loop but it threw an error when I tried executing it.

which error?

OPEN get_fg (bom_v);
        LOOP
        FETCH get_fg INTO fg_v;
              EXIT WHEN get_fg%NOTFOUND;
-- check to see if fg item exists in BOM

         BEGIN
              select distinct segment1 into comp_exist_v
              from mtl_system_items_b mtl,APPS.BOM_INVENTORY_COMPONENTS comp,apps.BOM_BILL_OF_MATERIALS bom
              where mtl.inventory_item_id = comp.COMPONENT_ITEM_ID (+)
              and mtl.organization_id = 402
              and comp.bill_sequence_id = bom.bill_sequence_id (+)
              and mtl.segment1 = fg_v;
       EXCEPTION
          WHEN NO_DATA_FOUND THEN
               -- if item is missing from BOM, print to screen            
               DBMS_OUTPUT.PUT_LINE(bom_v||'    '||'MISSING: '||fg_v);  

          WHEN OTHERS THEN
               -- some other error:
               v_error := SQLERRM;
               DBMS_OUTPUT.PUT_LINE(v_error);  
       END;
 END LOOP;
CLOSE get_fg;
0
 
LVL 4

Expert Comment

by:Harish_Rajani
ID: 16406781
Catch the exception 'WHEN NO DATA FOUND' and have an IF statement in the exception block.


OPEN get_fg (bom_v);
        LOOP
        FETCH get_fg INTO fg_v;
              EXIT WHEN get_fg%NOTFOUND;
-- check to see if fg item exists in BOM
              select distinct segment1 into comp_exist_v
              from mtl_system_items_b mtl,APPS.BOM_INVENTORY_COMPONENTS comp,apps.BOM_BILL_OF_MATERIALS bom
              where mtl.inventory_item_id = comp.COMPONENT_ITEM_ID (+)
              and mtl.organization_id = 402
              and comp.bill_sequence_id = bom.bill_sequence_id (+)
              and mtl.segment1 = fg_v;
-- if item is missing from BOM, print to screen            
               EXCEPTION WHEN NO DATAFOUND THEN
                         if comp_exist_v != fg_v
                         THEN
                   DBMS_OUTPUT.PUT_LINE(bom_v||'    '||'MISSING: '||fg_v);  
                         end if;
                END LOOP;
               END;
-- if there is no exception even then if should execute.
  if comp_exist_v != fg_v
                         THEN
                   DBMS_OUTPUT.PUT_LINE(bom_v||'    '||'MISSING: '||fg_v);  
                         end if;
               


 END LOOP;
CLOSE get_fg;


Rgds,
HR
0
 
LVL 16

Expert Comment

by:MohanKNair
ID: 16814705

OPEN get_fg (bom_v);
        LOOP
        FETCH get_fg INTO fg_v;
EXIT WHEN get_fg%NOTFOUND;
-- check to see if fg item exists in BOM
for c11 IN(select distinct segment1 from mtl_system_items_b mtl,APPS.BOM_INVENTORY_COMPONENTS comp,apps.BOM_BILL_OF_MATERIALS bom
where mtl.inventory_item_id = comp.COMPONENT_ITEM_ID (+) and mtl.organization_id = 402 and comp.bill_sequence_id = bom.bill_sequence_id (+) and mtl.segment1 = fg_v)
LOOP
-- if item is missing from BOM, print to screen            
           if c11.segment1 != fg_v
           THEN
     DBMS_OUTPUT.PUT_LINE(bom_v||'    '||'MISSING: '||fg_v);  
           end if;
      END LOOP;
 END LOOP;
CLOSE get_fg;
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
Suggested Courses

564 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