1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

How To Display Table Name Along With the Column Names

Discussion in 'SQL PL/SQL' started by april, Feb 2, 2015.

  1. april

    april Active Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    55
    Hello,
    I have 2 tables that have almost identical column names. To ensure I am looking at the right table, I always have to double check the select statement. Is there a way to display the table name along with the column names?

    For example:
    Select col1, col2, col3 from table1;
    Select col4, col5, col6 from table2;

    Can I modify these select statements to see the following results?

    table col1 col2 col3
    --------------------------
    table1 xx xx xx
    table1 yy yy yy

    table col4 col5 col6
    --------------------------
    table2 aa aa aa
    table2 bb bb bb
     
  2. DTSIGuy

    DTSIGuy Forum Advisor

    Messages:
    402
    Likes Received:
    58
    Trophy Points:
    410
    Location:
    Texas
    Have you looked at USER_TAB_COLUMNS?
     
  3. jagadekara

    jagadekara Forum Guru

    Messages:
    1,126
    Likes Received:
    145
    Trophy Points:
    1,805
    Location:
    Pulivendula
    Hi,

    You can also check all_tab_cols
     
  4. RG Hegde

    RG Hegde Forum Advisor

    Messages:
    185
    Likes Received:
    35
    Trophy Points:
    310
    Location:
    Pune
    Are you executing those 2 select statement separately ? If Yes you can hard code the table name in the select statement as
    SELECT 'table1',col1,col2,col3 FROM table1
    SELECT 'table2' ,col4,col5,col6 FROM table2 . This will return your expected result .
     
  5. april

    april Active Member

    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    55
    Yes, I do execute them separately. I added the hardcoded table name in my queries and it worked. Thank you very much.