Mysql

## 字符拼接 CONCAT('//',column_comment) ![image.png](https://cos.easydoc.net/48081513/files/kjtw8d5i.png) ## 查询表字段 类型 介绍 ``` SELECT replace( replace(replace(replace(replace(CONCAT( 'private ', data_type ) ,'bigint','Long') ,'varchar','String') ,'datetime' ,'String') ,'int' ,'Integer') ,'tinyint' ,'Integer') , CONCAT(LOWER(LEFT(CONCAT( column_name, ' ;' ), 1)) ,RIGHT(CONCAT( column_name, ' ;' ),LENGTH(CONCAT( column_name, ' ;' ))-1) ) , CONCAT( ' //', column_comment ) FROM information_schema.COLUMNS WHERE table_name = 'station' AND table_schema = 'wcs' -- mqttmessages 表名字 -- lifter1 数据库名字 ``` ## 查询表字段 类型 介绍 前端 ``` SELECT replace(replace(replace(CONCAT( '', data_type ),'bigint','int'),'varchar','String') ,'datetime' ,'String') , CONCAT(LOWER(LEFT(CONCAT( column_name, '' ), 1)) ,RIGHT(CONCAT( column_name, '' ),LENGTH(CONCAT( column_name, '' ))-1) ) , CONCAT( column_comment,' - ' ) FROM information_schema.COLUMNS WHERE table_name = 'topologyofconveyorunit' AND table_schema = 'wcs' -- mqttmessages 表名字 -- lifter1 数据库名字 ``` ![image.png](https://cos.easydoc.net/48081513/files/kjtwhk1i.png) ## 字符串 ``` CONCAT(str1, str2):字符连接函数 UPPER(str):将字符串改为大写字母 LOWER(str):将字符串改为小写字母 LENGTH(str):判定字符串长度 SUBSTRING(str, a, b):提取字段中的一段,从字符串str的第a位开始提取,提取b个字符 LEFT(str, n):提取字符串最左边的n个字符 RIGHT(str, n):提取字符串最右边的n个字符 例:将users表中的username字段的首字母转换为大写 SQL 替换特定字符 update 表名 set 字段名称=replace(字段名称,’ 替换的原始字符’,’替换的后的字符’) where … ``` ## 时间转换格式 ``` DATE_FORMAT(er.start_time,'%Y-%c-%d') AS startTimeStr , ```