我有一个带有时间戳字段的Oracle DB。在此字段中插入时间戳的正确SQL代码是什么?
SQL CLASSIC:
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);
});
答案 0 :(得分:1)
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'),
后面有一个逗号逗号。我把它留了下来,但看起来很奇怪。我目前无法测试以确保这是正确的