我有一个像这样的字符串:
2068414199308820683392068279206867820687022068646
我想在每个第七位后插入逗号符号。
我该怎么做?
所需的输出如下:
Output
======
2068414,1993088,2068339,2068279,2068678,2068702,2068646
答案 0 :(得分:5)
作为其中一种方法(Oracle 10g及更高版本),您可以使用regexp_replace()正则表达式函数来获得所需的结果:
SQL> with t1(col) as(
2 select '2068414199308820683392068279206867820687022068646' from dual
3 )
4 select rtrim(regexp_replace(col, '([[:digit:]]{7})', '\1,'), ',') as res
5 from t1
6 ;
结果:
res
-------------------------------------------------------
2068414,1993088,2068339,2068279,2068678,2068702,2068646
如何将此值更新为表客户
update your_table_name
set col_name = rtrim( regexp_replace( col_name
, '([[:digit:]]{7})'
, '\1,')
, ',' )
-- where clause if needed