Oracle模拟MySQL的showindexfromtable命令_MySQL
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Oracle模拟MySQL的showindexfromtable命令_MySQL,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3682字,纯文字阅读大概需要6分钟。
内容图文
![Oracle模拟MySQL的showindexfromtable命令_MySQL](/upload/InfoBanner/zyjiaocheng/579/de7b3eda756941569c4c891126742363.jpg)
实验数据初始化:
-
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 ;
-
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 ;
内容总结
以上是互联网集市为您收集整理的Oracle模拟MySQL的showindexfromtable命令_MySQL全部内容,希望文章能够帮你解决Oracle模拟MySQL的showindexfromtable命令_MySQL所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。