SELECT CONCAT(
'/* ',
CASE WHEN LENGTH(COLUMN_COMMENT) > 0 THEN
COLUMN_COMMENT
ELSE
COLUMN_NAME
END,
' */',
CHAR(13),
'private',
CASE
WHEN LOWER(DATA_TYPE) = 'varchar' THEN ' String '
WHEN INSTR(LOWER(DATA_TYPE), 'int') > 0 THEN ' Integer '
WHEN LOWER(DATA_TYPE) = 'text' THEN ' String '
WHEN LOWER(DATA_TYPE) = 'datetime' THEN ' String '
ELSE ' Object '
END,
CONCAT(
TRIM(CN1),
TRIM(CONCAT(UPPER(SUBSTRING(CN2, 1, 1)) , SUBSTRING(CN2, 2, LENGTH(CN2)))),
TRIM(CONCAT(UPPER(SUBSTRING(CN3, 1, 1)) , SUBSTRING(CN3, 2, LENGTH(CN3)))),
TRIM(CONCAT(UPPER(SUBSTRING(CN4, 1, 1)) , SUBSTRING(CN4, 2, LENGTH(CN4)))),
TRIM(CONCAT(UPPER(SUBSTRING(CN5, 1, 1)) , SUBSTRING(CN5, 2, LENGTH(CN5))))
),
';',
CHAR(13),
CHAR(13)
)
FROM
(
SELECT B.COLUMN_NAME,
CASE WHEN LENGTH(B.COLUMN_NAME) - LENGTH(REPLACE(B.COLUMN_NAME, '_', '')) + 1 >= 1 THEN
SUBSTRING_INDEX(SUBSTRING_INDEX(LCASE(B.COLUMN_NAME), '_', 1), '_', -1)
ELSE ' ' END AS CN1,
CASE WHEN LENGTH(B.COLUMN_NAME) - LENGTH(REPLACE(B.COLUMN_NAME, '_', '')) + 1 >= 2 THEN
SUBSTRING_INDEX(SUBSTRING_INDEX(LCASE(B.COLUMN_NAME), '_', 2), '_', -1)
ELSE ' ' END AS CN2,
CASE WHEN LENGTH(B.COLUMN_NAME) - LENGTH(REPLACE(B.COLUMN_NAME, '_', '')) + 1 >= 3 THEN
SUBSTRING_INDEX(SUBSTRING_INDEX(LCASE(B.COLUMN_NAME), '_', 3), '_', -1)
ELSE ' ' END AS CN3,
CASE WHEN LENGTH(B.COLUMN_NAME) - LENGTH(REPLACE(B.COLUMN_NAME, '_', '')) + 1 >= 4 THEN
SUBSTRING_INDEX(SUBSTRING_INDEX(LCASE(B.COLUMN_NAME), '_', 4), '_', -1)
ELSE ' ' END AS CN4,
CASE WHEN LENGTH(B.COLUMN_NAME) - LENGTH(REPLACE(B.COLUMN_NAME, '_', '')) + 1 >= 5 THEN
SUBSTRING_INDEX(SUBSTRING_INDEX(LCASE(B.COLUMN_NAME), '_', 5), '_', -1)
ELSE ' ' END AS CN5,
B.DATA_TYPE,
B.COLUMN_COMMENT
FROM information_schema.TABLES A
INNER JOIN information_schema.COLUMNS B ON (A.TABLE_NAME = B.TABLE_NAME)
WHERE A.TABLE_NAME = '[테이블]'
AND A.TABLE_SCHEMA = '[디비]'
ORDER BY B.ORDINAL_POSITION
) A
_(언더바) 갯수만큼 CN1 2 3 4 5 추가
'DB > MYSQL' 카테고리의 다른 글
초성 검색 함수 (0) | 2021.04.27 |
---|---|
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements (0) | 2021.03.03 |
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. (0) | 2021.03.03 |
mysql backup (0) | 2021.03.03 |
mysql 5.7 install (0) | 2021.03.03 |