问题描述
我需要使用 node js 使用第三方 webservice 并将其写入 oracle table 。基本上我得到了获取数据的代码。基本上需要获取该输出并插入到 Oracle clob 列中。有人可以通过示例指导我。
解决方法
一些资源:
-
https://github.com/oracle/node-oracledb/tree/master/examples 有 LOB 示例,例如 lobinsert1.js 和 lobinsert2.js
-
node-oracledb 手册中有大量关于在 node-oracledb 中使用 LOB 的文档,请参阅 Working with CLOB,NCLOB and BLOB Data。
例如:
// Insert a CLOB
const str = fs.readFileSync(clobInFileName,'utf8');
result = await connection.execute(
`INSERT INTO no_lobs (id,c) VALUES (:id,:c)`,{ id: 1,c: str }
);
if (result.rowsAffected != 1)
throw new Error('CLOB was not inserted');
else
console.log('CLOB inserted from ' + clobInFileName);
在您的情况下,您将从您的网络服务而不是磁盘读取 str
文件。由于我不知道该网络服务是什么,因此无法发表更多评论。
node-oracledb 的安装说明为 here。