Solved

Getting the columns data type

Posted on 2001-06-04
3
3,846 Views
Last Modified: 2008-03-17
I want to do a sql statement in sql plus to get the column names and the data types in a particular table?

Not sure how to do this:

SELECT data_type
FROM   all_tab_columns
WHERE  table_name = 'tblSecurityAccess';

tried this but returns nothing.

Any ideas?
0
Comment
Question by:eric07
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 1

Accepted Solution

by:
whbram earned 50 total points
ID: 6154791
Try uppercase

SELECT data_type
FROM   all_tab_columns
WHERE  table_name = 'TBLSECURITYACCESS';
0
 
LVL 9

Expert Comment

by:dbalaski
ID: 6154837
Hi,

I am going to guess the problem is in the case of the table_name in the where clause,
Oracle is case insensative unless the tablename was placed in double-quotes when created -- so you should use upper case.
you might try to re-write your query with upper clauses to ensure the case is found correctly:
SELECT data_type
   FROM   all_tab_columns
    WHERE  upper(table_name) ='TBLSECURITYACCESS';

A better query would be the following (it is actual output against the SCOTT.EMP  demo table):
  1  select TABLE_NAME,COLUMN_NAME,DATA_TYPE,
  2         DATA_LENGTH ,DATA_SCALE,DATA_PRECISION
  3  from all_tab_columns
  4  where owner='SCOTT'
  5  and TABLE_NAME='EMP'
  6* order by owner,TABLE_NAME,COLUMN_ID
SQL> /

TABLE_NAME COLUMN_NAME  DATA_TYPE DATA_LENGTH DATA_SCALE DATA_PRECISION
---------- ------------ --------- ----------- ---------- --------------
EMP        EMPNO        NUMBER             22          0              4
EMP        ENAME        VARCHAR2           10
EMP        JOB          VARCHAR2            9
EMP        MGR          NUMBER             22          0              4
EMP        HIREDATE     DATE                7
EMP        SAL          NUMBER             22          2              7
EMP        COMM         NUMBER             22          2              7
EMP        DEPTNO       NUMBER             22          0              2

8 rows selected.

It shows a bit more information about the columns,  such as in the columns in the proper order,  length of the columns.  Plus  scale & precision are for numbers...

Hope this solves your problem and answers your questions and gives you a better query to use..
sincerely,
dBalaski
0
 

Author Comment

by:eric07
ID: 6155236
Thanks guys. That really helped allot.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ORA-02288: invalid OPEN mode 2 129
pivot rows to columns 1 60
Errror when importing data from Oracle to SQL 6 67
C# Web service insert into Oracle table 8 39
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…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

734 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