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
精彩评论