查询sql:
SELECT
CONCAT('CREATE INDEX ',
IF(LENGTH(INDEX_NAME) < 30,INDEX_NAME,SUBSTRING(INDEX_NAME,1,30))
,' ', ' ON ',
IF(NON_UNIQUE = 1,
CASE UPPER(INDEX_TYPE)
WHEN 'FULLTEXT' THEN 'FULLTEXT INDEX'
WHEN 'SPATIAL' THEN 'SPATIAL INDEX'
ELSE CONCAT('',
TABLE_NAME,
' '
)
END,
IF(UPPER(INDEX_NAME) = 'PRIMARY',
CONCAT('PRIMARY KEY USING ',
INDEX_TYPE
),
CONCAT('UNIQUE INDEX ',
INDEX_NAME,
' USING ',
INDEX_TYPE
)
)
),'(', GROUP_CONCAT(DISTINCT CONCAT('', COLUMN_NAME, '',' ASC ') ORDER BY SEQ_IN_INDEX ASC SEPARATOR ', '), ');') AS 'Show_Add_Indexes'
FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = 'iov_his' and UPPER(INDEX_NAME)!='PRIMARY'
GROUP BY TABLE_NAME, INDEX_NAME
ORDER BY TABLE_NAME ASC, INDEX_NAME ASC
这样可以查出整个库的所有表的索引,并且拼接成oracle可以执行的sql脚本。
oracle命名长度不能超过30个字符,所以将名字截断了30个字符内。