如何在节点js中处理oracle.sql.ARRAY?

时间:2015-01-09 23:02:18

标签: node.js oracle

我正在尝试使用节点oracle驱动程序调用Oracle存储过程 - https://github.com/joeferner/node-oracle

我可以使用以下代码调用该过程,但我遇到第二个参数(parameterArray)的问题。它需要传递一个项目数组,在java中我们使用oracle.sql.ARRAY但是如何处理节点js呢?我目前的代码如下......

var oracle = require('oracle');

var connectData = {
    hostname: "example_editted.com",
    port: 1521,
    database: "dev", // System ID (SID)
    user: "user",
    password: "password"
}

oracle.connect(connectData, function(err, connection) {

var starting_time = req.body.startDate + " 00:00:00"
var ending_time = req.body.endDate +" 00:00:00"
var parameterArray = {owner_id: req.body.accountId, time_min: null, time_max: null, duration_min: null, duration_max: null, date_format: "'MM/DD/YYYY HH24:MI:SS'", start_date: starting_time, end_date: ending_time} 
connection.execute("call reporting.execute_report(:1, :2, :3)", ["ProcedureName", parameterArray,new oracle.OutParam()], function(err, results) {

我得到的当前错误是

Assertion failed: (handle->InternalFieldCount() > 0), function Unwrap, file /Users/johnson/.node-gyp/0.10.35/src/node_object_wrap.h, line 61.
Abort trap: 6

1 个答案:

答案 0 :(得分:1)

基于纯猜测,问题可能在于OCI无法绑定字符串索引集合,您的解决方案可能是在调用存储之前将JS对象分解为一对常规数组程序并在调用存储过程之前重新组合PLSQL代码中的关联集合,即...

.
.
.    
//var parameterArray = {owner_id: req.body.accountId, time_min: null, time_max: null, duration_min: null, duration_max: null, date_format: "'MM/DD/YYYY HH24:MI:SS'", start_date: starting_time, end_date: ending_time} 
var parameterArrayIndices = ["owner_id", "time_min", "time_max", "duration_min", "duration_max", "date_format", "start_date", "end_date"];
var parameterArrayValues = [req.body.accountId, null, null, null, null, "'MM/DD/YYYY HH24:MI:SS'", starting_time, ending_time];

connection.execute("
    declare
        i_indices     dbms_sql.varchar2a;
        i_values      dbms_sql.varchar2a;
        l_params      <the_collection_type_of_the_procedure's_second_parameter>;
    begin
        i_indices := :1;
        i_values := :2;

        for i in nvl(i_indices.first,1)..nvl(i_indices.last,0) loop
            l_params(i_indices(i)) := i_values(i);
        end loop;

        reporting.execute_report(:3, l_params, :4);
    end;
", [parameterArrayIndices, parameterArrayValues, "ProcedureName", new oracle.OutParam()], function(err, results) {