在 Node.js 中调用 Oracle 存储过程时出现 PLS-00306

问题描述 投票:0回答:1

如何解决“ ORA-06550:第 1 行,第 7 列:PLS-00306:调用 'GET_TICKER_INFO' 时参数数量或类型错误 ORA-06550:第 1 行,第 7 列:PL/SQL:语句被忽略”?

嗨,我是节点和 Oracle 的新手。 无法使用 Node js 运行该过程。需要帮助来解决这个问题 Oracle过程参考

PROCEDURE get_data_info (
  p_ticker       VARCHAR2,
  p_acronym      VARCHAR2,
  p_sort         VARCHAR2,
  p_call_source  VARCHAR2,
  p_data     OUT REF_CRS);

节点js代码

sql = 'begin get_data_info(:p_ticker,:p_acronym,:p_sort,:p_call_source,:p_data); end;';
        // run procedure to get all data
        const ticker_data ={
          p_ticker: '',
          p_acronym: '',
          p_sort: '',
          p_call_source: '',
          p_data: ''
        };
        data = { p_ticker: 'AAPL', p_data: ':output'};
        binds  = Object.assign({}, ticker_data, data);
        
        options = {
            outFormat: oracledb.OUT_FORMAT_OBJECT,  
        };
        result = await connection.execute(sql, binds, options);
node.js oracle plsql node-oracledb
1个回答
5
投票

猜测

REF_CRS
是一个REF CURSOR,你的问题是绑定参数对象中
p_data
的定义。 您需要给它一个类型和方向,例如:

p_data: {dir: oracledb.BIND_OUT, type: oracledb.CURSOR}

查看node-oracledb文档章节REF CURSOR绑定参数

工作代码如下:

/*

create or replace PROCEDURE get_data_info (
  p_ticker       VARCHAR2,
  p_acronym      VARCHAR2,
  p_sort         VARCHAR2,
  p_call_source  VARCHAR2,
  p_data     OUT SYS_REFCURSOR) as
begin
  open p_data for select * from dual;
end;
/
show errors

*/

const oracledb = require('oracledb');
const dbConfig = { user: 'cj', password: 'cj', connectString: 'localhost/orclpdb1' };

if (process.platform === 'darwin') {
  oracledb.initOracleClient({libDir: '/Users/cjones/instantclient_19_3'});
}

let sql, binds, options, result;
sql = `SELECT TO_CHAR(CURRENT_DATE, 'DD-Mon-YYYY HH24:MI') AS D FROM DUAL`;
options = {
//  outFormat: oracledb.OUT_FORMAT_OBJECT  // uncomment if you want object output instead of array
};

async function run() {
  let connection;
  
  try {
    connection = await oracledb.getConnection(dbConfig);
    
    sql = 'begin get_data_info(:p_ticker,:p_acronym,:p_sort,:p_call_source,:p_data); end;';
    
    const ticker_data = {
      p_ticker: '',
      p_acronym: '',
      p_sort: '',
      p_call_source: '',
      p_data: ''
    };
    const data = { p_ticker: 'AAPL', p_data: {dir: oracledb.BIND_OUT, type: oracledb.CURSOR}};
    const binds  = Object.assign({}, ticker_data, data);   

    result = await connection.execute(sql, binds, options);

    const resultSet = result.outBinds.p_data;
    let row;
    while ((row = await resultSet.getRow())) {
      console.log(row);
    }
    await resultSet.close();   // always close the ResultSet
    
  } catch (err) {
    console.error(err);
  } finally {
    if (connection) {
      try {
    await connection.close();
      } catch (err) {
    console.error(err);
      }
    }
  }
}

run();
© www.soinside.com 2019 - 2024. All rights reserved.