【发布时间】:2021-09-13 07:35:17
【问题描述】:
我想在第三个字符之后添加特殊字符。下面是例子
Current Phone Number:- 123234567
Expected output :- (123)234-567
我该怎么做?
【问题讨论】:
标签: sql oracle special-characters string-concatenation
我想在第三个字符之后添加特殊字符。下面是例子
Current Phone Number:- 123234567
Expected output :- (123)234-567
我该怎么做?
【问题讨论】:
标签: sql oracle special-characters string-concatenation
如您所说,连接以及substr 函数:
SQL> with test (col) as
2 (select 123234567 from dual)
3 select '(' || substr(col, 1, 3) || ')' ||substr(col, 4, 3) ||'-'|| substr(col, 7) result
4 from test;
RESULT
------------
(123)234-567
SQL>
或者,使用正则表达式:
SQL> with test (col) as
2 (select 123234567 from dual)
3 select regexp_replace(col, '([0-9]{3})([0-9]{3})', '(\1)\2-') result_2
4 from test;
RESULT_2
------------
(123)234-567
SQL>
【讨论】: