0

我正在尝试使用 asp.net 从 oracle 数据库中获取数据,但是当数据存在于表中时,我没有在游标中获得任何输出:我正在使用以下存储过程:

CREATE OR REPLACE PROCEDURE branch_details
( startIndex in  int
,pageSize    in  int
,isSearch    in  int
,byName      in  int
,dataDetail  in  varchar2
, p_cursor   out sys_refcursor)
AS
BEGIN
    IF isSearch=1 THEN
        IF byName=1 THEN
          OPEN p_cursor FOR
          SELECT *
            FROM (SELECT ROW_NUMBER() OVER(ORDER BY branch_id)
                         AS MyRows
                       , branch_id, branch_name
                       , branch_location, bm_name, bm_contact
                       , bm_email, is_active, max_ua
                       , (SELECT COUNT(branch_id)
                            FROM branch_info
                           WHERE branch_name LIKE
                                 '%'|| dataDetail||'%')
                         AS RowNumber
                    FROM branch_info 
                   WHERE branch_name LIKE '%'|| dataDetail||'%')
           WHERE MyRows BETWEEN startIndex
                                 AND startIndex+pageSize-1;
        ELSE
          OPEN p_cursor FOR
          SELECT *
            FROM (SELECT ROW_NUMBER() OVER(ORDER BY branch_id)
                         AS MyRows
                       , branch_id, branch_name, branch_location
                       , bm_name, bm_contact, bm_email, is_active
                       , max_ua
                       , (SELECT COUNT(branch_id)
                            FROM branch_info
                           WHERE branch_id LIKE
                                 '%'|| dataDetail||'%')
                         As  RowNumber 
                    FROM branch_info 
                   WHERE branch_id LIKE '%'|| dataDetail||'%')
           WHERE MyRows BETWEEN startIndex
                            AND startIndex+pageSize-1;
        END IF;
    ELSE
        OPEN p_cursor FOR
        SELECT *
          FROM (SELECT ROW_NUMBER() OVER(ORDER BY branch_id)
                         AS MyRows
                     , branch_id, branch_name, branch_location
                     , bm_name, bm_contact, bm_email
                     , is_active, max_ua
                     , (SELECT COUNT(branch_id)
                          FROM branch_info) AS RowNumber 
                  FROM branch_info)
         WHERE MyRows BETWEEN startIndex
                          AND startIndex+pageSize-1;
    END IF;
END;

并使用以下 asp.net 代码:

List<Paramarray> param = new List<Paramarray>();
    param.Add(new Paramarray("@dataDetail", data));
    param.Add(new Paramarray("@byName", id?"0":"1"));
    param.Add(new Paramarray("@isSearch", isSearch?"1":"0"));
    param.Add(new Paramarray("@startIndex", startIndex==1?startIndex.ToString():Convert.ToString(((startIndex-1)*pageSize)+1)));
    param.Add(new Paramarray("@pageSize", pageSize.ToString()));

    _command.Connection = _connection;
    _command.CommandType = CommandType.StoredProcedure;
    _command.CommandText = "branch_details";
    foreach (Paramarray _param in param)
    {
        _parameter = new OracleParameter(_param.name,_param.value);
        _command.Parameters.Add(_parameter);            
    }

    _command.Parameters.Add("@p_cursor", OracleDbType.RefCursor).Direction = ParameterDirection.Output;
    if (_connection.State != ConnectionState.Open) _connection.Open();
    _dataReader = _command.ExecuteReader();
    dt.Load(_dataReader);
    if (_connection.State == ConnectionState.Open) _connection.Close();

我的另一个程序的相同代码工作正常并给我输出。

如果我的程序或其他地方有误,请帮助我。我无法弄清楚问题所在。

4

1 回答 1

0

我敢打赌你的程序是错误的。您的 asp.net 代码看起来很好,没有更多信息,在我看来,光标只是没有返回任何数据。

您是否对过程进行了单元测试,甚至只是游标查询?

于 2013-04-02T19:49:07.087 回答