Oracle how to grab columns for just one index?

JoshKni8

I am using the following query to grab the index columns on a table along with their data type:

SELECT DISTINCT COL.COLUMN_NAME, COL.DATA_TYPE 
FROM DBA_IND_COLUMNS IND
  INNER JOIN DBA_TAB_COLUMNS COL
    ON ( IND.TABLE_OWNER = COL.OWNER AND IND.TABLE_NAME = COL.TABLE_NAME        
AND IND.COLUMN_NAME = COL.COLUMN_NAME)
WHERE IND.TABLE_NAME = 'MY_TABLE' AND TABLE_OWNER = 'SCHEMA'

But how can I grab the columns for just one index, instead of the columns for all the indexes?

For example: If a table has indexes:

INDEX1: column_a,column_b
INDEX2: column_c,column_d

My current query would result in:

column_a, varchar
column_b, varchar
column_c, varchar
column_d, varchar

but I want it to result in just:

column_a, varchar
column_b, varchar
marcelovca90

Since you just want the columns for the first index (in alphabetical order), you can try:

SELECT DISTINCT COL.COLUMN_NAME, COL.DATA_TYPE 
FROM DBA_IND_COLUMNS IND
    INNER JOIN DBA_TAB_COLUMNS COL
    ON ( IND.TABLE_OWNER = COL.OWNER AND IND.TABLE_NAME = COL.TABLE_NAME        
AND IND.COLUMN_NAME = COL.COLUMN_NAME)
WHERE IND.TABLE_NAME = 'MY_TABLE' AND TABLE_OWNER = 'SCHEMA'
AND INDEX_NAME = 
(
    SELECT MIN(INDEX_NAME) 
    FROM DBA_IND_COLUMNS IIND
    INNER JOIN DBA_TAB_COLUMNS CCOL
    ON ( IIND.TABLE_OWNER = CCOL.OWNER AND IIND.TABLE_NAME = CCOL.TABLE_NAME )       
)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to unstack and grab multiple columns into index?

From Dev

Is it necessary to index columns just for searching in Oracle views?

From Java

Oracle SQL: Single Index with two Columns vs index on one Column

From Dev

How to print columns with awk and in the same time edit just one column?

From Dev

How to get just one frequency of occurrence for items in different columns?

From Dev

How would I modify this fgetcsv to check multiple columns (not just one!)

From Dev

How to assign a user just to one tablespace? - Oracle 11g

From Dev

How to create a pivot table with just one section of a column as the index?

From Dev

MYSQL and PHP loop and grab just one item from a joint table?

From Dev

How to grab the index from a list using LINQ

From Dev

how can oracle SQL return 6 count(columns) from one

From Dev

How to allow NULL value for one column in unique index on multiple columns

From Dev

how to re-arrange multiple columns into one column with same index

From Dev

Exception with join columns just on one server

From Dev

Convert muliple columns and rows to just one

From Dev

How to parse/grab/get one source line?

From Dev

match, index, and concatenate to just one cell

From Dev

How to split one column into two columns just by counting the characters and inserting them into another table via a SQL query?

From Dev

SELECT by one of multiple columns with index

From Dev

How NOT to match in just one regex

From Dev

grab just the cents from string

From Dev

grab just the cents from string

From Dev

Is it possible to prevent the SQL Producer from overwriting just one of the tables columns?

From Dev

Mutate Command Making Multiple Columns Instead of Just One Column

From Dev

Split one level of an multi index into columns

From Dev

How to insert same random value into two columns within one SQL Statement (Oracle)?

From Dev

How to group by one column with single aggregate function but select multiple columns on oracle?

From Dev

How can I create a foreign key with Index in one single create table statement? (Oracle)

From Dev

How to replace one or more \ in string with just \?

Related Related

  1. 1

    How to unstack and grab multiple columns into index?

  2. 2

    Is it necessary to index columns just for searching in Oracle views?

  3. 3

    Oracle SQL: Single Index with two Columns vs index on one Column

  4. 4

    How to print columns with awk and in the same time edit just one column?

  5. 5

    How to get just one frequency of occurrence for items in different columns?

  6. 6

    How would I modify this fgetcsv to check multiple columns (not just one!)

  7. 7

    How to assign a user just to one tablespace? - Oracle 11g

  8. 8

    How to create a pivot table with just one section of a column as the index?

  9. 9

    MYSQL and PHP loop and grab just one item from a joint table?

  10. 10

    How to grab the index from a list using LINQ

  11. 11

    how can oracle SQL return 6 count(columns) from one

  12. 12

    How to allow NULL value for one column in unique index on multiple columns

  13. 13

    how to re-arrange multiple columns into one column with same index

  14. 14

    Exception with join columns just on one server

  15. 15

    Convert muliple columns and rows to just one

  16. 16

    How to parse/grab/get one source line?

  17. 17

    match, index, and concatenate to just one cell

  18. 18

    How to split one column into two columns just by counting the characters and inserting them into another table via a SQL query?

  19. 19

    SELECT by one of multiple columns with index

  20. 20

    How NOT to match in just one regex

  21. 21

    grab just the cents from string

  22. 22

    grab just the cents from string

  23. 23

    Is it possible to prevent the SQL Producer from overwriting just one of the tables columns?

  24. 24

    Mutate Command Making Multiple Columns Instead of Just One Column

  25. 25

    Split one level of an multi index into columns

  26. 26

    How to insert same random value into two columns within one SQL Statement (Oracle)?

  27. 27

    How to group by one column with single aggregate function but select multiple columns on oracle?

  28. 28

    How can I create a foreign key with Index in one single create table statement? (Oracle)

  29. 29

    How to replace one or more \ in string with just \?

HotTag

Archive