SELECT F.TABLE_NAME, F.CONSTRAINT_NAME, F.COLUMN_NAME, F.POSITION, P.TABLE_NAME, P.COLUMN_NAME, P.POSITION
FROM USER_CONSTRAINTS R, USER_CONS_COLUMNS F, USER_CONS_COLUMNS P
WHERE R.OWNER = UPPER(:schema)
AND R.TABLE_NAME = UPPER(:tab)
AND R.CONSTRAINT_TYPE = 'R'
AND R.CONSTRAINT_NAME = F.CONSTRAINT_NAME
AND R.R_CONSTRAINT_NAME = P.CONSTRAINT_NAME
AND F.POSITION = P.POSITION
ORDER BY F.TABLE_NAME, F.CONSTRAINT_NAME, F.POSITION;
FROM USER_CONSTRAINTS R, USER_CONS_COLUMNS F, USER_CONS_COLUMNS P
WHERE R.OWNER = UPPER(:schema)
AND R.TABLE_NAME = UPPER(:tab)
AND R.CONSTRAINT_TYPE = 'R'
AND R.CONSTRAINT_NAME = F.CONSTRAINT_NAME
AND R.R_CONSTRAINT_NAME = P.CONSTRAINT_NAME
AND F.POSITION = P.POSITION
ORDER BY F.TABLE_NAME, F.CONSTRAINT_NAME, F.POSITION;