我有一个Oracle数据库,其中有一个时间戳字段。在此字段中插入时间戳的正确SQL代码是什么?
SQL经典:
insert into test (time_of_add_doc)
values (to_timestamp('22/12/17 09:00:00','DD/MM/RR HH24:MI:SS');(1)一行添加成功!
我想在连接到数据库后从服务器NodeJS执行此操作(成功)
oracledb.getConnection({
user: 'ctrm',
password: 'ctrm',
connectString: "localhost/sig"
},
function (err, connection) {
if (err) {
console.error(err.message);
return;
}
console.log('Connection was successful!'); //Get Connection success
connection.execute(
"INSERT INTO test VALUES (:time_of_add_doc)", {
time_of_add_doc: ('22/12/17 09:00:00','DD/MM/RR HH24:MI:SS'),
},
function (err, result) {
if (err)
console.error(err.message);
else
console.log("Rows inserted " + result.rowsAffected);
});发布于 2017-12-27 23:19:36
Oracle期望一个日期,而您似乎正在将一个数组传递到单个绑定变量中。在节点中构造一个日期,然后绑定它。确保两端的数据类型均正确,并在需要时让Oracle和节点之间的接口应用标准转换
var time_of_add_doc = new Date(2017, 12, 22, 0, 0, 0, 0)
connection.execute(
"INSERT INTO test VALUES (:time_of_add_doc)", {
time_of_add_doc,
},
function (err, result) {
if (err)
console.error(err.message);
else
console.log("Rows inserted " + result.rowsAffected);
});time_of_add_doc: ('22/12/17 09:00:00','DD/MM/RR HH24:MI:SS'),后面有一个逗号。我把它留在里面了,但它看起来很奇怪。目前我不能测试以确保这是正确的
https://stackoverflow.com/questions/47994446
复制相似问题