Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2003
    Posts
    1

    Unanswered: 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

  2. #2
    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

  3. #3
    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

    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

  4. #4
    Join Date
    Jan 2003
    Posts
    1,605
    Hi,

    You can also use: DESCRIBE TABLE schema.table_name.

    Hope this helps,
    Grofaty

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •