Hi Gurus,
I've got a SQL file that needs to be optimized.
Can someone optimize this for me using EXECUTE IMMEDIATE or other means since there are repeated blocks of statements
The code is as follows:
spool c:\h4.lis
declare
cursor
C1 is
select rpad(nam_user,20)nam,cod_cc_brn,cod_user_id,DAT_LAST_SIGN_ON,to_char(TRUNC(SYSDATE-DAT_LAST_SIGN_ON))no_day
from sm_user_profile
where flg_status = 'E'
and to_char(dat_prof_end,'mm/dd/yyyy') = '12/31/2049'
and cod_user_id NOT LIKE 'GU%'
and cod_user_id NOT LIKE 'GS%'
order by cod_cc_brn,cod_user_id;
v_count number:=0;
v_count2 number:=0;
v_cod_user varchar2(36);
v_cod_cc_brn varchar2(3);
v_branch varchar2(150);
v_flag_status CHAR(1);
v_dat_last_sign_on date;
--
begin
for c1_rec in C1 loop
v_flag_status := ' ';
v_cod_user := ' ';
v_cod_cc_brn := ' ';
v_count := 0;
v_branch := ' ';
--
begin
select flg_status,cod_user_id,to_char(cod_cc_brn),dat_last_sign_on
into v_flag_status,v_cod_user,v_cod_cc_brn,v_dat_last_sign_on
from [Email Address Removed] where cod_user_id = c1_rec.cod_user_id
and flg_status = 'E';
v_count := v_count+1;
v_branch := lpad(v_cod_cc_brn,3,0)||' '||to_char(v_dat_last_sign_on,'dd/mm/yy');
exception
when others then null;
end;
begin
select flg_status,cod_user_id,to_char(cod_cc_brn),dat_last_sign_on
into v_flag_status,v_cod_user,v_cod_cc_brn,v_dat_last_sign_on
from [Email Address Removed] where cod_user_id = c1_rec.cod_user_id
and flg_status = 'E';
v_count := v_count+1;
v_branch := ' '||v_branch||' '||lpad(v_cod_cc_brn,3,0)||' '||to_char(v_dat_last_sign_on,'dd/mm/yy');
exception
when others then null;
end;
.
.
.
begin
select flg_status,cod_user_id,to_char(cod_cc_brn),dat_last_sign_on
into v_flag_status,v_cod_user,v_cod_cc_brn,v_dat_last_sign_on
from [Email Address Removed] where cod_user_id = c1_rec.cod_user_id
and flg_status = 'E';
v_count := v_count+1;
v_branch := ' '||v_branch||' '||lpad(v_cod_cc_brn,3,0)||' '||to_char(v_dat_last_sign_on,'dd/mm/yy');
exception
when others then null;
end;
if v_count > 1 then
dbms_output.put_line('Branch Dups '||rpad(v_branch,150)||' '||rpad(c1_rec.cod_user_id,12)||' '||c1_rec.nam);
v_count2 := v_count2 + 1;
end if;
end loop;
dbms_output.put_line('Total Users : '||to_char(v_count2));
dbms_output.put_line('***End***');
end;
/
spool off
Regards,
Patrick
The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission. If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited. If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments. Thank you.
Every effort is made to keep our network free from viruses. You should, however, review this e-mail message, as well as any attachment thereto, for viruses. We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message.
Oracle LazyDBA home page