DECIMAL is declared in the package SYS.STANDARD as a subtype of NUMBER (as are most numeric types in Oracle), specifically as NUMBER(38, 0), which means that DECIMAL values are not able to have digits to the right of the decimal point. In order to have DECIMAL values with numbers to the right of the decimal point they have to be declared as such, similar to
dValue DECIMAL(38, 4)
However, this won't help if you want to return such a value from a function, because you can't have precision specifiers on a function return type.
In order to have a DECIMAL value with digits to the right of the decimal place returned from a function you need to declare a subtype of DECIMAL that specifies the correct number of decimal places and use that subtype as the return type of your function. Here's an example:
DECLARE
SUBTYPE DEC_10_3 IS DECIMAL(10, 3);
FUNCTION TEST1 RETURN DECIMAL
IS
d DECIMAL := 1/3;
BEGIN
RETURN d;
END TEST1;
FUNCTION TEST2 RETURN DECIMAL
IS
d DECIMAL(10, 3) := 1/3;
BEGIN
RETURN d;
END TEST2;
FUNCTION TEST3 RETURN DEC_10_3 IS
d DEC_10_3 := 1/3;
BEGIN
RETURN d;
END TEST3;
BEGIN
-- Test statements here
DBMS_OUTPUT.PUT_LINE('TEST1=' || TEST1);
DBMS_OUTPUT.PUT_LINE('TEST2=' || TEST2);
DBMS_OUTPUT.PUT_LINE('TEST3=' || TEST3);
END;
Running the above will produce
TEST1=0
TEST2=0
TEST3=.333
Share and enjoy.