需求:mysql查询数据库表中所有字段,不想使用*,可使用group_concat拼接,并起别名
select group_concat(‘别名.’,COLUMN_NAME SEPARATOR ‘,’) AS t_info from information_schema.COLUMNS where table_name = ‘表名’;
不要别名
select group_concat(COLUMN_NAME SEPARATOR ‘,’) AS t_info from information_schema.COLUMNS where table_name = ‘表名’;
eg:
select group_concat(‘f.’,COLUMN_NAME SEPARATOR ‘,’) AS t_info from information_schema.COLUMNS where table_name = ‘t_file’;
mybatis用法:
<sql id="BASE_COLUMN_LIST">
</sql>
<include refid="BASE_COLUMN_LIST"/>
可能遇到的问题:
MySQL 的 group_concat_max_len 系统变量所设置的长度限制,列名太多,上述查询不能查出所有字段,可通过临时更改其长度
SET SESSION group_concat_max_len = 100000;

被折叠的 条评论
为什么被折叠?



