I want to test one of my functions in oracle pl/sql using DBMS_OUTPUT.PUT_LINE. The problem I encounter is, that when I write a point number inside my function, I get the following error:
Error
ORA-06502: PL/SQL: numerischer oder Wertefehler: Fehler beim Konvertieren von Zeichen zu Zahl
ORA-06512: in Zeile 4 // line 4 is "v_net := pricecalculator(120.09)"
06502. 00000 - "PL/SQL: numeric or value error%s"
*Cause: An arithmetic, numeric, string, conversion, or constraint error
occurred. For example, this error occurs if an attempt is made to
assign the value NULL to a variable declared NOT NULL, or if an
attempt is made to assign an integer larger than 99 to a variable
declared NUMBER(2).
*Action: Change the data, how it is manipulated, or how it is declared so
that values do not violate constraints.
This works
CREATE OR REPLACE FUNCTION Pricecalculator(net IN NUMBER, vat IN NUMBER DEFAULT 0.19)
RETURN NUMBER
IS
Result NUMBER;
BEGIN
Result := net * (1 + vat);
RETURN Result;
END;
/
SET SERVEROUTPUT ON
DECLARE
v_net NUMBER;
BEGIN
v_net := Pricecalculator(120);
DBMS_OUTPUT.PUT_LINE(v_net); // Prints (142.8)
END;
/
This does not work (see error)
SET SERVEROUTPUT ON
DECLARE
v_net NUMBER;
BEGIN
v_net := Pricecalculator(120.09);
DBMS_OUTPUT.PUT_LINE(v_net); // When I delete this, v_net gets compiled but I wont see the result
END;
/
I am new to oracle pl/sql and have zero clue why the second approach does not work.
DBMS_OUTPUT.PUT_LINE(v_net)is shown greyNLS_NUMERIC_CHARACTERS. The database seems with dot decimal separator, i guess your client is going for comma decimal separator. Tryv_net := Pricecalculator(120,09);in your PLSQL client bloc.Pricecalculator(120, 09), because then I would just change thevatparameter to 9 and the output would be 1200Pricecalculator(120,09)will see that as two arguments,netof 120 andvatof 9. But you're right that it's that setting that's breaking it... in SQL Developer, at least.