开发者

What are the boundary values of x and y in DECIMAL(x, y) in MySQL datatype declaration?

I have got the following UDF

drop function if exists getCurrency$$

create function getCurrency(dt datetime, x decimal(19,4), y decimal(19, 4)) 
returns decimal(10,4) reads sql data
begin
     declare currencyval decimal(10,4);

     /* Some conditions */
     select case when dt = "2000-12-31" then 0 else round((x/y), 4) into currencyval;

     return currencyval;
end$$

Sometimes this UDF throws Data truncation error. I can resolve the issue but t开发者_如何学Che before even that I want some information regarding the Decimal data type and the significance of 10, 4 in the parameters.

It would be good if you give some examples with the boundary conditions.


10, 4 means 6 digits (integer part) before point and 4 after (fractional part).

So the biggest possible number you can return is 999999.9999

In your particular case it is not possible to say what values are boundary for x and/or y, but you can check if the return value (currencyval) is out of -999999.9999 .. 999999.9999 range.

Btw, if you're asking about x and y in DECIMAL (x, y) records, then:

  • x = 1..65
  • y = 0..30 && y <= x

References:

  • MySQL 5.7 Reference Manual :: 11.2.2 Fixed-Point Types (Exact Value) - DECIMAL, NUMERIC
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜