如何在SQLIte中获取子字符串? [英] How to get substring in SQLIte?

查看:441
本文介绍了如何在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 string X 以第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 string X that begins with the Y-th character and which is Z characters long. If Z is omitted then substr(X,Y) returns all characters through the end of the string X beginning with the Y-th. The left-most character of X is number 1. If Y is negative then the first character of the substring is found by counting from the right rather than the left. If Z is negative then the abs(Z) characters preceding the Y-th character are returned. If X is a string then characters indices refer to actual UTF-8 characters. If X is a BLOB then the indices refer to bytes.

这篇关于如何在SQLIte中获取子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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