LISTAGG()WITHIN GROUP()

    SELECT T1.TABLE_NAME
          ,LISTAGG(CASE WHEN T2.DATA_TYPE = 'DATE'  THEN 'TO_CHAR('||T1.COLUMN_NAME || ',''YYYYMMDD'')' ELSE T1.COLUMN_NAME END,'||''|''||')WITHIN GROUP(ORDER BY T1.COLUMN_NAME) AS KEY_NAMES
     FROM USER_CONS_COLUMNS T1
     JOIN USER_TAB_COLUMNS T2
       ON T1.TABLE_NAME = T2.TABLE_NAME
      AND T1.COLUMN_NAME = T2.COLUMN_NAME
    WHERE T1.POSITION IS NOT NULL
      AND T1.TABLE_NAME = '""" + table_name + """'
 GROUP BY T1.TABLE_NAME 

  

posted @ 2021-06-21 14:32  rjm123456  阅读(62)  评论(0编辑  收藏  举报