【发布时间】:2021-06-01 02:14:41
【问题描述】:
在this answer 之后,我试图将 .jpg 文件保存到表内的 BLOB 类型列中。这是我目前所拥有的:
我创建了一个测试表:
CREATE TABLE test_lob(
ID NUMBER
, C CLOB
, B BLOB
);
然后我写了这段代码:
async function getFile() {
var str = fs.readFileSync('/path/to/image', 'utf8');
await insertBlob(str);
}
...
async function insertBlob(str) {
var connection;
try {
connection = await oracledb.getConnection({
user: process.env.USER,
password: process.env.PASS,
connectString: process.env.SERVER_CONNECT_STRING
});
const result = await connection.execute(
`
INSERT INTO test_lob(id, b) VALUES(1, :b)
`,
{ b: str },
{ autoCommit: true }
);
console.log(result);
} catch(err) {
console.error(err);
} finally {
if(connection) {
try {
await connection.close();
} catch(err) {
console.error(err);
}
}
}
}
但我总是得到错误:ORA-01461:只能绑定 LONG 值以插入 LONG 列。我错过了什么?
【问题讨论】:
标签: node.js oracle node-oracledb