查找varchar2列是否包含任何10位数字

时间:2013-09-26 10:10:59

标签: sql oracle oracle9i

我需要在oracle 9i中找到包含varchar2列的行,其中包含文本内部的10位数字。

  

例如“某些角色aftuivhe 7524941842更多角色”

10位数字可以是文本中的任何位置。

3 个答案:

答案 0 :(得分:1)

检查一下:

对于Oracle 9i

WITH TEST
    AS (SELECT
             'some characters aftuivhe 7524941842 some more characters' BRNO
        FROM
             DUAL
        UNION ALL
        SELECT
             'some characters aftuivhe 1234567890 some more 1234567890 characters'
                 BRNO
        FROM
             DUAL
        UNION ALL
        SELECT
             '7524941842 some characters aftuivhe  some more characters'
                 BRNO
        FROM
             DUAL
        UNION ALL
        SELECT
             'characters some characters aftuivhe  some more 7524941842 '
                 BRNO
        FROM
             DUAL)
SELECT
      SUBSTR (
             TRIM (
                   TRANSLATE (
                            BRNO,
                            '0abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ',
                            '0' ) ),
             0,
             10 )
FROM
      TEST

对于Oracle 10G及更高版本

WITH TEST
    AS (SELECT
             'some characters aftuivhe 7524941842 some more characters' BRNO
        FROM
             DUAL
        UNION ALL
        SELECT
             'some characters aftuivhe 1234567890 some more characters' BRNO
        FROM
             DUAL
        UNION ALL
        SELECT
             '7524941842 some characters aftuivhe  some more characters'
                 BRNO
        FROM
             DUAL
        UNION ALL
        SELECT
             'characters some characters aftuivhe  some more 7524941842 '
                 BRNO
        FROM
             DUAL)
SELECT
      REGEXP_SUBSTR ( BRNO,
                   '[[:digit:]]{10}' ) AS RESULT
FROM
      TEST
WHERE
      REGEXP_LIKE ( BRNO,
                 '[[:digit:]]' );


RESULT
7524941842
1234567890
7524941842
7524941842

答案 1 :(得分:0)

试试这个,

SELECT LENGTH(REPLACE(TRANSLATE(lower('aftuivhe 7524941842'),'abcdefghijklmnopqrstuvwxyz',' '),' ',''))
FROM  dual;

答案 2 :(得分:0)

如果字符串中有10位数字(a,b,C,&,%,$,#etc)以外的任何字符,您可以使用以下方法。

假设只有一个十位数而没有其他数字。逻辑是过滤不是数字的字符然后用空白替换它们

Sql fiddle Link

的示例
select  translate('etdgdb @# 1234567890 kgmn wwjw',
'A'||translate('etdgdb @# 1234567890 kgmn wwjw','A1234567890','A')
,'A')
 from dual;