代码之家  ›  专栏  ›  技术社区  ›  Ângelo Rigo

使用ORACLE查找第五个位置是否为字母而不是数字

  •  0
  • Ângelo Rigo  · 技术社区  · 7 年前

    我如何用甲骨文判断第五个位置是否是字母而不是数字?

    REGEXP_LIKE (table_column, '([abcdefghijklmnopqrstuvxyz])');
    
    4 回复  |  直到 7 年前
        1
  •  1
  •   Littlefoot    7 年前

    也许你更愿意检查第5位是否包含一个数字(这意味着它不是

    为什么?因为“字母”不仅仅是ASCII码;看看我的示例中的第4行-它包含克罗地亚字符,这些字符不在[a-z](或[a-z])之间。

    SQL> with test (col) as
      2    (select 'abc_3def' from dual union all
      3     select 'A435D887' from dual union all
      4     select '!#$%&/()' from dual union all
      5     select 'ASDĐŠŽĆČ' from dual
      6    )
      7  select col,
      8    case when regexp_like(substr(col, 5, 1), '\d+') then 'number'
      9         else 'not a number'
     10    end result
     11  from test;
    
    COL           RESULT
    ------------- ------------
    abc_3def      number
    A435D887      not a number
    !#$%&/()      not a number
    ASDĐŠŽĆČ      not a number
    
    SQL>
    
        2
  •  1
  •   Gary_W    7 年前

    select 'TRUE'
    from dual
    where regexp_like('abcd4fg', '^.{4}[A-Z]', 'i');
    
        3
  •  1
  •   Sentinel    7 年前

    还有另一种方法:

    regexp_like(table_column, '^....[[:alpha:]]')
    

    如果您关心的是字符不是数字,则使用

    not regexp_like(table_column, '^....[[:digit:]]')
    

    not regexp_like(table_column, '^....\d')
    
        4
  •  1
  •   TenG    7 年前

    REGEXP_LIKE (table_column, '^....[a-z]')
    

    或:

    SUBSTR (table_column, 5, 1 ) BETWEEN 'a' AND 'z'