Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Getting the columns data type

Posted on 2001-06-04
3
Medium Priority
?
4,246 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 200 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
Suggested Courses

916 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