• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4411
  • Last Modified:

Getting the columns data type

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
eric07
Asked:
eric07
1 Solution
 
whbramCommented:
Try uppercase

SELECT data_type
FROM   all_tab_columns
WHERE  table_name = 'TBLSECURITYACCESS';
0
 
dbalaskiCommented:
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
 
eric07Author Commented:
Thanks guys. That really helped allot.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now