2013-03-16 20 views

回答

0
select concat_ws('-', 
    left(a, 1), 
    substring(a from 2 for 2), 
    substring(a from 4 for 3), 
    substring(a from 7 for 2), 
    substring(a from 9 for 1), 
    right(a, 3) 
) 
from (values ('abcd1234efgh')) s(a) 

concat_ws函數將使用其第一個參數作爲分隔符。

1

使用一個regexp_replace()電話:

SELECT regexp_replace('abcd1234efgh' 
        ,'^(.)(..)(...)(..)(.)(...)' 
        ,'\1-\2-\3-\4-\5-\6' 
        ) 

可生產請求的結果。

同樣用數字寫:

SELECT regexp_replace('abcd1234efgh' 
        ,'^(.{1})(.{2})(.{3})(.{2})(.{1})(.{3})' 
        ,'\1-\2-\3-\4-\5-\6' 
        ) 
相關問題