2013-09-26 67 views
0

我需要在oracle 9i中查找具有varchar2列的行,其中包含文本中的10位數字。查找varchar2列是否包含任何10位數字

例如 「一些字符aftuivhe 7524941842個一些更多的字符」

10位數的數目可以文本內是任意的位置。

+0

確實的替換它們文本包含像@或$等字符 – psaraj12

回答

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 
+3

我開始寫一個'regexp_like'的答案,但問題陳述(不是很清楚!),它是9i的,直到10g才加入。 (雖然你不需要'where子句中的'{10}') –

+0

我的錯誤...將糾正它@AlexPoole感謝您指出我的疏忽 – SriniV

0

嘗試這樣,

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

您可以使用下面的方法如果有任何c其他字符串中的10位數字(a,b,C,&,%,$,#等)。

假設僅存在一個10位的數字並沒有其他numbers.The邏輯是過濾哪些不是數字的字符,然後用空白

的例子與Sql fiddle Link

select translate('etdgdb @# 1234567890 kgmn wwjw', 
'A'||translate('etdgdb @# 1234567890 kgmn wwjw','A1234567890','A') 
,'A') 
from dual; 
相關問題