How to Convert SQLite to Text

By Sean Mann

Converting a value into the "TEXT" data type in SQLite is helpful when you want to make sure the data isn't accidentally treated as an integer or some other data type. Unlike most SQL database engines, SQLite uses a dynamic type system, which allows data to move between data types more easily. To convert data in an SQLite query to the "TEXT" type, you need to utilize the "CAST" expression, which explicitly defines a data type to use.

Step 1

Load a SQLite database and enter the sqlite3 environment by typing the following text at the command prompt:

$ sqlite3 mydb.db

Replace "mydb.db" with the name of your database. A database with the specified name will be created if none already exists.

Step 2

Convert a value to the TEXT data type with the "CAST" expression by typing the following command at the command prompt:

$ sqlite3 my_db.db INSERT INTO my_table VALUES(CAST(97 AS TEXT))

Replace "my_table" with the name of your table. In the code, the number 97 is inserted into the table as a TEXT value.

Step 3

Exit the sqlite3 environment by typing ".quit", ".q" or ".exit." and pressing the "Enter" key.

×