Solved

Getting the columns data type

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

760 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

25 Experts available now in Live!

Get 1:1 Help Now