Asked 7 years ago
27 Jan 2017
Views 4462
sandip

sandip posted

typeof function in MySQL

i got that typeof function in SQLite
SQLite official site says ::
The typeof(X) function returns a string that indicates the datatype of the expression X: "null", "integer", "real", "text", or "blob".

select typeof(name) from employee

it will return type of column, which is "text" in our case

is MySQL have typeof function .so we can get type of column ? if no , than which are the alternative function in MySQL for typeof() ?

Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

is MySQL have typeof function ? -- No MySQL dont have such function which return column data type

But By Query we can achieve it

study following Query ::

SELECT DATA_TYPE FROM  information_schema .`COLUMNS` WHERE TABLE_SCHEMA='wp_database' AND TABLE_NAME='wdp_postmeta' and COLUMN_NAME='meta_value'

information_schema is database which store metadata about the all databases
so information_schema has COLUMNS table which have schema for all columns
so at column table we need to filter our column by its database --> table --> column
so
COLUMNS table have column like
TABLE_SCHEMA which have database name
TABLE_NAME which have table name
COLUMN_NAME which have column name

so we can write filter query in where like this

WHERE TABLE_SCHEMA='databasename' AND TABLE_NAME='tablename' and COLUMN_NAME='column name'


and COLUMNS have column DATA_TYPE which have data type of that column

so our needed Query is

SELECT DATA_TYPE FROM  information_schema .`COLUMNS` WHERE TABLE_SCHEMA='wp_database' AND TABLE_NAME='wdp_postmeta' and COLUMN_NAME='meta_value'


information_schema(database) >> COLUMNS (table)
have 19 column which store differ characteristic of every table 's columns


Post Answer