简体   繁体   中英

ORA-06502: PL/SQL: numeric or value error when using TO_BINARY_DOUBLE with JDBC

I have a small snippet of code that grabs some data and generates SQL statements to insert them in an Oracle database. These are then executed via a JDBC driver on the Oracle server.

The issue I am running into is that if these statements contain a TO_BINARY_DOUBLE call they always fail for me and not for anyone else in my team, which supposedly have the exact same driver and environment as I do, which is incredibly strange.

CREATE TABLE "SOME_TABLE" (
    "_id" BINARY_DOUBLE NOT NULL,
    "double" BINARY_DOUBLE,
    PRIMARY KEY ("_id")
);

DECLARE
    "#value__id" BINARY_DOUBLE;
    "#value_double" BINARY_DOUBLE;
BEGIN
    "#value__id" := TO_BINARY_DOUBLE('0.0');
    "#value_double" := TO_BINARY_DOUBLE('1.2');

    INSERT INTO "SOME_TABLE" ("_id", "double")
    VALUES(
        "#value__id",
        "#value_double"
);
END;

And the error:

Unable to execute SQL statement batch: error occurred during batching: ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 5

Hoping someone could shed some light on the source, or point me in the right direction to try find it.

You appear to have different NLS settings to your colleagues; specifically NLS_NUMERIC_CHARACTERS . With that set to '.,' the code works; with it set to ',.' (ie expecting a comma as the decimal separator, rather than a period) it throws the error you see.

You can either change your Java environment to match your colleagues', which will probably involve changing the locale, either of your PC or via JVM flags; or override it in the function call:

    "#value__id" := TO_BINARY_DOUBLE('0.0', '999D999', 'nls_numeric_characters=''.,''');
    "#value_double" := TO_BINARY_DOUBLE('1.2', '999D999', 'nls_numeric_characters=''.,''');

using a format mask that covers whatever string values you might have to deal with - I'm guessing that those values would normally come from a user or a procedure argument. Of course, this then assumes that the string values will always have a period as the decimal separator.

db<>fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM