1

我正在寻找相当于

DESCRIBE USERS;

对于 sql 语句,例如:

SELECT id,name,md5(password) FROM USERS

主要是因为我对返回的数据类型感兴趣。

我该怎么做呢?

4

3 回答 3

0

怎么样:

select column_name,data_type, character_maximum_length, numeric_precision 
from information_schema.columns 
where table_name = 'USERS';
于 2012-05-29T09:27:58.393 回答
0

解决方法:

CREATE TEMPORARY TABLE temp SELECT id,name,md5(password) FROM USERS;
DESCRIBE temp;
DROP TEMPORARY TABLE temp;
于 2012-05-29T09:29:41.083 回答
0

SELECT * FROM INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA = 'schema' and TABLE_NAME = 'table'

返回大量信息。

desc  INFORMATION_SCHEMA.COLUMNS
+--------------------------+---------------------+------+-----+---------+-------+
| Field                    | Type                | Null | Key | Default | Extra |
+--------------------------+---------------------+------+-----+---------+-------+
| TABLE_CATALOG            | varchar(512)        | YES  |     | NULL    |       |
| TABLE_SCHEMA             | varchar(64)         | NO   |     |         |       |
| TABLE_NAME               | varchar(64)         | NO   |     |         |       |
| COLUMN_NAME              | varchar(64)         | NO   |     |         |       |
| ORDINAL_POSITION         | bigint(21) unsigned | NO   |     | 0       |       |
| COLUMN_DEFAULT           | longtext            | YES  |     | NULL    |       |
| IS_NULLABLE              | varchar(3)          | NO   |     |         |       |
| DATA_TYPE                | varchar(64)         | NO   |     |         |       |
| CHARACTER_MAXIMUM_LENGTH | bigint(21) unsigned | YES  |     | NULL    |       |
| CHARACTER_OCTET_LENGTH   | bigint(21) unsigned | YES  |     | NULL    |       |
| NUMERIC_PRECISION        | bigint(21) unsigned | YES  |     | NULL    |       |
| NUMERIC_SCALE            | bigint(21) unsigned | YES  |     | NULL    |       |
| CHARACTER_SET_NAME       | varchar(32)         | YES  |     | NULL    |       |
| COLLATION_NAME           | varchar(32)         | YES  |     | NULL    |       |
| COLUMN_TYPE              | longtext            | NO   |     | NULL    |       |
| COLUMN_KEY               | varchar(3)          | NO   |     |         |       |
| EXTRA                    | varchar(27)         | NO   |     |         |       |
| PRIVILEGES               | varchar(80)         | NO   |     |         |       |
| COLUMN_COMMENT           | varchar(255)        | NO   |     |         |       |
+--------------------------+---------------------+------+-----+---------+-------+
于 2012-05-29T09:34:35.977 回答