database - 如何在 SQLIte 中获取子字符串?

标签 database sqlite

我从 SQLite 数据库中检索了很多数据。检索时,我将其映射到应用程序中的不同 View 。我的表中有一个文本字段,我不想从中获取全文,只是前 n 个字符。因此,如果我的查询是:

Select description from articles where id='29';

那么如何从描述中获取子字符串呢?谢谢

最佳答案

使用 substr 函数。

来自list of core functions :

substr(X,Y,Z) substr(X,Y) substring(X,Y,Z) substring(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.

substring() is an alias for substr() beginning with SQLite version 3.34.

关于database - 如何在 SQLIte 中获取子字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10413055/

相关文章:

php - 在 WHM/cPanel 服务器上通过 PHP 以编程方式创建数据库

database - Entity Framework : how to create double relationship (1-1 and many-1) with same objects

javascript - Felixge/Node-Mysql 独立连接文件

Python:如何创建 "global object"?

c# - 无法加载 DLL 'SQLite.Interop.dll'

java - 使用数据库中的数据填充 TableView。无法设置行

database - 在 Couchbase 中使用 N1QL 从对象的对象中获取所有唯一键

java - SQLite数据库错误: table has no column name

c - sqlite事务后获取受影响的行数

node.js - 如何通过 nodejs exec 将 .sql 文件导入到 sqlite