Help in solving this pl/sql block

Hi
Could some one help me in solving my problem
i want some data to be extracted by a sql its not fetching it so i prefered to write a pl/sql block for it ...
the block is as follows
begin
cursor opunit is
select code from fmg_operating_units;
cursor pak_code is --- those are the 3 codes which i require
select 'BNL' from dual
union select 'HNA' from dual
union select 'HNL' from dual;
cursor data1(opunit,pak_code) is
select mas.name ,
cl.id ,
opup.oun_code ,
fmg_phone_no(mas.id),
clpk.pak_code ,
clpk.id
from fmg_op_unit_positions opup,
fmg_clients cl,
fmg_client_paks clpk,
fmg_masters mas,
fmg_policies po,
fmg_policy_items pi
where mas.id=cl.mas_id
and cl.id=clpk.cli_id
and clpk.oup_id=opup.id
and opup.oun_code = opunit
and clpk.id=po.ctp_id
and po.id=pi.pol_id
and pi.current_status='AC'
and clpk.pak_code = pak_code;
loop opunits
loop pak_code
open data1
fetch data1(opunit,pak_code) ;
end loop;
end loop;
could some one help me in extracting the data and put it on the CSV file ...
i would be very thank full to you if some one take some time to full fill this task..
thanks in advance

Declare
     cursor opunit is
          select distinct code
          from fmg_operating_units;
     cursor pak_code is --- those are the 3 codes which i require
          select 'BNL' codes from dual
          union
          select 'HNA' codes from dual
          union
          select 'HNL' codes from dual;
     cursor data1(opunit,pak_code) is
          select mas.name ,
               cl.id ,
               opup.oun_code ,
               fmg_phone_no(mas.id),
               clpk.pak_code ,
               clpk.id
          from fmg_op_unit_positions opup,
          fmg_clients cl,
               fmg_client_paks clpk,
               fmg_masters mas,
               fmg_policies po,
               fmg_policy_items pi
          where mas.id     =     cl.mas_id
          and cl.id     =     clpk.cli_id
          and clpk.oup_id =     opup.id
          and opup.oun_code =      opunit
          and clpk.id     =     po.ctp_id
          and po.id     =     pi.pol_id
          and pi.current_status=     'AC'
          and clpk.pak_code =      pak_code;
begin
     FOR opunits IN opunit LOOP
          FOR pak_codes IN pak_code LOOP
               OPEN data1;     
                    fetch data1(opunits.code,pak_codes.codes) ;
                    EXIT WHEN data1%NOTFOUND;
                    < Rest of your code here > -- You can insert processed data into a temp table &
                                   -- extract data from that table afterwards via select statement
                                   -- & saving the data in a .cvs file extension.
               CLOSE data1;
          END LOOP;
     END LOOP;
     <Some more code here if applicable>
EXCEPTION
     <Exception handling code section here>
END;

Similar Messages

Maybe you are looking for

  • Report problem directly in iTunes has been disabled?

    I had understood that it was possible to report a problem on a purchase directly from within iTunes, by going to my account, history then selcting the ourchase that had the problem. However the "Report a Problem"link now just boots me off to the Appl

  • Where should I keep my music?

    I have an external drive with most of all of my music on it and some of that music is actually on the hard drive. I just ripped a bunch of cd's to my external drive and put them in my library and numerous songs have the ! so I locate them, when I sea

  • Level of profit centers

    Hi All Could you please tell at what level ( level 5 or level 9 ) are the profit centers maintained in SAP. For example how to find the level of FRBs in the table BSIS. Also if anybody can explain me the concept of cost centers, profit centers and co

  • How many computers can I put CS5 Production Premium on?

    How many computer can I put CS5 Production Premium on if I were to buy it for my company?

  • Elements 12 upgrade

    Hi I have elements 8 installed on my old PC can I buy elements 12 upgrade and load it onto my new PC or do I have to buy the full version of elements 12