how to use substring function sqlite android

老子叫甜甜 提交于 2020-03-05 21:10:46

问题


suppose I have a table name : TEST, that it has 2 columns ID and CONTENT, like this :

TEST TABLE :

ID ======= CONTENT

0 ======= hello world

now, how can I split CONTENT column from 0 index to 5 index to retrieve just hello word? (at here, ID=> 0) (I just want to use sql, not other functions in others languages );


回答1:


select substr(content, 0, 5) from test



回答2:


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.

The answer to your question is:

select substr(content, 0, 5) from test where id >= 0;



回答3:


Check substr() function in sqlite3 core functions. It will let achieve what you need.

Use it as:

SELECT substr(content, 0, 5) FROM test WHERE id >= 0;


来源:https://stackoverflow.com/questions/25531689/how-to-use-substring-function-sqlite-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!