MySQL queries the number of decimal places

Source: Internet
Author: User

How do I query a field for a few small numbers?

MySQL database:

Through the following SQL can be found out, there are 2 col*100, there are 3 col*1000, one analogy;

Select *  from where real_quantity*-Floor (real_quantity*1000  >0

Note: Floor: The function returns only the integer part, and the fractional part is discarded.

Oracle Database:

Select LTrim ('124532.62879'-Floor ('124532.62879'), ' 0.' from dual; Select Length (66695 from dual;

With these two SQL combinations, you can find out the number of decimal places in the back part of the dotted line, classic in Oracle, and practical!

The following approach is also Classic (recommended):

For example, a field with a table is number (10,4), but most of it is 3 decimal places, how to query the results of 4 decimal places:

Select *  from where (Col- trunc (col,3<>0  ; Select Length ('21221.3410'- InStr ('  21221.3410','. '  from dual;

Finally, I summarize the following sql:

---query where the decimal point is located

Select InStr ('12563.26530','. '  from dual;


---query decimal parts

Select substr ('12563.26530', InStr ('12563.26530', ' . ') + 1  from dual;


---Query the length of a fractional part

Select Length (substr ('12563.26530', InStr ('12563.26530  ','. ') + 1  from dual;

MySQL queries the number of decimal places

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.