Oracle模擬MySQL的show index from table命令
Oracle模擬MySQL的show index from table命令
實驗資料初始化:
顯示該表所有索引的資訊。
以dba登入
以普通使用者登入
但是可以看到,以倒序建立的索引欄位,都是以SYS等命名。
Oracle把這種倒序建立的索引欄位看成函式索引。
它的資訊儲存在user_ind_expressions檢視
user_ind_expressions檢視的COLUMN_EXPRESSION欄位型別是long型。
王工的版本可以解決這個問題
實驗資料初始化:
-
create table t as select * from hr.employees;
-
create index inx_t1 on t(employee_id,first_name desc,last_name);
- create index inx_t2 on t(job_id,hire_date);
以dba登入
-
set linesize 300;
-
set pagesize 100;
-
col c1 format a20;
-
col c2 format a20;
-
col c3 format a20;
-
col c4 format a20;
-
col c5 format a20;
-
col INDEX_NAME format a20;
-
select INDEX_NAME,
-
max(decode(COLUMN_POSITION,1,COLUMN_NAME||','||COLUMN_LENGTH||','||DESCEND,null)) c1,
-
max(decode(COLUMN_POSITION,2,COLUMN_NAME||','||COLUMN_LENGTH||','||DESCEND,null)) c2,
-
max(decode(COLUMN_POSITION,3,COLUMN_NAME||','||COLUMN_LENGTH||','||DESCEND,null)) c3,
-
max(decode(COLUMN_POSITION,4,COLUMN_NAME||','||COLUMN_LENGTH||','||DESCEND,null)) c4,
-
max(decode(COLUMN_POSITION,5,COLUMN_NAME||','||COLUMN_LENGTH||','||DESCEND,null)) c5
-
from (
-
select INDEX_NAME,COLUMN_NAME,COLUMN_LENGTH,COLUMN_POSITION,DESCEND
-
from dba_ind_columns
-
where table_owner='LIHUILIN'
-
AND table_name='T'
-
order by INDEX_NAME,column_position
- ) group by INDEX_NAME;
-
set linesize 300;
-
set pagesize 100;
-
col c1 format a20;
-
col c2 format a20;
-
col c3 format a20;
-
col c4 format a20;
-
col c5 format a20;
-
col INDEX_NAME format a20;
-
select INDEX_NAME,
-
max(decode(COLUMN_POSITION,1,COLUMN_NAME||','||COLUMN_LENGTH||','||DESCEND,null)) c1,
-
max(decode(COLUMN_POSITION,2,COLUMN_NAME||','||COLUMN_LENGTH||','||DESCEND,null)) c2,
-
max(decode(COLUMN_POSITION,3,COLUMN_NAME||','||COLUMN_LENGTH||','||DESCEND,null)) c3,
-
max(decode(COLUMN_POSITION,4,COLUMN_NAME||','||COLUMN_LENGTH||','||DESCEND,null)) c4,
-
max(decode(COLUMN_POSITION,5,COLUMN_NAME||','||COLUMN_LENGTH||','||DESCEND,null)) c5
-
from (
-
select INDEX_NAME,COLUMN_NAME,COLUMN_LENGTH,COLUMN_POSITION,DESCEND
-
from user_ind_columns
-
where table_name='T'
-
order by INDEX_NAME,column_position
- ) group by INDEX_NAME;
但是可以看到,以倒序建立的索引欄位,都是以SYS等命名。
Oracle把這種倒序建立的索引欄位看成函式索引。
它的資訊儲存在user_ind_expressions檢視
user_ind_expressions檢視的COLUMN_EXPRESSION欄位型別是long型。
王工的版本可以解決這個問題
-
CREATE OR REPLACE FUNCTION long_2_varchar (
-
p_index_name IN user_ind_expressions.index_name%TYPE,
-
p_table_name IN user_ind_expressions.table_name%TYPE,
-
p_COLUMN_POSITION IN user_ind_expressions.table_name%TYPE)
-
RETURN VARCHAR2
-
AS
-
l_COLUMN_EXPRESSION LONG;
-
BEGIN
-
SELECT COLUMN_EXPRESSION
-
INTO l_COLUMN_EXPRESSION
-
FROM user_ind_expressions
-
WHERE index_name = p_index_name
-
AND table_name = p_table_name
-
AND COLUMN_POSITION = p_COLUMN_POSITION;
-
-
RETURN SUBSTR (l_COLUMN_EXPRESSION, 1, 4000);
-
END;
- /
-
set linesize 300;
-
set pagesize 100;
-
col c1 format a20;
-
col c2 format a20;
-
col c3 format a20;
-
col c4 format a20;
-
col c5 format a20;
-
col INDEX_NAME format a20;
-
SELECT INDEX_NAME,
-
MAX (DECODE (COLUMN_POSITION, 1, COLUMN_NAME || ' ' || DESCEND, NULL))
-
c1,
-
MAX (DECODE (COLUMN_POSITION, 2, COLUMN_NAME || ' ' || DESCEND, NULL))
-
c2,
-
MAX (DECODE (COLUMN_POSITION, 3, COLUMN_NAME || ' ' || DESCEND, NULL))
-
c3,
-
MAX (DECODE (COLUMN_POSITION, 4, COLUMN_NAME || ' ' || DESCEND, NULL))
-
c4,
-
MAX (DECODE (COLUMN_POSITION, 5, COLUMN_NAME || ' ' || DESCEND, NULL))
-
c5
-
FROM ( SELECT a.INDEX_NAME,
-
REPLACE (
-
DECODE (
-
descend,
-
'DESC', long_2_varchar (b.index_name,
-
b.table_NAME,
-
b.COLUMN_POSITION),
-
a.column_name),
-
'"',
-
'')
-
COLUMN_NAME,
-
a.COLUMN_LENGTH,
-
a.COLUMN_POSITION,
-
DESCEND
-
FROM user_ind_columns a
-
LEFT JOIN
-
user_ind_expressions b
-
ON a.index_name = b.index_name
-
AND a.table_name = b.table_name
-
WHERE a.table_name = 'T'
-
ORDER BY INDEX_NAME, column_position)
- GROUP BY INDEX_NAME;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29254281/viewspace-1193391/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MysqL中的Show Index From Table_Name命令說明MySqlIndex
- Mysql---show table statusMySql
- mysql show命令MySql
- MySQL中的show命令MySql
- MySQL Show命令的用法大全MySql
- mysql的ALTER TABLE命令MySql
- MySQL show status 命令詳解MySql
- MySQL SHOW STATUS命令介紹MySql
- mysql show命令用法大全MySql
- mysql show processlist命令詳解MySql
- Oracle Index-organized table (IOT)概述OracleIndexZed
- MySQL中show命令用法大全MySql
- 關於 mysql 中的 select * from table_a,table_b 的問題MySql
- Oracle RMAN 的 show,list,crosscheck,delete命令整理OracleROSdelete
- 簡述Oracle IOT(Index Organized Table)(上)OracleIndexZed
- 簡述Oracle IOT(Index Organized Table)(下)OracleIndexZed
- 簡述Oracle IOT(Index Organized Table)(中)OracleIndexZed
- MySQL show 命令使用大全 未完待續MySql
- index table (IOT)Index
- oracle中監聽器show命令備記Oracle
- mysql的show processlistMySql
- SQL查詢table或index異常增長問題 - space_usage (show_space)SQLIndex
- mysql中You can’t specify target table for update in FROM clMySql
- Oracle中的虛擬列索引-nosegment indexOracle索引Index
- mysql資料庫show的常用命令說明MySql資料庫
- git show 命令Git
- MySQL:kill和show命令hang住一列MySql
- MySQL show status命令輸出結果詳解MySql
- partition table and partition indexIndex
- mysql學習之-show table status(獲取表的資訊)引數說明MySql
- TABLE size (including table,index,lob,lobindex)Index
- 查詢使用表空間的TABLE,INDEX,INDEX SUBPARTITIONIndex
- oracle10.2.0.4_create table_constraint_indexOracleAIIndex
- MySQL show status命令常用輸出欄位詳解MySql
- 模擬linux下的ls -l命令Linux
- git show命令用法Git
- 'mysql.column_stats' doesn't exist and Table 'mysql.index_stats' doesn't existMySqlIndex
- 模擬Oracle的desc命令編寫的describe,查詢表的結構Oracle