oracle: Error: NJS-012: encountered invalid bind data type in parameter 2
oracle: Error: NJS-012: encountered invalid bind data type in parameter 2
我在 Oracle db
中将新用户插入 users
table 但遇到此错误,
oracle: Error: NJS-012: encountered invalid bind data type in parameter 2
当我查看了指示的参数时,我发现没有问题!
function storedProcs() {
this.SP_USER_ADD_USER = {
name: 'sp_user_adduser',
params: {
username : {val: null, type: dbParams.STRING, dir : dbParams.BIND_IN},
password : {val: null, type: dbParams.STRING, dir : dbParams.BIND_IN},
salt : {val: null, type: dbParams.STRING, dir : dbParams.BIND_IN},
userTypeId : {val: null, type: dbParams.NUMBER, dir : dbParams.BIND_IN},
isActive : {val: null, type: dbParams.NUMBER, dir : dbParams.BIND_IN},
isTeller : {val: null, type: dbParams.NUMBER, dir : dbParams.BIND_IN},
userLoginIpAuthTypeId : {val: null, type: dbParams.NUMBER, dir : dbParams.BIND_IN},
userLoginIp : {val: null, type: dbParams.STRING, dir : dbParams.BIND_IN},
forceChangePassword : {val: null, type: dbParams.STRING, dir : dbParams.BIND_IN},
customerId : {val: null, type: dbParams.NUMBER, dir : dbParams.BIND_IN},
userId : {val: null, type: dbParams.NUMBER, dir : dbParams.BIND_OUT},
errorMsg : {val: null, type: dbParams.STRING, dir : dbParams.BIND_OUT}
}
}
}
``
``
oracleDbAssist.getConnection(function(err,conn){
if(err){
console.log('error: - getConnection ' + JSON.stringify(err));
return;
}
for(var i = 0; i < myData.length; i++) {
session.newUser = myData[i];
var sp = new StoredProcs().SP_USER_ADD_USER;
sp.params.username.val = session.newUser.userName;
sp.params.salt.val = util.generateSalt();
sp.params.password.val = util.hash(session.newUser.password, sp.params.salt.val);
sp.params.userTypeId.val = session.newUser.userTypeId;
sp.params.isActive.val = session.newUser.isActive;
sp.params.isTeller.val = session.newUser.isTeller;
sp.params.forceChangePassword.val = session.newUser.forceChangePassword == 0 ? '0' : '1';
sp.params.customerId.val = session.newUser.customerId;
sp.params.userLoginIpAuthTypeId.val = session.newUser.userLoginIpAuthTypeId;
sp.params.userLoginIp.val = session.newUser.userLoginIp;
console.log('sp: ' + JSON.stringify(sp));
oracleDbAssist.executeSqlWithConn(sp,true,conn, function(err,result){
if(err){
console.log('error:- executeSqlWithConn ' + err);
return;
}
console.log('New user added: ' + JSON.stringify(result));
});
}
});
下面是 console.log('sp: ' + JSON.stringify(sp));
的输出
仔细查看控制台输出,未发现无效数据类型。
``
sp: {
"name":"sp_user_adduser",
"params":{
"username":{"val":"200216","type":"STRING","dir":"BIND_IN"},
"password":{"val":"e64b580d65b34219826a1a89fc85dc8e17b97f59","type":"STRING","dir":"BIND_IN"},
"salt":{"val":"895909","type":"STRING","dir":"BIND_IN"},
"userTypeId":{"val":3,"type":"NUMBER","dir":"BIND_IN"},
"isActive":{"val":1,"type":"NUMBER","dir":"BIND_IN"},
"isTeller":{"val":0,"type":"NUMBER","dir":"BIND_IN"},
"userLoginIpAuthTypeId":{"val":1,"type":"NUMBER","dir":"BIND_IN"},
"userLoginIp":{"val":null,"type":"STRING","dir":"BIND_IN"},
"forceChangePassword":{"val":"1","type":"STRING","dir":"BIND_IN"},
"customerId":{"val":null,"type":"NUMBER","dir":"BIND_IN"},
"userId":{"val":null,"type":"NUMBER","dir":"BIND_OUT"},
"errorMsg":{"val":null,"type":"STRING","dir":"BIND_OUT"}}
}
``
我现在在执行后遇到这个错误,oracle: Error: NJS-012: encountered invalid bind data type in parameter 2
。
有帮助吗?
提前致谢。
您不应该使用 DB_TYPE_* 常量。来自文档:
These values indicate the Oracle Database type shown in extended
metadata for queries and REF CURSORS, and also shown for DbObject
types.
您可以使用 3.1.2 Node-oracledb 类型常量:
https://oracle.github.io/node-oracledb/doc/api.html#-312-node-oracledb-type-constants
Constants for execute() bind parameter type property, for the
createLob() type parameter, for the Lob type property, for
fetchAsBuffer, for fetchAsString and fetchInfo, and for extended
metadata.
请记住,您不需要使用 "in" 绑定指定类型,因为它们都有基于 JS 类型的默认映射。 https://oracle.github.io/node-oracledb/doc/api.html#-201-in-bind-parameters
我在 Oracle db
中将新用户插入 users
table 但遇到此错误,
oracle: Error: NJS-012: encountered invalid bind data type in parameter 2
当我查看了指示的参数时,我发现没有问题!
function storedProcs() {
this.SP_USER_ADD_USER = {
name: 'sp_user_adduser',
params: {
username : {val: null, type: dbParams.STRING, dir : dbParams.BIND_IN},
password : {val: null, type: dbParams.STRING, dir : dbParams.BIND_IN},
salt : {val: null, type: dbParams.STRING, dir : dbParams.BIND_IN},
userTypeId : {val: null, type: dbParams.NUMBER, dir : dbParams.BIND_IN},
isActive : {val: null, type: dbParams.NUMBER, dir : dbParams.BIND_IN},
isTeller : {val: null, type: dbParams.NUMBER, dir : dbParams.BIND_IN},
userLoginIpAuthTypeId : {val: null, type: dbParams.NUMBER, dir : dbParams.BIND_IN},
userLoginIp : {val: null, type: dbParams.STRING, dir : dbParams.BIND_IN},
forceChangePassword : {val: null, type: dbParams.STRING, dir : dbParams.BIND_IN},
customerId : {val: null, type: dbParams.NUMBER, dir : dbParams.BIND_IN},
userId : {val: null, type: dbParams.NUMBER, dir : dbParams.BIND_OUT},
errorMsg : {val: null, type: dbParams.STRING, dir : dbParams.BIND_OUT}
}
}
}
``
``
oracleDbAssist.getConnection(function(err,conn){
if(err){
console.log('error: - getConnection ' + JSON.stringify(err));
return;
}
for(var i = 0; i < myData.length; i++) {
session.newUser = myData[i];
var sp = new StoredProcs().SP_USER_ADD_USER;
sp.params.username.val = session.newUser.userName;
sp.params.salt.val = util.generateSalt();
sp.params.password.val = util.hash(session.newUser.password, sp.params.salt.val);
sp.params.userTypeId.val = session.newUser.userTypeId;
sp.params.isActive.val = session.newUser.isActive;
sp.params.isTeller.val = session.newUser.isTeller;
sp.params.forceChangePassword.val = session.newUser.forceChangePassword == 0 ? '0' : '1';
sp.params.customerId.val = session.newUser.customerId;
sp.params.userLoginIpAuthTypeId.val = session.newUser.userLoginIpAuthTypeId;
sp.params.userLoginIp.val = session.newUser.userLoginIp;
console.log('sp: ' + JSON.stringify(sp));
oracleDbAssist.executeSqlWithConn(sp,true,conn, function(err,result){
if(err){
console.log('error:- executeSqlWithConn ' + err);
return;
}
console.log('New user added: ' + JSON.stringify(result));
});
}
});
下面是 console.log('sp: ' + JSON.stringify(sp));
的输出
仔细查看控制台输出,未发现无效数据类型。
``
sp: {
"name":"sp_user_adduser",
"params":{
"username":{"val":"200216","type":"STRING","dir":"BIND_IN"},
"password":{"val":"e64b580d65b34219826a1a89fc85dc8e17b97f59","type":"STRING","dir":"BIND_IN"},
"salt":{"val":"895909","type":"STRING","dir":"BIND_IN"},
"userTypeId":{"val":3,"type":"NUMBER","dir":"BIND_IN"},
"isActive":{"val":1,"type":"NUMBER","dir":"BIND_IN"},
"isTeller":{"val":0,"type":"NUMBER","dir":"BIND_IN"},
"userLoginIpAuthTypeId":{"val":1,"type":"NUMBER","dir":"BIND_IN"},
"userLoginIp":{"val":null,"type":"STRING","dir":"BIND_IN"},
"forceChangePassword":{"val":"1","type":"STRING","dir":"BIND_IN"},
"customerId":{"val":null,"type":"NUMBER","dir":"BIND_IN"},
"userId":{"val":null,"type":"NUMBER","dir":"BIND_OUT"},
"errorMsg":{"val":null,"type":"STRING","dir":"BIND_OUT"}}
}
``
我现在在执行后遇到这个错误,oracle: Error: NJS-012: encountered invalid bind data type in parameter 2
。
有帮助吗?
提前致谢。
您不应该使用 DB_TYPE_* 常量。来自文档:
These values indicate the Oracle Database type shown in extended metadata for queries and REF CURSORS, and also shown for DbObject types.
您可以使用 3.1.2 Node-oracledb 类型常量: https://oracle.github.io/node-oracledb/doc/api.html#-312-node-oracledb-type-constants
Constants for execute() bind parameter type property, for the createLob() type parameter, for the Lob type property, for fetchAsBuffer, for fetchAsString and fetchInfo, and for extended metadata.
请记住,您不需要使用 "in" 绑定指定类型,因为它们都有基于 JS 类型的默认映射。 https://oracle.github.io/node-oracledb/doc/api.html#-201-in-bind-parameters