what're Oracle equivalent of DB2 sysibm.sysindexes,sysibm.sysrels

I have the following two queries from db2 system tables to return primary key and a list of children tables of a given table

Could anybody help to convert them to Oracle equivalent

1. SELECT colnames
                FROM sysibm.sysindexes
                  WHERE tbName = 'mytableName' AND
                  uniquerule = 'P' AND colcount = 1

SELECT tbname, fkcolnames
                  FROM sysibm.sysrels
                  WHERE reftbname = 'myTableName'
                  ORDER BY timestamp

Who is Participating?
riazpkConnect With a Mentor Commented:
SELECT column_name
FROM all_ind_columns a
WHERE table_name= '<table name in CAPS>'
AND column_position=1
exists (select null from all_indexes b where a.index_name=b.index_name and UNIQUENESS='UNIQUE')


select column_name
FROM all_ind_columns a, all_indexes b
WHERE table_name= '<table name in CAPS>'
and a.index_name=b.index_name
AND column_position=1
seazodiacConnect With a Mentor Commented:
sure. try this:


SELECT column_name
FROM all_ind_columns
WHERE table_name= '<table name in CAPS>'
AND column_position=1;


select table_name, column_name
from all_cons_columns A, all_constraints B
where A.constraint_name=B.constraint_name
and B.constraint_type='R'
and  table_name='<table_name in CAPS>'
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

dnarramoreConnect With a Mentor Commented:

select all_ind_columns.column_name
from all_indexes,
where all_indexes.index_name = all_ind_columns.index_name
and  all_indexes.table_owner = all_ind_columns.table_owner
and uniqueness = 'UNIQUE'
and all_indexes.table_name = 'MyTableName'
and all_indexes.index_name || all_indexes.table_owner in (select index_name || table_owner
                   from all_ind_columns
                           group by index_name, table_owner
                           having count(*) > 1)
oldyyyAuthor Commented:
Thanks seazodiac and dharramore.

seazodiac's1 give me a list of 6 rows on oracle, where the db2 one only returned one row--> the first row.
Seazodiac's 1 is equivalent to the following db2  
SELECT colnames
                FROM sysibm.sysindexes
                  WHERE tbName = 'mytableName'

( without uniquerule = 'P' AND colcount = 1)

seazodiac's 2 give me 0 rows, where the db2 one returned 4 rows on db2 database.

dnarramore's 1 gives me 0 rows

Could anyone help again?

Here is the explanation for my first query to return 6 rows in oracle but the similar query return only 1 rows.

that's because when you have "colcount=1" and "uniquerule='P'" in the where clause, you are limited the ONLY PRIMARY KEY column in the MytableName , and conceivably, you have only one PRimary key in one table.

the similar query in Oracle will return all the Indexed columns including PRIMARY key (because Oracle db will create a unique index on PK by default).

just to add, still on the first question, colcount in IBM sysindexes table means the number of columns in the index.

so your original query is trying to get the single-column Primary key from sysindexes table.

there is really no need to try to find the matching query, as long as you are getting comfortable with Metadata in each database, you will get what you want.

select column_name,position
from all_cons_columns a, all_constraints b
where b.table_name='TABLEName'
and a.constraint_name=b.constraint_name
and constraint_type='R'
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.