DB2 ingest of decimal data from csv

220 views Asked by At

i am looking for a db2 method to import a .csv file (IMPORT.CSV) like this:

2020-01-01;1.234.567,12345

in the a DB2 table MY_TABLE:

CREATE TABLE
    MY_TABLE
    (
        DTRIF DATE,
        SALDO DECIMAL(18,5)
    );

i tried "INGEST" method:

INGEST FROM FILE IMPORT.CSV FORMAT DELIMITED
  (
      $data date,
      $decimale char(18)
   ) 
   INSERT INTO MY_TABLE(dtrif,saldo)
      VALUES( 
        $data, 
        CAST(REPLACE(REPLACE($decimale, '.', ''), ',', '.') AS DECIMAL(18,5))
   );

but the result is:

    DTRIF      SALDO
2020-01-01 12345.00000 

why?

1

There are 1 answers

0
mao On

The following works correctly for me (other variations are possible) with Db2-LUW v11.1.4.5:

INGEST FROM FILE ... FORMAT DELIMITED BY ';'
  (
      $data date,
      $decimale char
  )
   INSERT INTO ... (dtrif,saldo)
      VALUES( $data
            , CAST(REPLACE(REPLACE($decimale, '.', ''), ',', '.') AS DECIMAL(18,5)));