Tuesday, August 20, 2024

bulk collect with dbms

 declare

v_first_name varchar2(1000):='Sunny';

t_no     sys.odcinumberlist;

t_fname  sys.odcivarchar2list;

t_lname  sys.odcivarchar2list;

t_rfname sys.odcivarchar2list;

        cursor emp_c

          is

            select  replace(first_name,'Sundar','Sunny') rfirst_name,

                    first_name,

                    last_name,

                    employee_id

              from  jai;

         type emp_typ

           is table of emp_c%rowtype;

         v_data emp_typ;

    begin

        open emp_c;

        fetch emp_c

           bulk collect

           into v_data;

        close emp_c;

        forall i in 1..v_data.last

          update jai

             set first_name=v_data(i).rfirst_name

           where first_name ='Sundar';

     open emp_c;

     fetch emp_c bulk collect into t_rfname,t_fname, t_lname,t_no;

     close emp_c;

  --

       for x in t_no.first .. t_no.last loop

       dbms_output.put_line('Number = '||t_no(x) ||' The First Name = '|| t_fname(x));

     end loop; 

commit;

end;

/

No comments:

Post a Comment