Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8487497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:15:34+00:00 2026-06-10T21:15:34+00:00

Is there any setting or method I can use to get Oracle to return

  • 0

Is there any setting or method I can use to get Oracle to return results in <table>.<column> format? For example:

Query:

SELECT     *
FROM       foo f
INNER JOIN bar b
ON         b.foo_id = f.id

Desired results:

F.ID  F.BLAH  B.ID  B.FOO_ID  B.BLAH
--------------------------------------------------------
1     blah    7     1         blah
2     blah    8     2         blah
3     blah    9     2         blah

The obvious solution is to individually alias each column SELECT f.id AS F_ID, ...; however, I’m needing to export some very large legacy tables (300+ columns), so using this method would cause the queries to be enormous and impractical.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:15:36+00:00Added an answer on June 10, 2026 at 9:15 pm

    There is no “option” in Oracle to do this; you may be able to find a client that allows you to do so as this is a job that would normally be done in the client; I don’t know of one.

    To expand upon tbone’s answer you’re going to have to do this dynamically. This does not mean that you have to list every column. You would use the data dictionary, specifically all_tab_columns or user_tab_columns to create your query. It would be easier to create a view with the exact definition you want so that you can re-use it if you want.

    The aim is to use the fact that the columns existence is stored in a table as a string in order to create a query to use that column. As the column names and table names are stored as strings you can use string aggregation techniques to easily create a query or DDL statement that you can then manually, or dynamically, execute.

    If you’re using Oracle 11g Release 2 the listagg function is available to help you:

    select 'create or replace view my_view as 
            select '
          || listagg( table_name || '.' || column_name 
                   || ' as ' 
                   || substr(table_name,1,1) || '_' 
                   || column_name, ', ')
            within group 
             ( order by case when table_name = 'FOO' then 0 else 1 end
                      , column_id
              )
           || ' from foo f
                join bar b
                  on f.id = b.foo_id'
      from user_tab_columns
     where table_name in ('FOO','BAR')
            ;
    

    Assuming this table structure:

    create table foo ( id number, a number, b number, c number);
    create table bar ( foo_id number, a number, b number, c number);
    

    This single query produces the following:

    create or replace view my_view as 
     select FOO.ID as F_ID, FOO.A as F_A, FOO.B as F_B, FOO.C as F_C
          , BAR.FOO_ID as B_FOO_ID, BAR.A as B_A, BAR.B as B_B, BAR.C as B_C 
       from foo f 
       join bar b on f.id = b.foo_id
    

    and here’s a SQL Fiddle to prove it.

    In you’re not using 11.2 you can achieve exactly the same results using the undocumented function wm_concat or the user-defined function stragg, which was created by Tom Kyte. Oracle Base has an article on string aggregation techniques and there are many posts on Stack Overflow.

    As a little addendum you can actually create exactly what you’re looking for with a small change to the above query. You can use a quoted identifier to create a column in the TABLE_NAME.COLUMN_NAME format. You have to quote it as . is not a valid character for an object name in Oracle. The benefit of this is that you gain exactly what you want. The downside is that querying the created view is a huge pain if you don’t use select * from ...; selecting named columns will require them to be quoted.

    select 'create or replace view my_view as
            select '
          || listagg( table_name || '.' || column_name 
                   || ' as ' 
                   || '"' || table_name || '.'
                   || column_name || '"', ', ')
            within group 
             ( order by case when table_name = 'FOO' then 0 else 1 end
                      , column_id
              )
           || ' from foo f
                join bar b
                  on f.id = b.foo_id'
      from user_tab_columns
     where table_name in ('FOO','BAR')
            ;
    

    This query returns:

    create or replace view my_view as 
     select FOO.ID as "FOO.ID", FOO.A as "FOO.A", FOO.B as "FOO.B", FOO.C as "FOO.C"
          , BAR.FOO_ID as "BAR.FOO_ID", BAR.A as "BAR.A"
          , BAR.B as "BAR.B", BAR.C as "BAR.C"
       from foo f 
       join bar b on f.id = b.foo_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to extract the path c:/documents and settings/user using Java... Is there any method??
Is there any way of setting up a simple bash script such as chmod
Is there any possibility to extract globalize2 translation for specified locale without setting I18n.locale
I am setting up Jenkins for automating iOS builds. Are there any possibility to
I am getting problem while setting up Session cookie using jersey. is there any
Is there any way to change settings for multiple projects in a Visual Studio
Is there any way to change the Facebook album privacy settings with graph api
Is there any way to access the iPhone/iPod touch settings programatically ? Thanks. Biranchi
Is there any way to set/update values in the settings.bundle from within your app.
Is there any functional difference in Python between a try statement and an if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.