我有这个行表
RowA
______
ABC123
DEF432
WER677
JKL342
Run Code Online (Sandbox Code Playgroud)
如何在使用oracle的记录之间添加一个'_'?假设添加最后4个字符.
RowA
______
ABC_123
DEF_432
WER_677
JKL_342
Run Code Online (Sandbox Code Playgroud)
你会尝试类似的东西:
Update Table_name set table_column = substr(table_column, 1, 3) || '_' || substr(table_column, 4);
Run Code Online (Sandbox Code Playgroud)
这些SUBSTR函数允许您从字符串中提取子字符串.该SUBSTR函数的语法是:
SUBSTR( string, start_position, [ length ] )
Run Code Online (Sandbox Code Playgroud)
string 是源字符串.
start_position是提取的位置.字符串中的第一个位置始终为1.
length是可选的.它是要提取的字符数.如果省略此参数,SUBSTR函数将返回整个字符串.
另一种方法,使用regexp_replace()正则表达式函数:
select regexp_replace(RowA, '^([[:alpha:]]{3})', '\1_') as res
from your_table
Run Code Online (Sandbox Code Playgroud)
结果:
RES
----------
ABC_123
DEF_432
WER_677
JKL_342
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
32481 次 |
| 最近记录: |