主頁(yè) > 知識(shí)庫(kù) > Oracle中實(shí)現(xiàn)MySQL show index from table命令SQL腳本分享

Oracle中實(shí)現(xiàn)MySQL show index from table命令SQL腳本分享

熱門標(biāo)簽:廣東營(yíng)銷智能外呼系統(tǒng)商家 地圖標(biāo)注怎么保存 七日殺a19.5全地圖標(biāo)注 車瑪仕極限運(yùn)動(dòng)場(chǎng)所地圖標(biāo)注 騰訊地圖標(biāo)注要費(fèi)用嗎 外呼電話系統(tǒng)用卡嗎 電渠外呼系統(tǒng) N個(gè)你智能電銷機(jī)器人 高德地圖標(biāo)注公司名字大全

實(shí)驗(yàn)數(shù)據(jù)初始化:

復(fù)制代碼 代碼如下:

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登錄

復(fù)制代碼 代碼如下:

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;

以普通用戶登錄

復(fù)制代碼 代碼如下:

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;

但是可以看到,以倒序創(chuàng)建的索引字段,都是以SYS等命名。

Oracle把這種倒序創(chuàng)建的索引字段看成函數(shù)索引。

它的信息保存在user_ind_expressions視圖。

user_ind_expressions視圖的COLUMN_EXPRESSION字段類型是long型。

王工的版本可以解決這個(gè)問(wèn)題

復(fù)制代碼 代碼如下:

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;
/


復(fù)制代碼 代碼如下:

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;


您可能感興趣的文章:
  • SQL獲取表結(jié)構(gòu)的show_table.vbs (冰點(diǎn)極限NP)
  • show engine innodb status顯示信息不全如何解決
  • Mysql中 show table status 獲取表信息的方法

標(biāo)簽:大興安嶺 來(lái)賓 贛州 玉樹 棗莊 長(zhǎng)沙 蘇州 遼寧

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Oracle中實(shí)現(xiàn)MySQL show index from table命令SQL腳本分享》,本文關(guān)鍵詞  Oracle,中,實(shí)現(xiàn),MySQL,show,index,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Oracle中實(shí)現(xiàn)MySQL show index from table命令SQL腳本分享》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Oracle中實(shí)現(xiàn)MySQL show index from table命令SQL腳本分享的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章