If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > What is the SQL query to find the datatype of a column in a table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-14-03, 02:41
ajathsatru ajathsatru is offline
Registered User
 
Join Date: Nov 2003
Posts: 1
What is the SQL query to find the datatype of a column in a table

Hi,

I want to find the datatype of a particular field in a table. I want to process my code based on this datatype.

i.e.

if(datatype is varchar32)
{
// do something
}
else
{
// do something
}

DESC <tablename> gives me the schema in case of mysql and iam able to find the datatype by using resultset.getString("TYPE")

But DESC tablename or DESCRIBE tablename doesnot work in oracle.
Is there a genric SQL query common for all databases

Also is it possible to find the columns names of a schema.

i.e in case of mysql "FIELD" denotes the column name. But in case of ORACLE "NAME" denotes the column name.

Please help me
Reply With Quote
  #2 (permalink)  
Old 11-14-03, 03:21
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
You're going to have to do this at the application level rather than the database. Your drivers should take care of any cross database anomalies. If you are using Java, you could look at the 'DatabaseMetaData' interface.

HTH
Reply With Quote
  #3 (permalink)  
Old 11-14-03, 06:12
jsander jsander is offline
Registered User
 
Join Date: Apr 2003
Posts: 191
Re: What is the SQL query to find the datatype of a column in a table

Hi,

have a look at the view SYSCAT.COLUMNS, if you are on Windows or Unix.

Johann

Quote:
Originally posted by ajathsatru
Hi,

I want to find the datatype of a particular field in a table. I want to process my code based on this datatype.

i.e.

if(datatype is varchar32)
{
// do something
}
else
{
// do something
}

DESC <tablename> gives me the schema in case of mysql and iam able to find the datatype by using resultset.getString("TYPE")

But DESC tablename or DESCRIBE tablename doesnot work in oracle.
Is there a genric SQL query common for all databases

Also is it possible to find the columns names of a schema.

i.e in case of mysql "FIELD" denotes the column name. But in case of ORACLE "NAME" denotes the column name.

Please help me
Reply With Quote
  #4 (permalink)  
Old 11-15-03, 10:20
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,

You can also use: DESCRIBE TABLE schema.table_name.

Hope this helps,
Grofaty
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On