Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 406
user917670 Avatar asked Sep 06 '11 10:09

user917670


People also ask

How do I get decimal points in SQL?

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.

How do I select just the decimal value in SQL?

X - TRUNC(X), works for negatives too. It would give you the decimal part of the number, as a double, not an integer.

How do I find the size of a column in SQL?

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.


1 Answers

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>'
like image 157
Baz1nga Avatar answered Nov 13 '22 03:11

Baz1nga