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.


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.


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.


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

About the Author

Sean Mann has been a freelance writer since 2010. With thorough knowledge and experience in technological fields such as computer software, hardware, the internet and programming, he creates online content for various websites. Mann has a Bachelor of Science in computer science from Ohio State University.