zoukankan      html  css  js  c++  java
  • 查出数字字符字段中非数字字符的记录

    最近,将原来的数字符字段转换为数字时,总报错误:无效数字。

    如何找出其中哪些是非数字字符的记录?比较麻烦的事。下面是用Oracle DB自带的函数translate可以找出来的

    1.创建测试表

    Create Table TestChar(
        ITEM_NUMBER VARCHAR2(20)
    );

    2.手工插入测试记录

    Insert Into TestChar (ITEM_NUMBER) values ('312');
    Insert Into TestChar (ITEM_NUMBER) values ('312');
    Insert Into TestChar (ITEM_NUMBER) values ('4412');
    Insert Into TestChar (ITEM_NUMBER) values ('152');
    Insert Into TestChar (ITEM_NUMBER) values ('162');
    Insert Into TestChar (ITEM_NUMBER) values ('172');
    Insert Into TestChar (ITEM_NUMBER) values ('142');
    Insert Into TestChar (ITEM_NUMBER) values ('142');
    Insert Into TestChar (ITEM_NUMBER) values ('112');
    Insert Into TestChar (ITEM_NUMBER) values ('1d2');
    Insert Into TestChar (ITEM_NUMBER) values ('152');
    Insert Into TestChar (ITEM_NUMBER) values ('125');
    Insert Into TestChar (ITEM_NUMBER) values ('162');
    Insert Into TestChar (ITEM_NUMBER) values ('712');
    Insert Into TestChar (ITEM_NUMBER) values ('A712');
    commit;

    3.妙用Oracle 内置函数Translate找出非数字字符的记录

    select trim(translate(RTRIM(LTRIM(ITEM_NUMBER)), '#0123456789', '#'))
      from TestChar
     Where trim(translate(RTRIM(LTRIM(ITEM_NUMBER)), '#0123456789', '#')) is not null;

  • 相关阅读:
    java.lang.IllegalStateException: Failed to load ApplicationContext
    exit 和 return
    ORA-01031:insufficient privileges
    Errors running buider 'DeploymentBuilder' on project 'HFMS'
    unpack
    :Spring MVC +MyBatis +MySQL 登录查询Demo
    :Spring MVC +MyBatis +MySQL 登录查询Demo
    kill 某个进程
    10053 诊断事件
    11g 搜集直方图导致不走索引
  • 原文地址:https://www.cnblogs.com/zzjhn/p/5130999.html
Copyright © 2011-2022 走看看