数据库
首页 > 数据库> > 通过sql拼接表的下划线转驼峰

通过sql拼接表的下划线转驼峰

作者:互联网

SELECT
	-- COLUMN_NAME,
    -- _分割之后的第一段
   concat(    SUBSTRING_INDEX(LOWER(column_name), '_', 1),
    -- _分割之后的第二段
    SUBSTR(
      UPPER(column_name),
      LENGTH(
        SUBSTRING_INDEX(column_name, '_', 1)
      ) + 2,
      1
    ),
    SUBSTR(
      LOWER(column_name),
      LENGTH(
        SUBSTRING_INDEX(column_name, '_', 1)
      ) + 3,
      LENGTH(
        SUBSTRING_INDEX(column_name, '_', 2)
      ) - LENGTH(
        SUBSTRING_INDEX(column_name, '_', 1)
      ) - 2
    ), -- _分割之后的第三段
    SUBSTR(
      UPPER(column_name),
      LENGTH(
        SUBSTRING_INDEX(column_name, '_', 2)
      ) + 2,
      1
    ),
		 SUBSTR(
      LOWER(column_name),
      LENGTH(
        SUBSTRING_INDEX(column_name, '_', 2)
      ) + 3,
      LENGTH(
        SUBSTRING_INDEX(column_name, '_', 3)
      ) - LENGTH(
        SUBSTRING_INDEX(column_name, '_', 2)
      ) - 2
    ),
    -- _分割之后的第四段
    SUBSTR(
      UPPER(column_name),
      LENGTH(
        SUBSTRING_INDEX(column_name, '_', 3)
      ) + 2,
      1
    ),
    SUBSTR(
      LOWER(column_name),
      LENGTH(
        SUBSTRING_INDEX(column_name, '_', 3)
      ) + 3,
      LENGTH(
        SUBSTRING_INDEX(column_name, '_', 4)
      ) - LENGTH(
        SUBSTRING_INDEX(column_name, '_', 3)
      ) - 2
    )),
	column_comment 
FROM
	INFORMATION_SCHEMA.COLUMNS 
WHERE
	table_name = 'scd_cost_charge_item';

标签:INDEX,name,驼峰,column,SUBSTRING,SUBSTR,LENGTH,sql,下划线
来源: https://www.cnblogs.com/yuangyuan/p/16449815.html