SQL WHERE LIKE with tab

10,324

Solution 1

try

CAST(X'09' AS TEXT)

for the tab character

Solution 2

I'm using DB2, but maybe this solution is something you can use on Sqlite also.

Try using the chr function. I think in ASCII the tab character has value 8. In DB2 the following works

SELECT * FROM table WHERE field LIKE '%' || chr(8) || '%'
Share:
10,324

Related videos on Youtube

Mark
Author by

Mark

Updated on August 16, 2022

Comments

  • Mark
    Mark about 1 year

    Seems like such a simple thing. I need to specify a WHERE criteria with the LIKE operator and include a tab in the expression.

    SELECT * FROM table WHERE field LIKE '%Run1[TAB]%';
    

    I've tried \t, \\t, %t and the char operator.

    I am working in Sqlite.

    Thanks.

  • boes
    boes about 12 years
    My ascii has become a bit rustii
  • Mark
    Mark about 12 years
    So such luck - "Query Error: no such function: chr Unable to execute statement", I do not think sqlite has a char like function
  • Mark
    Mark about 12 years
    Thanks @hatchet, query: SELECT * FROM table WHERE field like '%Run1' || X'09' || '%' does the trick!
  • hatchet - done with SOverflow
    hatchet - done with SOverflow about 12 years
    glad that worked. I knew X'09' was the key, but wasn't sure whether it needed to be cast or not.