【问题标题】:Error executing a PL/SQL procedure using Node.js node-oracledb使用 Node.js node-oracledb 执行 PL/SQL 过程时出错
【发布时间】:2020-01-23 13:23:24
【问题描述】:

我想在 Oracle 中执行一个存储过程,从我的 debian 服务器使用 nodejs 文件,在 windows 中它可以工作,但是当我在我的 debian 服务器中执行相同的代码时,它不起作用,我无法尝试使用 SQLPLUS因为我没有服务器上的权限,这是主要原因,因为我正在尝试使用 nodejs.file

  • debian 服务器节点版本:10.17.0
  • 节点版本窗口:12.14.1
  • node-oracledb 版本 = 4.2.0

错误:

[Error: ORA-00900: invalid SQL statement] errorNum: 900, offset: 0 }

  • ORACLE DB:11g R1

代码:

    const oracledb = require('oracledb');

    oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;

    const mypw = 'bikeutal'  

    async function run() {

      let connection;

      try {
        connection = await oracledb.getConnection(  {
          user          : "user",
          password      : mypw,
          connectString : "host/sys"
        });

        const result = await connection.execute(
          `exec actualizar_rating();`//bad
          //`BEGIN BIKE_UTAL.ACTUALIZAR_RATING(); END ;`//bad

          //`exec ACTUALIZAR_RATING()` //bad
          //"CALL ACTUALIZAR_RATING()" //bad
          //`EXECUTE ACTUALIZAR_RATING()`// bad
          //`SELECT * FROM dev_viajes` //work
          //

         // console.log(result);
         );
      } catch (err) {
        console.error(err);
      } finally {
        if (connection) {
          try {
            await connection.close();
          } catch (err) {
            console.error(err);
          } 
        }
      }
    }

    run();

【问题讨论】:

标签: oracle plsql debian node-oracledb


【解决方案1】:
  • EXEC(及其全名 EXECUTE)是一个 SQL*Plus 命令。这是一个非 SQL 语句,因此数据库无法理解它。使用此命令的 Node.js 会出现任何错误。

  • BEGIN BIKE_UTAL.ACTUALIZAR_RATING(); END ; 出现什么错误?

  • 您确定在 Debian 上连接的数据库与在 Windows 上连接的数据库相同吗?

  • 如果您可以在 Node.js 中使用 node-oracledb,您应该可以轻松地在同一台计算机上使用 SQL*Plus。

  • 关于调用 PL/SQL 存储过程的 Node-oracledb 文档位于 PL/SQL Stored Procedure

【讨论】:

    猜你喜欢
    • 2019-04-28
    • 2019-01-13
    • 1970-01-01
    • 2021-07-17
    • 1970-01-01
    • 2019-03-08
    • 1970-01-01
    • 2016-08-09
    • 1970-01-01
    相关资源
    最近更新 更多