Home sql How to check with a SQL query that the field has a...

How to check with a SQL query that the field has a specified rounding?

Author

Date

Category

What kind of request to verify that the values ​​in the column are rounded, for example, up to 3 characters after the comma? Or back request that there are no values ​​other than the three-disconnect rounding.


Answer 1, Authority 100%

Check with a SQL query that the field has a specified rounding

If there is a table field, then

select column_name,
    Data_Type,
    numeric_precision,
    numeric_scale
From information_schema.columns.
Where Table_schema = 'Database'
 And table_name = 'Table'
 And data_type in ('Decimal', 'Float', 'Double');

If it is about the field in a certain data set – then in general, no way.

How can you paint the string using the query and calculate the decimal characters

(Locate (1.1 FROM 2 FOR 1), Field) & gt; 0) * Length (SUBSTRING_INDEX (field , SUBSTRING (1.1 FROM 2 FOR 1), -1))

If you are convinced that the forts with the decimal separator are not expected, then simply

(Locate (', Field) & gt; 0) * Length (Substring_index (Field,'. ' -1))

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions