S.M_Emamian
S.M_Emamian

Reputation: 17383

how to use substring function sqlite android

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 );

Upvotes: 0

Views: 2944

Answers (3)

Ronnie Hwang
Ronnie Hwang

Reputation: 61

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;

Upvotes: 1

Diego Torres Milano
Diego Torres Milano

Reputation: 69198

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;

Upvotes: 0

Limeoats
Limeoats

Reputation: 426

select substr(content, 0, 5) from test

Upvotes: 2

Related Questions