如何在oracle中替换字符串的前三个字符。假设我有100条员工ID记录,我需要在100的30到50之间替换记录的前三个字符。
答案 0 :(得分:1)
假设您要在第30至第50行中将前3个字符替换为abc
(按某些条件排序),然后:
SELECT CASE
WHEN ROWNUM BETWEEN 30 AND 50
THEN 'abc' + SUBSTR( your_column, 4 )
ELSE your_column
END AS replaced_value
FROM (
SELECT *
FROM your_table
ORDER BY <some_criteria>
)
答案 1 :(得分:0)
检查此:
SELECT * FROM ns_words;
mine
mini
mani
nikhil
sugandh
mining
SELECT regexp_replace(a,'(.{3}(.*)$)','abc\2') FROM NS_WORDS;
abce
abci
abci
abchil
abcandh
abcing
对于您的查询,例如:
SELECT regexp_replace(a,'(.{3}(.*)$)','abc\2') FROM NS_WORDS where col2
between 30 and 50;