• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to get table name from oracle query?

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I want to get table name and column name from query. i got column name. but i didn't get table name from the query. Please help me
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From your post not really sure what you want to achieve. You may need to check dba_tables?
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vijay Panner wrote:Hi,
I want to get table name and column name from query. i got column name. but i didn't get table name from the query. Please help me


I suppose that you've run a SQL query and are reading it using a resultset, and you're trying to obtain column and table names from the resultset.

The resultset does not contain column's table names, generally because it is not always possible to assign a table to a column in resultset. Consider this:

Which table do columns A and B come from? And while the column C comes clearly from table T1, that table actually might not have a column named C at all.

If you're interested just in a set of tables a query uses, it might be possible to extract this information from the text of the SQL query. However, you'd need to parse the query according to the SQL syntax of the target database to do this for arbitrary SQL queries, which seems like a lot of work to me.
 
Greenhorn
Posts: 24
Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assume that you are using JDBC statement to process your sql query.Then,from the resultset you can get the resultsetMetadata which contains all the info about it i.e. Table names,Column Names number of columns retrieved,etc.You can use its object to get whatever you need.For eg:


There is no need for a sql parser if ResultSetMetadata can fullfill you need..but it has one limitation as it will fetch table name related to each column...
 
Where does a nanny get ground to air missles? Protect this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic