How can I find the underlying column and table name for an Oracle view?

前端 未结 7 1840
余生分开走
余生分开走 2021-01-23 05:34

This sounds like it should be simple to do but not so! There is no Oracle (meta-data) view that I can find that gives the underlying column and table name for an Oracle view col

7条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-23 06:07

    This works well if you want a views table and column dependencies:

    WITH view_dependencies (view_name, table_name) AS (
        SELECT CONNECT_BY_ROOT d.name AS view_name, d.referenced_name AS table_name
        FROM all_dependencies d
        WHERE d.referenced_type IN ('TABLE', 'VIEW')
        START WITH d.name = UPPER('jtf_rs_resource_extns_vl') AND d.type = 'VIEW'
        CONNECT BY PRIOR d.referenced_name = d.name AND PRIOR d.referenced_type = d.type
    )
    SELECT deps.view_name, deps.table_name, tbl.table_id, cols.column_id, 
           cols.column_name  
    FROM view_dependencies deps
        LEFT JOIN FND_TABLES tbl ON tbl.table_name = deps.table_name
        LEFT JOIN FND_COLUMNS cols ON tbl.table_id = cols.table_id
    ORDER BY deps.view_name,  deps.table_name, cols.column_sequence;
    

    Outputs

    VIEW_NAME                   TABLE_NAME            TABLE_ID COLUMN_ID COLUMN_NAME
    =======================================================================================
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563724  RESOURCE_ID
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563712  CREATED_BY
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563713  CREATION_DATE
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563718  LAST_UPDATED_BY
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563719  LAST_UPDATE_DATE
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563720  LAST_UPDATE_LOGIN
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563704  CATEGORY
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563725  RESOURCE_NUMBER
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563729  SOURCE_ID
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563686  ADDRESS_ID
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563709  CONTACT_ID
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563721  MANAGING_EMPLOYEE_ID
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563730  START_DATE_ACTIVE
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563714  END_DATE_ACTIVE
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563732  TIME_ZONE
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563711  COST_PER_HR
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563723  PRIMARY_LANGUAGE
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563726  SECONDARY_LANGUAGE
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563717  IES_AGENT_LOGIN
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563728  SERVER_GROUP_ID
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563687  ASSIGNED_TO_GROUP_ID
    JTF_RS_RESOURCE_EXTNS_VL    JTF_RS_RESOURCE_EXTNS   80056   563710  COST_CENTER
    

提交回复
热议问题