廢話不多說(shuō)了,直接給大家貼代碼了,具體代碼如下所示:
create or replace procedure PROC_test is --Description:刪除字段中的指定字符(回車(chē)chr(13)、換行chr(10)) --By LiChao --Date:2016-03-01 colname varchar(20); --列名 cnt number; --包含換行符的列的行數(shù) v_sql varchar(2000); --動(dòng)態(tài)SQL變量 begin --讀取表中的列 for col in (select column_name from user_tab_columns where table_name = 'TEMP') loop colname := col.column_name; --替換換行符chr(10) v_sql := 'select count(1) from temp where instr(' || colname || ',chr(10))>0 '; EXECUTE IMMEDIATE V_SQL into cnt; if cnt > 0 then v_sql := 'update temp set ' || colname || '=trim(replace(' || colname || ',chr(10),''''))' || 'where instr(' || colname || ',chr(10))>0 '; EXECUTE IMMEDIATE V_SQL; commit; end if; --替換回車(chē)符chr(13) v_sql := 'select count(1) from temp where instr(' || colname || ',chr(13))>0 '; EXECUTE IMMEDIATE V_SQL into cnt; if cnt > 0 then v_sql := 'update temp set ' || colname || '=trim(replace(' || colname || ',chr(13),''''))' || 'where instr(' || colname || ',chr(13))>0 '; EXECUTE IMMEDIATE V_SQL; commit; end if; --替換'|' chr(124) 為'*' chr(42) v_sql := 'select count(1) from temp where instr(' || colname || ',chr(124))>0 '; EXECUTE IMMEDIATE V_SQL into cnt; if cnt > 0 then v_sql := 'update temp set ' || colname || '=replace(' || colname || ',chr(124),chr(42))' || 'where instr(' || colname || ',chr(124))>0 '; EXECUTE IMMEDIATE V_SQL; commit; end if; end loop; end PROC_test; /
以上所述是小編給大家介紹的Oracle刪除字段中的空格、回車(chē)及指定字符的實(shí)例代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
標(biāo)簽:遼源 紹興 百色 寧波 海東 自貢 中衛(wèi) 昭通
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Oracle刪除字段中的空格、回車(chē)及指定字符的實(shí)例代碼》,本文關(guān)鍵詞 Oracle,刪除,字段,中的,空格,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。