如何在Oracle SQL查询中指定第三个字符后的字符



我想在第三个字符后添加特殊字符。以下是示例

Current Phone Number:- 123234567
Expected output     :- (123)234-567

我该怎么做?

正如您所说的连接,以及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>

最新更新