SQLite - 替换字符串的一部分 [英] SQLite - replace part of a string

查看:58
本文介绍了SQLite - 替换字符串的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 SQLite 表中使用 SQL 来替换部分字符串?

Is it possible using SQL in an SQLite table to replace part of a string?

例如,我有一个表,其中一个字段保存文件的路径.是否可以替换部分字符串,例如

For example, I have a table where one of the fields holds the path to a file. Is it possible to replace parts of the string so that, e.g.

c:\afolder\afilename.bmp

变成

c:\anewfolder\afilename.bmp

?

推荐答案

您可以使用内置的 replace() 函数在查询中执行字符串替换.

You can use the built in replace() function to perform a string replace in a query.

其他字符串操作函数(以及更多)在SQLite核心函数列表

Other string manipulation functions (and more) are detailed in the SQLite core functions list

以下应该为您指明正确的方向.

The following should point you in the right direction.

UPDATE table SET field = replace( field, 'C:\afolder\', 'C:\anewfolder\' ) WHERE field LIKE 'C:\afolder\%';

这篇关于SQLite - 替换字符串的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆