分享一个oracle 获取某张表的所有索引,并组装重讲索引语句
SELECT 'alter index ' || i.index_name || ' REBUILD parallel 8 nologging' AS result
FROM user_indexes i
JOIN user_ind_columns c ON i.index_name = c.index_name AND i.table_name = c.table_name
WHERE i.table_name in ('XX','XXX') -- 表名
GROUP BY i.index_name, i.table_name, i.uniqueness,i.index_type
ORDER BY i.table_name, i.index_name;
-- 关闭并发和nologging
SELECT 'alter index ' || i.index_name || ' noparallel logging' AS result
FROM user_indexes i
JOIN user_ind_columns c ON i.index_name = c.index_name AND i.table_name = c.table_name
WHERE i.table_name in i.table_name in ('XX','XXX')
GROUP BY i.index_name, i.table_name, i.uniqueness,i.index_type
ORDER BY i.table_name, i.index_name;