Node.js 和 Oracle DB 选择查询在行中获取空数组

问题描述

   const result = await connection.execute(
       `SELECT * from no_example `,[],{ maxRows: 1000 } // bind value for :id
   );

但结果我总是得到空行

解决方法

如果您在另一个工具或另一个程序中插入行。确保您提交数据:

SQL> create table t (c number);

Table created.

SQL> insert into t (c) values (1);

1 row created.

SQL> commit;

Commit complete.

如果您使用 Node.js 插入,请查看 autoCommit 属性和 connection.commit() 函数。另请参阅 Transaction Management 上的 node-oracledb 文档。

与您的问题无关,但您几乎肯定不应该使用 maxRows。默认情况下,node-oracledb 将返回所有行。如果您不想要全部,则在您的查询中添加某种 WHERE 子句或 row-limiting clause。如果您需要大量行,请使用 result set 以便您可以访问连续批次的行。