oracle dml 문장 생성 1

WITH tempTbl AS (
    SELECT a.COLUMN_ID AS colId 
         , a.COLUMN_NAME AS colName
         , LOWER(SUBSTR(REPLACE(INITCAP(a.COLUMN_NAME),'_'),1,1))||SUBSTR(REPLACE(INITCAP(a.COLUMN_NAME),'_'),2,LENGTH(a.COLUMN_NAME)-1) AS camel 
         , ('/*'||c.COMMENTS || ','|| a.DATA_TYPE ||'('||a.DATA_LENGTH ||')'||'*/') AS cmt
         , ('/*'||c.COMMENTS ||'*/') AS cmt2
         , c.COMMENTS AS orgCmt
         , a.DATA_TYPE AS dataType
         , a.DATA_LENGTH AS dataLen
      FROM ALL_TAB_COLUMNS a
      LEFT OUTER JOIN ALL_COL_COMMENTS c
        ON a.OWNER = c.OWNER
       AND a.TABLE_NAME = c.TABLE_NAME
       AND a.COLUMN_NAME = c.COLUMN_NAME
     WHERE a.OWNER = 'SEMA_ERP'
       AND a.TABLE_NAME IN ('AM_CMMN_COSTPT_D') /*조회할 Table명*/
--       AND a.COLUMN_NAME IN ('COMPANY_CODE','BANK_NO_SEQ','BANK_NO','BANK_DIV','CUST_CODE','DEPOSIT_OWNER','USE_YN','DEPT_CODE','APL_STR_DTE'
--                            ,'APL_END_DTE','FUND_CHK_YN','FUND_CHK_NOTE','FUND_CHK_YN_B','BANK_RES_CODE','BANK_RES_DESC','INPUT_DATE','INPUT_DUTY_ID'
--                            ,'CHG_DATE','CHG_DUTY_ID'
--       )
)
SELECT MAX(aa.ommType) AS ommType
     , MAX(aa.colId) AS colId
     , aa.ommName
     , MAX(aa.ommDescription) AS ommDescription
     , MAX(aa.ommLength) AS ommLength
     , (MAX(aa.ommType)||' '||aa.ommName||'<length='||MAX(aa.ommLength)||' description="'||MAX(aa.ommDescription)||'">;') AS ommGenStr
     , MAX(aa.dmlStr) AS dmlStr
     , MAX(aa.dmlStr2) AS dmlStr2
  FROM (
        SELECT CASE WHEN a.dataType IN ('VARCHAR2') THEN 'String' 
                    WHEN a.dataType IN ('DATE') THEN 'Date'
                    WHEN a.dataType IN ('NUMBER') AND a.dataLen < 10 THEN 'Integer'
                    WHEN a.dataType IN ('NUMBER') AND a.dataLen >= 10 THEN 'BigDecimal'
               END ommType
             , a.camel AS ommName
             , a.orgCmt AS ommDescription
             , a.dataLen AS ommLength
             , a.colId 
             , (', '||RPAD(a.colName, b.maxLenCol, ' ') ||' AS '||RPAD(a.camel, b.maxLenCmt,' ')||' '||a.cmt) AS dmlStr
             , (', '||RPAD(a.colName, b.maxLenCol, ' ') ||' '||a.cmt2) AS dmlStr2
          FROM tempTbl a
         OUTER APPLY( SELECT MAX(LENGTHB(colName)) AS maxLenCol
                           , MAX(LENGTHB(camel)) AS maxLenCmt 
                        FROM tempTbl
                    ) b  
       ) aa
 GROUP BY aa.ommName
-- ORDER BY aa.ommName
 ORDER BY MAX(aa.colId)
-- ORDER BY MAX(aa.ommName)

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다