UPDATE Mytable t
SET column = SUBSTR(t.U_MSG, 1, LENGTH(t.U_MSG)-15)
-- ^^
-- length of the replaced string
-- hard coded in this example, should
-- probably use `LENGTH(...)` for ease
-- of maintenance in production code
WITH t AS (
SELECT 'PLEASE, CALL HELPDESK' U_MSG FROM DUAL
UNION ALL SELECT 'CALL HELPDESK, CALL HELPDESK! THEY SAID, CALL HELPDESK' FROM DUAL
)
SELECT SUBSTR(t.U_MSG, 1, LENGTH(t.U_MSG)-15) || ' CALL HELP DESK' MSG FROM t;
生产:
MSG
------------------------------------------------------
PLEASE CALL HELP DESK
CALL HELPDESK, CALL HELPDESK! THEY SAID CALL HELP DESK
3条答案
按热度按时间fykwrbwg1#
REPLACE
不使用通配符,它只是用第二个字符串替换第一个字符串的所有示例。flvlnr442#
考虑用而不是替换ALL逗号。
其他,简单
注意,它也删除逗号后面的所有空格。
ohfgkhjo3#
由于替换的字符串是 fixed,为什么不简单地使用:
这可能没有其他解决方案聪明,但即使由于意外的命运转折,被替换的字符串在某些字符串中出现了几次,这也会起作用:
生产: