Solved

Getting the columns data type

Posted on 2001-06-04
3
3,782 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

679 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