2017-02-05 98 views
1

我想獲取從下面的圖案的第一特殊字符如何使用特殊字符作爲分隔符在oracle中grep字符串?

SQL> select distinct cell_name from v$cell_state; 

CELL_NAME 
-------------------------------------------------------------------------------- 
10.160.0.39;10.160.0.40 
10.160.0.41;10.160.0.42 
10.160.0.43;10.160.0.44 
10.160.0.45;10.160.0.46 
10.160.0.47;10.160.0.48 
10.160.0.49;10.160.0.50 
10.160.0.51;10.160.0.52 

expected output: 
10.160.0.39 
10.160.0.41 
10.160.0.43 
10.160.0.45 
10.160.0.47 
10.160.0.49 
10.160.0.51 

SQL> select distinct cell_name from v$cell_state; 

CELL_NAME 
-------------------------------------------------------------------------------- 
10.160.0.39,10.160.0.40 
10.160.0.41,10.160.0.42 
10.160.0.43,10.160.0.44 
10.160.0.45,10.160.0.46 
10.160.0.47,10.160.0.48 
10.160.0.49,10.160.0.50 
10.160.0.51,10.160.0.52 

expected output: 
10.160.0.39 
10.160.0.41 
10.160.0.43 
10.160.0.45 
10.160.0.47 
10.160.0.49 
10.160.0.51 

SQL> select distinct cell_name from v$cell_state; 

CELL_NAME 
-------------------------------------------------------------------------------- 
190.160.14.3 
190.160.14.4 
190.160.14.5 
190.160.14.8 
190.160.14.9 

expected output: 
190.160.14.3 
190.160.14.4 
190.160.14.5 
190.160.14.8 
190.160.14.9 

我想編寫一個查詢來實現它獲取的IP在所有上述3個方案是,即使沒有特別的前結束該IP地址字符,那麼就應該取現有的IP輸出

回答

1

[^;, ]任何包機比;,
*任意數量出現其他

select distinct 
     regexp_substr(cell_name,'[^;, ]*') 

from v$cell_state 
; 

演示

select regexp_substr('10.160.0.39;10.160.0.40' ,'[^;, ]*') 
     ,regexp_substr('10.160.0.39,10.160.0.40' ,'[^;, ]*') 
     ,regexp_substr('10.160.0.39'    ,'[^;, ]*') 

from dual 
; 
+0

嗨嘟嘟,super.Could請你解釋一點它是如何獲取即使如果沒有特殊字符 –

+0

確定了它*是關鍵 –

+0

如果我想補充的空間也特殊的字符,然後如何把它放在特殊的char列表中? –

相關問題