LISTAGG之取索引对应列名称

SQL> select uc.TABLE_NAME,
  2         uc.INDEX_NAME,
  3         listagg(uc.COLUMN_NAME, ',') within group(order by uc.COLUMN_POSITION) as cols
  4    from user_ind_columns uc
  5   group by uc.TABLE_NAME, uc.INDEX_NAME
  6  /
 
TABLE_NAME  INDEX_NAME   COLS      
----------- ------------ ----------
T1          IDX_T1       ID,OWNER
EMP         PK_EMP       EMPNO
DEPT        PK_DEPT      DEPTNO

增加排序属性显示

select uc.TABLE_NAME,
       uc.INDEX_NAME,
       listagg(uc.COLUMN_NAME || ' ' || uc.DESCEND, ',') within group(order by uc.COLUMN_POSITION) as cols
  from user_ind_columns uc
 group by uc.TABLE_NAME, uc.INDEX_NAME;


你可能感兴趣的:(LISTAGG之取索引对应列名称)