2013-05-30 83 views
0
select regexp_replace((select regexp_substr(reference_number, '[^|]+', 1, level), 
         reference_number 
         from ups_ship1 
         connect by regexp_substr(reference_number, '[^|]+', 1, level) 
          is not null), '(\D+)', '') 
from ups_ship1; 

回答

1

很難說沒有任何數據,但根據您剛纔的問題和Ben's answer,你傳遞兩列(您計算的提取值和原始管道分隔的字符串)轉換爲regexp_replace - 它給出了ORA-00913 - 而regexp_substr()返回了多行,這也是錯誤的。

我想你想要這樣的:

select reference_number, regexp_replace(val, '(\D+)', '') 
from (
    select regexp_substr(reference_number, '[^|]+', 1, level) val, 
     reference_number 
     from ups_ship1 
     connect by regexp_substr(reference_number, '[^|]+', 1, level) is not null 
); 

SQL Fiddle based on your previous question's sample data,雖然不具備觸發替換任何數據。

2

這很難理解您要做什麼,但是無法發送返回多行的子查詢的結果(使用2列)作爲regexp_replace的第一個參數。

您可以在子查詢的FROM子句這樣的:

select regexp_replace(rn, '(\D+)', '') 
from (select regexp_substr(reference_number, '[^|]+', 1, level) rn, 
         reference_number 
         from ups_ship1 
         connect by regexp_substr(reference_number, '[^|]+', 1, level) 
          is not null) up; 

Here is a sqlfiddle demo

相關問題