1、查找表的所有索引(包括索引名,类型,构成列):
SELECT T.*, I.INDEX_TYPE
FROM USER_IND_COLUMNS T, USER_INDEXES I WHERE T.INDEX_NAME = I.INDEX_NAME AND T.TABLE_NAME = I.TABLE_NAME AND T.TABLE_NAME = 'TABLE_NAME'
将多列索引,列名合并
SELECT TABLE_NAME, INDEX_NAME, MAX(COLUMN_NAME), INDEX_TYPE
FROM (SELECT T.INDEX_NAME, T.TABLE_NAME, WMSYS.WM_CONCAT(T.COLUMN_NAME) OVER(PARTITION BY T.INDEX_NAME, T.TABLE_NAME, I.INDEX_TYPE ORDER BY T.COLUMN_POSITION) COLUMN_NAME, I.INDEX_TYPE FROM USER_IND_COLUMNS T, USER_INDEXES I WHERE T.INDEX_NAME = I.INDEX_NAME AND T.TABLE_NAME = I.TABLE_NAME AND T.TABLE_NAME IN ('MYTABLE')) GROUP BY INDEX_NAME, TABLE_NAME, INDEX_TYPE ORDER BY TABLE_NAME, INDEX_NAME目前对函数索引,无法 显示索引内容。
SELECT CU.* FROM USER_CONS_COLUMNS CU, USER_CONSTRAINTS AU WHERE CU.CONSTRAINT_NAME = AU.CONSTRAINT_NAME AND AU.CONSTRAINT_TYPE = 'P' AND AU.TABLE_NAME = 'TABLE_NAME'
SELECT COLUMN_NAME FROM USER_CONS_COLUMNS CU, USER_CONSTRAINTS AU WHERE CU.CONSTRAINT_NAME = AU.CONSTRAINT_NAME AND AU.CONSTRAINT_TYPE = 'U' AND AU.TABLE_NAME = 'TABLE_NAME'
SELECT * FROM USER_CONSTRAINTS C WHERE C.CONSTRAINT_TYPE = 'R' AND C.TABLE_NAME = 'TABLE_NAME'
SELECT * FROM USER_CONS_COLUMNS CL WHERE CL.CONSTRAINT_NAME = '外键名称'
SELECT * FROM USER_CONS_COLUMNS CL WHERE CL.CONSTRAINT_NAME = '外键引用表的键名'
SELECT T.*, C.COMMENTS FROM USER_TAB_COLUMNS T, USER_COL_COMMENTS C WHERE T.TABLE_NAME = C.TABLE_NAME AND T.COLUMN_NAME = C.COLUMN_NAME AND T.TABLE_NAME = 'TABLE_NAME'
6、oracle锁定表解锁
查询锁表记录
select sess.sid, sess.serial#, lo.oracle_username, lo.os_user_name, ao.object_name, lo.locked_mode from v$locked_object lo, dba_objects ao, v$session sess where ao.object_id = lo.object_id and lo.session_id = sess.sid;解锁语句
alter system kill session 'SID,SERIAL#';