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.
select length( substr( cast(Column as text), instr(cast(Column as text), '. ')+1 ) ) as "Column-precision" from "Table"; The code will cast the column as text, then get the index of a period ( . ) in the text, and fetch the substring from that point on to the end of the text.
X - TRUNC(X), works for negatives too. It would give you the decimal part of the number, as a double, not an integer.
Use COL_LENGTH() to Get a Column's Length in SQL Server In SQL Server, you can use the COL_LENGTH() function to get the length of a column. More specifically, the function returns the defined length of the column, in bytes. The function accepts two arguments: the table name, and the column name.
for sql server:
select precision from sys.columns where name='<column_name>'
for oracle:
select data_precision from all_tab_columns where column_name = '<columnName>'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With