• Oracle-检查数字中有无这符


    方法一 
    返回值为NULL的表示字符串,返回值大于等于1的表示有非数字字符 
    select   lengthb(ltrim( '1248346 ', '0123456789 '))   from   dual; 
    或 
    select   lengthb(rtrim( '1248346a ', '0123456789 '))   from   dual; 

    方法二 
    返回值为NULL的表示字符串,返回值大于等于1的表示有非数字字符 
    select   translate( '123 ', '0123456789 ', ' ')   from   dual 

    方法三 
    如果返回为空指,则全部为数字,反之则含有非数字字符 
    select   lengthb(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace( '0123456789a ', '0 '), '1 '), '2 '), '3 '), '4 '), '5 '), '6 '), '7 '), '8 '), '9 '))   ifnum   from   dual 

    方法四 
    如果是Oracle   10g,可以用正则表达式实现 
    如果返回为0,则表示都是数字,反之,表示有非数字存在 
    SELECT   count( 'a123 ')   FROM   dual   WHERE   REGEXP_LIKE( 'a123 ',   '[^[:digit:]] ') 

    ======================== 
    不建议使用方法三

    select  id  from   ac07_02 where  lengthb(rtrim( id, '0123456789 '))>1; 

  • 相关阅读:
    Study Plan The Twelfth Day
    Study Plan The Fifteenth Day
    Study Plan The Seventeenth Day
    Study Plan The Tenth Day
    Study Plan The Eighth Day
    Study Plan The Eleventh Day
    Study Plan The Sixteenth Day
    Study Plan The Thirteenth Day
    Study Plan The Fourteenth Day
    Study Plan The Ninth Day
  • 原文地址:https://www.cnblogs.com/lzhat/p/4344173.html
Copyright © 2020-2023  润新知