System Tables in Oracle 10g

  • We all know that in SQL Server that there is a system table that tells you about all the columns in each table in a database, sys.columns (in SQL Server 2005/2008).

    Is there an equivalent system table or view that provides the same information? I'm not having much luck finding one, but perhaps one of you out there that also are familiar with Oracle may be able to assist.

  • there's a few suites of views of the objects: ALL_TABLES, DBA_TABLES and USER_TABLES;

    i try to stick with USER_tables, which are filtered to the schema you belong to (well the oracle user)

    USER_TABLES is ~sys.tables

    user_tab_columns is ~ sys.columns

    here's an example i use when getting tables in a FK hierarchy order:

    WITH MyCommonTableExpression

    AS

    (

    SELECT

    a.table_name as child_table,

    b.table_name parent_table,

    colb.column_name as child_column

    from user_constraints a

    INNER JOIN user_constraints b ON a.r_constraint_name = b.constraint_name

    INNER JOIN user_cons_columns conb ON conb.constraint_name = b.constraint_name

    INNER JOIN user_tab_columns colb ON colb.table_name = conb.table_name

    AND colb.column_name = conb.column_name

    WHERE a.constraint_type = 'R'

    )

    SELECT

    parent_table,

    child_table,

    child_column,

    1 as lvl

    FROM MyCommonTableExpression

    WHERE parent_table='GMACT'

    START WITH parent_table = 'GMACT'

    CONNECT BY PRIOR child_table = parent_table

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • also this will really get you what you are after:

    select * from all_views where LEFT(view_name,5) = 'USER_'

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • I also founf ALL_TAB_COLUMNS that provided me with the info I needed.

    I will definately take a closer look and the code you provided when I have a little more time. Got some project stuff I need to work on right now.

    Thanks Lowell.

  • Lynn Pettis (10/8/2010)


    We all know that in SQL Server that there is a system table that tells you about all the columns in each table in a database, sys.columns (in SQL Server 2005/2008).

    Is there an equivalent system table or view that provides the same information? I'm not having much luck finding one, but perhaps one of you out there that also are familiar with Oracle may be able to assist.

    check dba_tab_columns, you have to have dba privileges to have access to it.

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply