简体   繁体   English

如何使用node.js运行oracle用户定义的函数

[英]How to run oracle user defined functions using node.js

I am trying to run an user defined function on oracle db through node.js using oracledb driver. 我正在尝试使用oracledb驱动程序通过node.js在oracle db上运行用户定义的函数。 My oracle function is declared in PACKAGE z_1419_pkg as 我的oracle函数在PACKAGE z_1419_pkg中声明为

FUNCTION GET_CUSTOMER_INFO(P_COMPANY_NAME VARCHAR2, P_COMP_CODE VARCHAR2) RETURN QC_UTL_PKG.CURSOR_TYPE
  IS
    C QC_UTL_PKG.CURSOR_TYPE;
    V_COMPANY_NAME COMPANIES.COMPANY_NAME%TYPE := TRIM(P_COMPANY_NAME);
    V_COMP_CODE    COMPANIES.COMPANY_CODE%TYPE := TRIM(P_COMP_CODE);
  BEGIN
    C := QC_CV_PKG.COMPANIES_BROWSE(NULL,V_COMP_CODE,V_COMPANY_NAME,NULL,NULL,
                                    NULL,NULL,NULL,NULL,NULL,
                                    NULL,NULL,NULL,NULL,NULL);
    RETURN C;
  END;

and my node.js code is 而我的node.js代码是

exports.syncOracle = function (req, res) {

  var oracledb = require('oracledb');
  var bindvars = {
    p1:  'BM Dusters',
    p2: 'bmduster', 
  };
  oracledb.getConnection({
    user          : 'uname',
    password      : 'password',
    connectString : 'locahost/TEST' },
      function (err, conn) {
        if (err) { console.error(err); return; }
        console.log('success');
        conn.execute('SELECT Z_1419_PKG.GET_CUSTOMER_INFO(:p1, :p2) from dual;' ,bindvars ,function (error, rows) {
          if (error) {
            console.log('ERROR: ' + error);
          }
          return res.status(200).json(rows);
      });
  });

};

but I am getting 但我越来越

ERROR: Error: ORA-00900: invalid SQL statement 错误:错误:ORA-00900:无效的SQL语句

Can somebody tell me what is wrong with my code. 有人可以告诉我代码有什么问题吗? I could not find any documentation or example on how to use oracle functions with oracledb driver. 我找不到任何有关如何通过oracledb驱动程序使用oracle函数的文档或示例。

Thanks in advance. 提前致谢。

When executing an SQL statement through an API such as this you shouldn't put a semi-colon at the end of the statement, so the call to conn.execute should be: 通过这样的API执行SQL语句时,不应在该语句的末尾添加分号,因此对conn.execute的调用应为:

conn.execute('SELECT Z_1419_PKG.GET_CUSTOMER_INFO(:p1, :p2) from dual',
             bindvars ,function (error, rows) {

Best of luck. 祝你好运。

As already stated, node-oracledb 0.6 doesn't support user defined types. 如前所述,node-oracledb 0.6不支持用户定义的类型。 You could write a 'wrapper' function in PL/SQL that decomposes your data into the basic types that are currently supported. 您可以在PL / SQL中编写一个“包装器”函数,该函数将数据分解为当前支持的基本类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM