Home > Net >  INVALID NUMBER ORA-01722 with correct Data
INVALID NUMBER ORA-01722 with correct Data

Time:12-27

ERROR OF THE LOG AFTER EXECUTE SQLDRI'm trying to insert numeric values in a field, but I'm getting the same error all the time INVALID NUMBER ORA-01722. I don't know where is the error because I'm inserting decimal number declared as NUMBER (18,6) for field IMP_NPVFRONT and the value is casted to this length, but it isn't working. I'm using this code:

echo "OPTIONS (SKIP=1)" >> $TEPR_NFICHCONTROLCTL
echo "LOAD DATA" >> $TEPR_NFICHCONTROLCTL
echo "APPEND" >> $TEPR_NFICHCONTROLCTL
echo "INTO TABLE TERM.TTERMNZI" >> $TEPR_NFICHCONTROLCTL
echo "FIELDS TERMINATED BY ';' ">> $TEPR_NFICHCONTROLCTL
echo "OPTIONALLY ENCLOSED BY '\"' " >> $TEPR_NFICHCONTROLCTL
echo "TRAILING NULLCOLS" >> $TEPR_NFICHCONTROLCTL
echo "(" >> $TEPR_NFICHCONTROLCTL
echo " COD_CURRPL CHAR NULLIF COD_CURRPL=\"\"," >> $TEPR_NFICHCONTROLCTL
echo " COD_IDINST INTEGER EXTERNAL," >> $TEPR_NFICHCONTROLCTL
echo " COD_COUNTER CHAR NULLIF COD_COUNTER=\"\"," >> $TEPR_NFICHCONTROLCTL
echo " XTI_INTERNA CHAR NULLIF XTI_INTERNA=\"\"," >> $TEPR_NFICHCONTROLCTL
echo " COD_PRTFOLIO CHAR NULLIF COD_PRTFOLIO=\"\",">> $TEPR_NFICHCONTROLCTL
echo " COD_FAMILY CHAR NULLIF COD_FAMILY=\"\"," >> $TEPR_NFICHCONTROLCTL
echo " COD_GRUPO CHAR NULLIF COD_GRUPO=\"\"," >> $TEPR_NFICHCONTROLCTL
echo " COD_TIPOPER CHAR NULLIF COD_TIPOPER=\"\"," >> $TEPR_NFICHCONTROLCTL
echo " FEC_EXPIRY DATE \"DD/MM/RRRR\"," >> $TEPR_NFICHCONTROLCTL
echo " COD_STATUS CHAR NULLIF COD_STATUS=\"\"," >> $TEPR_NFICHCONTROLCTL
echo " FEC_INICIO   DATE \"DD/MM/RRRR\"," >> $TEPR_NFICHCONTROLCTL
echo " COD_INSTRMNT CHAR NULLIF COD_INSTRMNT=\"\"," >> $TEPR_NFICHCONTROLCTL
echo " COD_ENTITY CHAR NULLIF COD_ENTITY=\"\"," >> $TEPR_NFICHCONTROLCTL
echo " IMP_NONFMV CHAR \"to_number(:IMP_NONFMV, '999999999999999999D999999', 'NLS_NUMERIC_CHARACTERS = ''.,''')\"," >> $TEPR_NFICHCONTROLCTL
echo " IMP_CAMBIO CHAR \"to_number(:IMP_CAMBIO, '999999999999999999D999999', 'NLS_NUMERIC_CHARACTERS = ''.,''')\","  >> $TEPR_NFICHCONTROLCTL
echo " COD_APLICFO CHAR,"  >> $TEPR_NFICHCONTROLCTL
echo " IMP_NPVFRONT CHAR \"to_number(:IMP_NPVFRONT,'999999999999999999D999999', 'NLS_NUMERIC_CHARACTERS = ''.,''')\"," >> $TEPR_NFICHCONTROLCTL
echo " FEC_PROCESO \"to_date('$3', 'DD/MM/RRRR')\" ," >> $TEPR_NFICHCONTROLCTL
echo " COD_FICHERIN CONSTANT \"$4\" ," >> $TEPR_NFICHCONTROLCTL
echo " FEC_LOADER SYSDATE ," >> $TEPR_NFICHCONTROLCTL
echo " XTI_ESTADO CONSTANT 0 " >> $TEPR_NFICHCONTROLCTL
echo " )" >> $TEPR_NFICHCONTROLCTL

echo "$TEPR_HLOG Fichero de control $TEPR_NFICHCONTROLCTL generado correctamente"

echo "$TEPR_HLOG Fin Ejecucion de: $TEPR_NSCRIPT"

exit 0

The above produced a control file containing something like this:

OPTIONS (SKIP=1)
LOAD DATA
APPEND
INTO TABLE TERM.TTERMNZI
FIELDS TERMINATED BY ';' 
OPTIONALLY ENCLOSED BY '"' 
TRAILING NULLCOLS
(
 COD_CURRPL CHAR NULLIF COD_CURRPL="",
 COD_IDINST INTEGER EXTERNAL,
 COD_COUNTER CHAR NULLIF COD_COUNTER="",
 XTI_INTERNA CHAR NULLIF XTI_INTERNA="",
 COD_PRTFOLIO CHAR NULLIF COD_PRTFOLIO="",
 COD_FAMILY CHAR NULLIF COD_FAMILY="",
 COD_GRUPO CHAR NULLIF COD_GRUPO="",
 COD_TIPOPER CHAR NULLIF COD_TIPOPER="",
 FEC_EXPIRY DATE "DD/MM/RRRR",
 COD_STATUS CHAR NULLIF COD_STATUS="",
 FEC_INICIO   DATE "DD/MM/RRRR",
 COD_INSTRMNT CHAR NULLIF COD_INSTRMNT="",
 COD_ENTITY CHAR NULLIF COD_ENTITY="",
 IMP_NONFMV CHAR "to_number(:IMP_NONFMV, '999999999999999999D999999', 'NLS_NUMERIC_CHARACTERS = ''.,''')",
 IMP_CAMBIO CHAR "to_number(:IMP_CAMBIO, '999999999999999999D999999', 'NLS_NUMERIC_CHARACTERS = ''.,''')",
 COD_APLICFO CHAR,
 IMP_NPVFRONT CHAR "to_number(:IMP_NPVFRONT,'999999999999999999D999999', 'NLS_NUMERIC_CHARACTERS = ''.,''')",
 FEC_PROCESO "to_date('', 'DD/MM/RRRR')" ,
 COD_FICHERIN CONSTANT "" ,
 FEC_LOADER SYSDATE ,
 XTI_ESTADO CONSTANT 0 
 )

Thank you in advance and sorry for my English :)

CREATE TABLE:

CREATE TABLE TTERMNZI 
(
  COD_IDINST VARCHAR2(150 BYTE) NOT NULL 
, COD_FICHERIN VARCHAR2(20 BYTE) 
, FEC_PROCESO DATE 
, COD_OPERORI VARCHAR2(100 BYTE) 
, XTI_ESTADO NUMBER(1, 0) 
, COD_ESTADO NUMBER(4, 0) 
, COD_PRTFOLIO VARCHAR2(20 BYTE) 
, COD_DEALID VARCHAR2(20 BYTE) 
, COD_EVENT VARCHAR2(20 BYTE) 
, COD_CURRCON VARCHAR2(20 BYTE) 
, COD_COUNTER VARCHAR2(20 BYTE) 
, FEC_ALTA DATE 
, FEC_MATURITY DATE 
, FEC_FRONTVAL DATE 
, FEC_RKVAL DATE 
, IMP_NPVFRNEU NUMBER(18, 6) 
, IMP_NPVBO NUMBER(18, 6) 
, IMP_NPVBOEU NUMBER(18, 6) 
, COD_CURRPL VARCHAR2(4 BYTE) 
, IMP_MVPAGO NUMBER(18, 6) 
, IMP_MVRECIBO NUMBER(18, 6) 
, IMP_MVCONSA NUMBER(18, 6) 
, IMP_MVCONEU NUMBER(18, 6) 
, COD_FAMILY VARCHAR2(20 BYTE) 
, COD_GRUPO VARCHAR2(20 BYTE) 
, COD_STATUS VARCHAR2(8 BYTE) 
, COD_TIPOPER VARCHAR2(4 BYTE) 
, FEC_EXPIRY DATE 
, FEC_INICIO DATE 
, COD_INSTRMNT VARCHAR2(20 BYTE) 
, COD_ENTITY VARCHAR2(20 BYTE) 
, COD_APLICFO VARCHAR2(5 BYTE) NOT NULL 
, FEC_LOADER DATE 
, COD_USUARIO VARCHAR2(5 BYTE) 
, XTI_INTERNA VARCHAR2(1 BYTE) 
, IMP_NONFMV NUMBER(18, 6) 
, IMP_CAMBIO NUMBER(18, 6) 
, IMP_NPVFRONT NUMBER(18, 6) 
, CONSTRAINT CTERMNZI PRIMARY KEY 
  (
    COD_IDINST 
  , COD_APLICFO 
  )
  USING INDEX 
  (
      CREATE UNIQUE INDEX CTERMNZI ON TTERMNZI (COD_IDINST ASC, COD_APLICFO 
ASC) 
      LOGGING 
      TABLESPACE ETERM01 
      PCTFREE 10 
      INITRANS 2 
      STORAGE 
      ( 
        INITIAL 65536 
        NEXT 1048576 
        MINEXTENTS 1 
        MAXEXTENTS UNLIMITED 
        BUFFER_POOL DEFAULT 
      ) 
      NOPARALLEL 
  )
  ENABLE 
) 
LOGGING 
TABLESPACE ETERM01 
PCTFREE 10 
INITRANS 1 
STORAGE 
( 
  INITIAL 65536 
  NEXT 1048576 
  MINEXTENTS 1 
  MAXEXTENTS UNLIMITED 
  BUFFER_POOL DEFAULT 
) 
NOCOMPRESS 
NOPARALLEL;

DATA FILE:

EST;3773909;8EUK;N;RF_STARTY;IRD;BOND;S;18/10/2024;LIVE;25/09/2020;OCD 0 184534;0018234537;-2402029;1;0;MX;-2402029.000000
EST;8223589;A4805;N;SW_STARTY;IRD;IRS;B;22/12/2045;LIVE;29/09/2014;EUROPE;001345297;-217726.721335;1;0;MX;-217726.721335

CodePudding user response:

The issue seems to be that IMP_NPVFRONT has the value 'MX' in both sample records, causing the error when attempting to apply the to_number expression on it.

COD_CURRPL COD_IDINST COD_COUNTER XTI_INTERNA COD_PRTFOLIO COD_FAMILY COD_GRUPO COD_TIPOPER FEC_EXPIRY COD_STATUS FEC_INICIO COD_INSTRMNT COD_ENTITY IMP_NONFMV IMP_CAMBIO COD_APLICFO IMP_NPVFRONT FEC_PROCESO COD_FICHERIN FEC_LOADER XTI_ESTADO
EST 3773909 8EUK N RF_STARTY IRD BOND S 18/10/2024 LIVE 25/09/2020 OCD 0 184534 0018234537 -2402029 1 0 MX -2402029.000000
EST 8223589 A4805 N SW_STARTY IRD IRS B 22/12/2045 LIVE 29/09/2014 EUROPE 001345297 -217726.721335 1 0 MX -217726.721335

When I set IMP_NPVFRONT filler (so it is skipped), the file loaded. You will need to check your data and how it should be loaded. (I also added a header to the test file to match OPTIONS (SKIP=1) in the control file.)

Other points:

  1. COD_CURRPL CHAR NULLIF COD_CURRPL="" and all other fields that are set to null if there is no value - that doesn't seem to achieve anything so I removed the 'nullif' expressions.

  2. COD_IDINST INTEGER EXTERNAL - this datatype is for binary data, not text characters representing numbers. To be honest I've never used it. According to the log file, SQL*Loader is ignoring it, and the column is a string anyway.

OPTIONS (SKIP=1)
LOAD DATA
APPEND
INTO TABLE TTERMNZI
FIELDS TERMINATED BY ';' 
OPTIONALLY ENCLOSED BY '"' 
TRAILING NULLCOLS
(
 COD_CURRPL CHAR,
 COD_IDINST CHAR,
 COD_COUNTER CHAR,
 XTI_INTERNA CHAR,
 COD_PRTFOLIO CHAR,
 COD_FAMILY CHAR,
 COD_GRUPO CHAR,
 COD_TIPOPER CHAR,
 FEC_EXPIRY DATE "DD/MM/RRRR",
 COD_STATUS CHAR,
 FEC_INICIO DATE "DD/MM/RRRR",
 COD_INSTRMNT CHAR,
 COD_ENTITY CHAR,
 IMP_NONFMV CHAR "to_number(:IMP_NONFMV, '999999999999999999D999999', 'NLS_NUMERIC_CHARACTERS = ''.,''')",
 IMP_CAMBIO CHAR "to_number(:IMP_CAMBIO, '999999999999999999D999999', 'NLS_NUMERIC_CHARACTERS = ''.,''')",
 COD_APLICFO CHAR,
 IMP_NPVFRONT filler, --CHAR "to_number(:IMP_NPVFRONT,'999999999999999999D999999', 'NLS_NUMERIC_CHARACTERS = ''.,''')",
 FEC_PROCESO "to_date('', 'DD/MM/RRRR')" ,
 COD_FICHERIN CONSTANT "" ,
 FEC_LOADER SYSDATE,
 XTI_ESTADO CONSTANT 0 
 )
  • Related