1. vo 만들기
SELECT
#CONCAT(COL,',')AS ''
CONCAT('private ', CASE WHEN DATA_TYPE = 'timestamp' THEN 'Timestamp ' ELSE 'String ' END, GENERATOR_COL,';' , ' //' , IFNULL(COLUMN_COMMENT, ''))AS ''
#CONCAT('#{', GENERATOR_COL,'},')AS ''
FROM
(
SELECT COL,
CASE WHEN COL1 ='' THEN '_id'
ELSE CONCAT(LOWER(COL1),UPPER(SUBSTR(COL2, 1, 1)),LOWER(SUBSTR(COL2, 2)),UPPER(SUBSTR(COL3, 1, 1)),LOWER(SUBSTR(COL3, 2)),UPPER(SUBSTR(COL4, 1, 1)),LOWER(SUBSTR(COL4, 2)))
END GENERATOR_COL, COLUMN_COMMENT, DATA_TYPE
FROM
(
SELECT replace(substring(substring_index(COL,'_', 1), length(substring_index(COL,'_', 1 - 1)) + 1),'_','')AS COL1,
replace(substring(substring_index(COL,'_', 2), length(substring_index(COL,'_', 2 - 1)) + 1),'_','')AS COL2,
replace(substring(substring_index(COL,'_', 3), length(substring_index(COL,'_', 3 - 1)) + 1),'_','')AS COL3,
replace(substring(substring_index(COL,'_', 4), length(substring_index(COL,'_', 4 - 1)) + 1),'_','')AS COL4,
COL, COLUMN_COMMENT, DATA_TYPE
FROM
(
SELECT column_name AS COL, COLUMN_COMMENT, DATA_TYPE
FROM information_schema.columns
WHERE table_name ='ST_COM_MESSAGE'
)AS X
)AS Y
)AS Z;
'개발 > 개발에 유용한 팁' 카테고리의 다른 글
Regular Expression (0) | 2021.03.07 |
---|---|
Mybatis 쿼리 바인딩 로그 출력 (0) | 2020.08.24 |
MessageBundle DB로 전환 (0) | 2020.08.23 |
톰캣 재시작 없이 Java 수정 (0) | 2020.08.15 |
테이블로 VO, Insert, Update문 만들기 (0) | 2020.08.13 |