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 > Is it possible to query the data type of a column?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-21-06, 06:00
zony zony is offline
Registered User
 
Join Date: Feb 2006
Posts: 4
Question Is it possible to query the data type of a column?

Hello, I have to evaluate the data types of various columns in a table (with Perl/DBI), is that possible with an SQL statement? My last option would be exporting the table structure and parsing it but if there's something easier...

Thanks in advance.
Reply With Quote
  #2 (permalink)  
Old 02-21-06, 06:47
przytula przytula is offline
Registered User
 
Join Date: Nov 2004
Posts: 374
coltype

look at sysibm.syscolumns
NAME SYSIBM VARCHAR 128 0 No
TBNAME SYSIBM VARCHAR 128 0 No
TBCREATOR SYSIBM VARCHAR 128 0 No
REMARKS SYSIBM VARCHAR 254 0 Yes
COLTYPE SYSIBM CHARACTER 8 0 No

select name,coltype from sysibm.syscolumns where tbname='xxx' and tbcreator='yy'
__________________
Best Regards, Guy Przytula
DB2/ORA/SQL Services
DB2 DBA & Advanced DBA Certified
DB2 Dprop Certified
http://users.skynet.be/przytula/dbss.html
Reply With Quote
  #3 (permalink)  
Old 02-21-06, 06:52
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
or SYSCAT.COLUMNS view ...
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #4 (permalink)  
Old 02-21-06, 08:00
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
SELECT TYPENAME, LENGTH, SCALE FROM SYSCAT.COLUMNS WHERE TABSCHEMA='SCHEMA_NAME' AND TABNAME='TABLE_NAME'

Replace SCHEMA_NAME with your table schema
Replace TABLE_NAME with your table name
Reply With Quote
  #5 (permalink)  
Old 02-21-06, 08:05
zony zony is offline
Registered User
 
Join Date: Feb 2006
Posts: 4
Thanks for all your replies. The suggestion from przytula works perfectly.
Reply With Quote
  #6 (permalink)  
Old 02-21-06, 08:35
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
IIRC, IBM's recommendation is to use the Catalog views (Schema SYSCAT) in preference to the Catalog Tables(SYSIBM)

Cheers
Sathyaram
__________________
Visit the new-look IDUG Website , register to gain access to the excellent content.
Reply With Quote
  #7 (permalink)  
Old 02-21-06, 09:07
zony zony is offline
Registered User
 
Join Date: Feb 2006
Posts: 4
Another similar problem, this time with Cloudscape. I managed to get the data types of the table columns with the following SQL query:

Code:
SELECT c.columnname, c.columndatatype FROM sys.syscolumns c,sys.systables t 
  WHERE c.referenceid = t.tableid AND t.tablename = '<TABLE>'
This works so far except for the fact that the output is sorted alphabetically. Anybody knows whether it's possible to view the data types on Cloudscape in the order they appear in the table (which is the default on DB2 UDB)? Thanks.
Reply With Quote
  #8 (permalink)  
Old 02-21-06, 09:25
zony zony is offline
Registered User
 
Join Date: Feb 2006
Posts: 4
Figured it out, I found a table reference and "ORDER BY c.columnnumber" fixed it.
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