我从SQLite数据库中检索了大量数据.检索时,我将其映射到我的应用程序中的不同视图.我的表格中有一个文本字段,我不希望得到全文,只有前n个字符.所以如果我的查询例如是:
Select description from articles where id='29';
Run Code Online (Sandbox Code Playgroud)
那么如何从描述中获取子字符串?谢谢
Enz*_*kie 16
您可以在SQLite中使用内置函数substr(X,Y,Z).x字段表示要切片的字符串输入,y和z字段分别表示使用索引的起点和终点.
===============================
|Database Table : **articles**|
===============================
|id | description |
-------------------------------
|29 | Lorem ipsum domit |
===============================
Run Code Online (Sandbox Code Playgroud)
现在我们将尝试为我们的描述进行选择查询
SELECT substr(description,1,4) FROM articles where id='29';
Run Code Online (Sandbox Code Playgroud)
输出将是:Lore而不是Lorem ipsum domit