sqlite的sql语句中使用字符串操作

版权声明: https://blog.csdn.net/henysugar/article/details/83099172

sqlite的字符串操作有:substr,replace等等。

本文通过replace的使用例子演示一下大概怎么使用。

官网上是这么说的:


replace(X,Y,Z)

The replace(X,Y,Z) function returns a string formed by 
substituting string Z for every occurrence of string Y 
in string X. The BINARY collating sequence is used for 
comparisons. If Y is an empty string then return X unchanged. 
If Z is not initially a string, it is cast to a UTF-8 string 
prior to processing. 

意思是XXXXX,就不翻译了,

官网的X,Y,Z不宜阅读不好理解,如果修改成replace(sourceStr,substr,newstr),估计可以为大家节省不少时间!

直接看代码:

"UPDATE testtable SET filename=replace(filename,'.JPG','.GIF')"

代码的意思是,把文件名中的“.JPG”都替换为".GIF"。

更多的其它字符串操作函数,请参考sqlite官网的介绍:https://www.sqlite.org/lang_corefunc.html 。

猜你喜欢

转载自blog.csdn.net/henysugar/article/details/83099172