发布于 2017-03-17 21:08:55 | 142 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Oracle关系数据库管理系统

Oracle Database,又名Oracle RDBMS,或简称Oracle。是甲骨文公司的一款关系数据库管理系统。到目前仍在数据库市场上占有主要份额。


本文给大家分享Oracle删除字段中的空格、回车及指定字符的实例代码,非常不错,具有参考借鉴价值,需要的的朋友参考下

废话不多说了,直接给大家贴代码了,具体代码如下所示:


create or replace procedure PROC_test is
 --Description:删除字段中的指定字符(回车chr(13)、换行chr(10))
 --By LiChao
 --Date:2016-03-01
 colname varchar(20); --列名
 cnt   number; --包含换行符的列的行数
 v_sql  varchar(2000); --动态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;
  --替换回车符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删除字段中的空格、回车及指定字符的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对PHPERZ网站的支持!



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务