【问题标题】:oracle stored procedure return resultsetoracle 存储过程返回结果集
【发布时间】:2017-10-03 13:38:26
【问题描述】:

我可以在不使用 RefCursor 的情况下定义存储过程吗? (如“返回引用”)

我不想使用 OracleDbType.RefCursor,因为它不是在其他数据库中作为 dbparameter 发送的。

还有 DbParameter.DbType = OracleDbType.RefCursor;不支持

我不想在下面的代码中定义“retval IN OUT SYS_REFCURSOR”。还有其他方法吗?

CREATE OR REPLACE procedure SYSTEM.customer_select_row(
    p_email IN CUSTOMER.Email%TYPE,
    p_password IN CUSTOMER."Password"%TYPE,
    retval IN OUT SYS_REFCURSOR
  )
IS
BEGIN
  OPEN retval FOR
    SELECT CustomerId, FirstName, LastName FROM CUSTOMER
    WHERE Email = p_email AND "Password" = p_password 

END customer_select_row;

【问题讨论】:

    标签: c# .net oracle stored-procedures odp.net


    【解决方案1】:

    您可以使用管道函数,

    这是一个完全像表格一样工作的函数

    你可以这样称呼它

    SELECT * 
      FROM TABLE(TEST_PIPELINE.STOCKPIVOT(10));
    

    TEST_PIPELINE.STOCKPIVOT(10) 是一个函数

    你可以这样构建它:

    create or replace PACKAGE TEST_PIPELINE AS
    
      -- here you declare a type record 
      type t_record is record
      (
        field_1     VARCHAR2(100),
        field_2      VARCHAR2(100));
    
      -- declare a table type from your previously created type 
      TYPE t_collection IS TABLE OF t_record;
    
      -- declare that the function will return the collection pipelined
      FUNCTION StockPivot(P_LINES NUMBER) RETURN t_collection PIPELINED;
    
      END;
    
    /
    
    create or replace PACKAGE BODY TEST_PIPELINE IS
    
    FUNCTION StockPivot(P_LINES NUMBER) RETURN t_collection PIPELINED IS
    
      -- declare here a type of the record
      T_LINE T_RECORD;
    
      BEGIN
    
        -- here is a loop example for insert some lines on pipeline
        FOR I IN 1..P_LINES LOOP
    
          -- inser data on your line this way
          T_LINE.field_1      := 'LINE - ' || I;
          T_LINE.field_2      := 'LINE - ' || I;
    
          -- then insert insert the line for result (this kind of functions should not have a return statement)
          PIPE ROW (T_LINE );
    
        END LOOP;
    
      END;
    
    END;
    

    【讨论】:

      猜你喜欢
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-28
      • 2012-07-19
      • 1970-01-01
      • 1970-01-01
      • 2016-03-27
      相关资源
      最近更新 更多