Link to home
Create AccountLog in
Avatar of Sh M
Sh MFlag for United States of America

asked on

Oracle system generated name in n column names of data type varchar2

Using user_ind_columns and user_tab_columns, I would like to extract a list of indexes (of index_name, table_name and column_name,) on the columns with data_type VARCHAR2.

The problem is that Oracle generates system column name and I can not match the columns in the two tables.

Any suggestions?



Avatar of Sean Stuber
Sean Stuber

Any of these should do it.

Whether the column names are system or manually generated is irrelevant to the query.


  SELECT i.index_name, i.table_name, i.column_name
    FROM user_ind_columns i
         JOIN user_tab_columns t
             ON i.table_name = t.table_name AND i.column_name = t.column_name
   WHERE t.data_type = 'VARCHAR2'
ORDER BY i.index_name, i.table_name, i.column_name;

  SELECT index_name, table_name, column_name
    FROM user_ind_columns i
   WHERE EXISTS
             (SELECT NULL
                FROM user_tab_columns t
               WHERE i.table_name = t.table_name
                 AND i.column_name = t.column_name
                 AND t.data_type = 'VARCHAR2')
ORDER BY index_name, table_name, column_name;

   SELECT i.index_name, i.table_name, i.column_name
    FROM user_ind_columns i
   WHERE (table_name, column_name) IN
             (SELECT t.table_name, t.column_name
                FROM user_tab_columns t
               WHERE t.data_type = 'VARCHAR2')
ORDER BY i.index_name, i.table_name, i.column_name;

Avatar of Sh M

ASKER

First and second won’t work because 

This condition 

i.column_name = t.column_name

does not work as oracle generate system name for column name for data types of varchar2 in user_ind_column table

Third one is not working because there is no index_name column in t table.


Note the logic in second one bypasses the columns which I need to see in the result set.

Sean's queries work on my system.  But I'm using the default security/encryption, too.



@Sh M: I agree with Kent! These script will do the work. 

If you think, they do not, then you should have stated your question(s) more detailed and properly ;-)

Seans's script are the correct answer to your question!

ASKER CERTIFIED SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Sh M

ASKER

Hello Sean,

Apologies for late response.

Yes what I mean is function based indexes. I wondered there might be a pattern on the way these columns are named but if it can not be done. That is fine.

Thank you for your advice.