plsql - PL/SQL garbage value cleaning -
a table contains millions of records in there 12 critical columns contain garbage values. not records in these 12 columns garbage. there records fine while others garbage.
so want write pl/sql script clean these garbage values without using update statement 12 times. have code written doesn't seem work cause. suggestions modify code or change code entirely welcome. suppose dynamic sql used here don't have knowledge of ever , i'm short on time.
set serveroutput on declare count_total number := 0; number :=0; ch varchar2(10); ch2 varchar2(10); cursor cursor_sim_b select a1, a2, a3, a4, a5, a6, b1, b2, b3, b4, b5, b6, -- identify trim(translate(a1,'0123456789',' ')) a_1, -- garbage values trim(translate(a2,'0123456789',' ')) a_2, trim(translate(a3,'0123456789',' ')) a_3, trim(translate(a4,'0123456789',' ')) a_4, trim(translate(a5,'0123456789',' ')) a_5, trim(translate(a6,'0123456789',' ')) a_6, trim(translate(b1,'0123456789',' ')) b_1, trim(translate(b2,'0123456789',' ')) b_2, trim(translate(b3,'0123456789',' ')) b_3, trim(translate(b4,'0123456789',' ')) b_4, trim(translate(b5,'0123456789',' ')) b_5, trim(translate(b6,'0123456789',' ')) b_6 temp_clean; sim_b_rec cursor_sim_b%rowtype; begin dbms_output.put_line('outside cursor '); sim_b_rec in cursor_sim_b loop dbms_output.put_line('outside loop '); in 1..6 loop ch := 'a_' ||i; dbms_output.put_line('inside loop '||ch); if sim_b_rec.ch not null -- error in passing 'ch' cursor -- error says 'ch' not declared begin execute immediate 'update temp_clean set sim_b_rec.ch = null'; exception when others rollback; end; dbms_output.put_line('a'||i||'<' || sim_b_rec.ch || '>'); end if; ch2 := 'b_' ||i; if sim_b_rec.ch2 not null begin execute immediate 'update temp_clean set sim_b_rec.ch2 = null'; exception when others rollback; end; dbms_output.put_line('b'||i||'<'|| sim_b_rec.ch2 || '>'); end if; end loop; end loop; commit; end; /
this not answer. perhaps question op.
i guess way of finding garbage not work. translating every value null
. assuming garbage contains non-numeric.
see below:
select translate('567','0123456789',null), length(translate('567','0123456789',null) ) dual; -- output: null null select translate('abc56','0123456789',null) , length(translate('abc56','0123456789',null) ) dual; -- output: null null select translate('%&12ab','0123456789',null), length(translate('%&12ab','0123456789',null) ) dual; -- output: null null
just make sure translated null
have added length
check.
provide sample valid values , garbage values further
Comments
Post a Comment