Solved

SQL Script to List Table Columns

Posted on 2008-06-19
5
4,119 Views
Last Modified: 2013-12-19
Recently purchased an ERP system that uses Oracle 9.2.0.6.  The system includes a data dictionary and an interface to write SQL scripts.  I would like to write 2 SQL scripts:

1.  Script that lists all of the column/field names in a single table
2.  Script that lists all of the column/field names in all of the tables.

The scripts will then be used in Crystal Reports to assist me in finding columns(fields).

Regards,
Gary
0
Comment
Question by:pcguru_gary
5 Comments
 
LVL 14

Expert Comment

by:ajexpert
ID: 21826423

--To list all columns for given table

SELECT * FROM USER_TAB_COLS

WHERE TABLE_NAME = '<table_name>'

--to list all columns in all tables

SELECT * FROM USER_TAB_COLS

Open in new window

0
 
LVL 100

Expert Comment

by:mlmcc
ID: 21827389
How do you plan to use them in a report?

mlmcc
0
 

Author Comment

by:pcguru_gary
ID: 21830505
ajexpert provided the script that works.  mlmcc asked an important follow up question: How do I plan to use them in a report?  Because the output from the SQL statement in Data Dictionary prints to screen only and cannot be exported, I need to create a formula in CR that can then be exported to Excel.  The table/column listing would then be easy to search on for specific column names.  

So the question is:  How do I create a CR from scratch using the script that ajexpert provided?  

Note: I increased the point value and will split them.

Regards,
Gary
0
 
LVL 22

Accepted Solution

by:
DrSQL earned 500 total points
ID: 21831140
Gary,
    If you have sqlplus as part of your ERP system, then you can "spool" the data to a file.  Also, you can search the dictionary,just like any other Oracle table.

To spool a file of all tables and all columns to which you have access:

set lines 2000
set pages 0
set heading on
set trimspool on
select * from all_tab_columns
spool tabledefs.txt
/
spool off

To search for a particular column in YOUR schema:
select table_name,column_name from user_tab_columns
where column_name like '%CREDIT%';

Here's a link to all of the views available to you: http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_part.htm#REFRN002

Good luck!
0
 
LVL 22

Expert Comment

by:DrSQL
ID: 22088396
Gary,
    It's been over a month.  Could you please update/close this question?  Thank you for using Experts Exchange.

Good luck!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
EXECUTE IMMEDIATE 5 53
grouping on time windows 6 43
Oracle 12c database link between pdb not working 20 48
Shredding xml into an oracle 11g Database 2 31
Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now