SQLite - 替换一次字符串的一部分

时间:2015-04-11 10:22:15

标签: sqlite replace

在SQLite中是否可以替换一次字符串的一部分?

例如

UPDATE pages SET path = replace(path, '/page', '/article') WHERE path LIKE '/page/%'"

结果 /page/page1/page2 => /article/article1/article2

但我需要 /page/page1/page2 => /article/page1/page2

2 个答案:

答案 0 :(得分:0)

就像这样:

UPDATE pages SET path = replace(path, '/page/', '/article/') WHERE path LIKE '/page/%'"

答案 1 :(得分:0)

$l1 = strlen($old_path);
$l2 = $l1+1;

UPDATE pages
SET path = replace(
    substr(path, 1, {$l1}),
    '{$old_path}',
    '{$new_path}'
) || substr(path,{$l2})
WHERE path LIKE '{$old_path}/%'

对我有帮助