如何在SQLIte中获取子字符串? [英] How to get substring in SQLIte?
问题描述
我从SQLite数据库中检索了大量的数据。当检索我将它映射到我的应用程序中的不同视图。在我的表中有一个文本字段,我不想从中获取完整的文本,只是前n个字符。所以如果我的查询是例如:
从文章中选择描述id = '29';
那么如何从描述中获取子字符串?感谢
使用 substr
$ b
从核心功能列表:
substr(X,Y,Z)
Y)
substr(X,Y,Z)
函数返回一个子字符串的输入字符串X
表示
以Y
字符开头,并且Z
个字符。如果Z
是
省略,则substr(X,Y)
返回所有字符b $ b stringX
以第Y个开头。X
的最左边的字符是
number 1.如果Y
子串
通过从右而不是左计数来找到。如果Z
是
negative,则Y之前的
字符是abs(Z)
返回。如果X
是字符串,则字符索引引用实际的
UTF-8字符。如果X
是BLOB,则索引引用字节。
I retrieve quite a lot of data from SQLite database. When retrieving I map it to different views in my application. There is a text field in my table from which I don't want to get the full text, just first n chars. So if my query for example is:
Select description from articles where id='29';
Then how do I get the substring from description? thanks
Use the substr
function.
From the list of core functions:
substr(X,Y,Z)
substr(X,Y)
The
substr(X,Y,Z)
function returns a substring of input stringX
that begins with theY
-th character and which isZ
characters long. IfZ
is omitted thensubstr(X,Y)
returns all characters through the end of the stringX
beginning with the Y-th. The left-most character ofX
is number 1. IfY
is negative then the first character of the substring is found by counting from the right rather than the left. IfZ
is negative then theabs(Z)
characters preceding theY
-th character are returned. IfX
is a string then characters indices refer to actual UTF-8 characters. IfX
is a BLOB then the indices refer to bytes.
这篇关于如何在SQLIte中获取子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!