MAK
MAK

Reputation: 7260

SQLite: Get only character string from text column

I have the following table:

Table: Test1

Text_Column
------------
2021AB022
1A012998F
ZAY
212P09990
1232124
PMP

Expected result is:

Only_text
----------
ZAY
PMP

Try:

SELECT Text_Column AS Only_text
FROM Test1
WHERE Text_Column REGEXP '(A,Z)'

Upvotes: 0

Views: 603

Answers (2)

g_bor
g_bor

Reputation: 1092

I am not sure that this solves your problem, but works for the given example:

SELECT * FROM Test1 WHERE
Text_Column GLOB '*[^0-9]*';

giving back only the columns not containig characters in the range 0-9.

Upvotes: 0

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521259

If your version of SQLite in fact supports REGEXP, then you were on the right track:

SELECT Text_Column AS Only_text
FROM Test1
WHERE Text_Column REGEXP '^[A-Z]+$';

But not all versions of SQLite would ship with REGEXP out of the box. Here is another SO question which discusses other ways to detect a number.

Upvotes: 1

Related Questions