sqlsql-serveroracle-databasedelphi-xenls-lang

Insert/Update SQL queries for decimal separator comma in NLS_NUMERIC_CHARACTERS


I need to create bulk insert/update queries for which it is necessary to pass ORACLE SQL queries in string format, and I cannot use parametrized queries, because of some performance issue in SQL query string parsing in Delphi.

My concern is, while creating these queries and passing float values, should I be concerned about the NLS_NUMERIC_CHARACTERS of the Database? For now I am passing my queries as:

   "INSERT ALL
    INTO TABLE EMPLOYEE (EMP_ID, EMP_SAL) VALUES (123, 123.123)
    INTO TABLE EMPLOYEE (EMP_ID, EMP_SAL) VALUES (345, 345.345)
    INTO TABLE EMPLOYEE (EMP_ID, EMP_SAL) VALUES (456, 456.456)
    SELECT * FROM DUAL"

Should I read the value of NLS_NUMERIC_CHARACTERS instead and then fire the following bulk query if decimal separator is ',', or is this handled by the DB server?

   "INSERT ALL
    INTO TABLE EMPLOYEE (EMP_ID, EMP_SAL) VALUES (123, '123,123')
    INTO TABLE EMPLOYEE (EMP_ID, EMP_SAL) VALUES (345, '345,345')
    INTO TABLE EMPLOYEE (EMP_ID, EMP_SAL) VALUES (456, '456,456')
    SELECT * FROM DUAL"

How should the implementation be for SQL server?


Solution

  • NLS_NUMERIC_CHARACTERS is only used when converting strings (varchar) to numbers or numbers to strings. It doesn't matter if the conversion is implicit (as in your second example) or explicit when using to_char() or to_number().

    Plain SQL number literals (=constants) always use the . as the decimal separator. A number like 123.123 will always be treated correctly regardless of the value of NLS_NUMERIC_CHARACTERS - this is also true for SQL Server.

    It's not clear to me what you mean with "the implementation be for SQL server". If it's about the insert statement inserting more than a single row, then the equivalent in SQL Server (and standard SQL) would be:

    INSERT INTO EMPLOYEE 
      (EMP_ID, EMP_SAL) 
    VALUES 
      (123, 123.123),
      (345, 345.345),
      (456, 456.456);