Skip to content
Advertisement

SQL query to get the precision value of a column

I need a sql query that gets the precision value for certain columns.. I am mainly concerned with a decimal type column and I need the precision value for the same.

I realise that it is possible to do so in certain versions and vendors of database servers. It would be nice if you could list down for a few of them.

Advertisement

Answer

Oracle:

SELECT DATA_LENGTH, DATA_PRECISION
FROM ALL_TAB_COLUMNS
WHERE TABLE_NAME = :TableName
AND COLUMN_NAME = :ColumnName

Firebird (+ Interbase) :

SELECT
       rdb$field_scale,
       rdb$field_precision
FROM   rdb$relations r
       JOIN rdb$relation_fields rf
         ON rf.rdb$relation_name = r.rdb$relation_name
       JOIN rdb$fields fld
         ON rf.rdb$field_source = fld.rdb$field_name
WHERE  r.rdb$relation_name = :TableName
       AND rf.rdb$field_name = :ColumnName

MySql (Not Tested !) :

SELECT
  NUMERIC_PRECISION,  NUMERIC_SCALE
FROM
  INFORMATION_SCHEMA.COLUMNS
WHERE
  TABLE_NAME  = :TableName AND
  COLUMN_NAME = :ColumnName
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement