queryString = `INSERT INTO TABLENAME ( DATEBORN ) VALUES ( to_date(:dtb, 'DD.MM.YYYY') )`;
optionsObj = {
autoCommit: true,
bindDefs: {
dtb: { type: oracledb.DATE }
}
}
bindsArr =[ { dtb: '11.05.2019' }, { dtb: '20.06.2019' } ]
connection = await oracledb.getConnection(
{
user: dbConfig.user,
password: dbConfig.password,
connectString: dbConfig.connectString
});
// There error: [Error: NJS-011: encountered bind value and type mismatch]
result = await connection.executeMany(
queryString
,bindsArr
,optionsObj
);
I can't insert the date into the database using executeMany. There is no problem with other types of data.
Also, the date is successfully added using execute.
What am I doing wrong?
The minimal change is to bind as oracledb.STRINGsince your dates are actually stored as strings like '20.06.2019' in your example.
let queryString = `INSERT INTO TABLENAME ( DATEBORN ) VALUES ( to_date(:dtb, 'DD.MM.YYYY') )`;
let optionsObj = {
autoCommit: true,
bindDefs: {
dtb: { type: oracledb.STRING, maxSize: 10 }
}
};
let bindsArr = [ { dtb: '11.05.2019' }, { dtb: '20.06.2019' } ];
result = await connection.executeMany(queryString, bindsArr, optionsObj);
Thnx, it works!
But i can't understand why.
In my database type of field is

In this case, what is { type: oracledb.DATE } used for?
According to my example, there is no use at all.
You are passing a string in:
let s = '11.05.2019';
console.log(typeof s); // string
Most helpful comment
The minimal change is to bind as
oracledb.STRINGsince your dates are actually stored as strings like'20.06.2019'in your example.