您可以在“ information_schema.columns”的帮助下获取MySQL表列数据类型。
语法如下-
SELECT DATA_TYPE from INFORMATION_SCHEMA.COLUMNS where table_schema = ’yourDatabaseName’ and table_name = ’yourTableName’.
要了解上述语法,让我们首先创建一个表-
mysql> create table DataTypeDemo −> ( −> Id int, −> Address varchar(200), −> Money decimal(10,4) −> );
应用以上语法获取MySQL列数据类型。查询如下-
mysql> select data_type from information_schema.columns where table_schema = 'business' and able_name = 'DataTypeDemo';
以下是输出-
+-----------+ | DATA_TYPE | +-----------+ | int | | varchar | | decimal | +-----------+ 3 rows in set (0.00 sec)
如果需要,请在数据类型之前的输出中也包括列名称。查询如下-
mysql> select column_name,data_type from information_schema.columns where table_schema = 'business' and table_name = 'DataTypeDemo';
以下输出显示与数据类型相对应的列名称-
+-------------+-----------+ | COLUMN_NAME | DATA_TYPE | +-------------+-----------+ | Id | int | | Address | varchar | | Money | decimal | +-------------+-----------+ 3 rows in set (0.00 sec)