Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problems of four kinds of databases PMSO in accuracy calculation

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to solve the problem of PMSO in precision calculation of 4 databases. The content is concise and easy to understand. It will definitely make your eyes shine. I hope you can gain something from the detailed introduction of this article.

1 Oracle calculation, different positions of the calculation will cause different final results of the problem, see the following figure

2 The official answer is that direct computation returns floating point arithmetic without rounding in IEEE 754 fashion.

3 The correct calculation method recommended by the official is to add the to_number method to perform the relevant numerical calculation.

In rounding calculations, the values obtained in this way will not have different values as above.

Existence.

4 Such questions do not exist in SQL SERVER, the answer is yes, and more difficult to do

First of all, we copy the calculation above. It is clear from the figure that the result is different from ORACLE.

Let's do it the way we do it, let's do it the same way ORACLE does it, and see what happens.

The result is different from ORACLE, even if double precision numbers are used for calculation, it still causes different calculation order and different values.

There are two ways to solve this problem.

Method 1: Add more reserved bits. As we can see in the figure, the results are consistent, but I think many students who develop will not be satisfied.

Method 2 uses menoy type to transform, the result is consistent

What if this happens in a MYSQL database?

The same problem exists in MYSQL.

MYSQL is handled slightly differently here. Although we added decimal, if we still keep 2 decimal places, the result is still incorrect. If we keep one more digit than the required value, the result will be consistent.

Finally, how does PostgreSQL do the following

Among the many databases, only POSTGRESQL gives the truth of the matter, and the results of different calculations are different in different orders.

In Postgresql, the equation can be modified in a similar way to MYSQL, and both calculations get the same result.

The above content is how to solve the problem of PMSO in precision calculation of 4 databases. Have you learned knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report