Rechercher dans le manuel MySQL
12.6.1 Arithmetic Operators
The usual arithmetic operators are available. The result is determined according to the following rules:
In the case of
-
,+
, and*
, the result is calculated withBIGINT
(64-bit) precision if both operands are integers.If both operands are integers and any of them are unsigned, the result is an unsigned integer. For subtraction, if the
NO_UNSIGNED_SUBTRACTION
SQL mode is enabled, the result is signed even if any operand is unsigned.If any of the operands of a
+
,-
,/
,*
,%
is a real or string value, the precision of the result is the precision of the operand with the maximum precision.In division performed with
/
, the scale of the result when using two exact-value operands is the scale of the first operand plus the value of thediv_precision_increment
system variable (which is 4 by default). For example, the result of the expression5.05 / 0.014
has a scale of six decimal places (360.714286
).
These rules are applied for each operation, such that nested
calculations imply the precision of each component. Hence,
(14620 / 9432456) / (24250 / 9432456)
,
resolves first to (0.0014) / (0.0026)
, with
the final result having 8 decimal places
(0.60288653
).
Because of these rules and the way they are applied, care should be taken to ensure that components and subcomponents of a calculation use the appropriate level of precision. See Section 12.10, “Cast Functions and Operators”.
For information about handling of overflow in numeric expression evaluation, see Section 11.2.6, “Out-of-Range and Overflow Handling”.
Arithmetic operators apply to numbers. For other types of
values, alternative operations may be available. For example, to
add date values, use DATE_ADD()
;
see Section 12.7, “Date and Time Functions”.
Addition:
- -> 8
Subtraction:
- -> -2
Unary minus. This operator changes the sign of the operand.
- -> -2
Multiplication:
- -> 15
- -> 324518553658426726783156020576256.0
- -> out-of-range error
The last expression produces an error because the result of the integer multiplication exceeds the 64-bit range of
BIGINT
calculations. (See Section 11.2, “Numeric Types”.)Division:
- -> 0.60
Division by zero produces a
NULL
result:A division is calculated with
BIGINT
arithmetic only if performed in a context where its result is converted to an integer.Integer division. Discards from the division result any fractional part to the right of the decimal point.
If either operand has a noninteger type, the operands are converted to
DECIMAL
and divided usingDECIMAL
arithmetic before converting the result toBIGINT
. If the result exceedsBIGINT
range, an error occurs.Modulo operation. Returns the remainder of
N
divided byM
. For more information, see the description for theMOD()
function in Section 12.6.2, “Mathematical Functions”.
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 26/06/2006, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/mysql-rf-arithmetic-functions.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor Diese Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.