2017-10-03 16 views
0

RefCursor를 사용하지 않고 저장 프로 시저를 정의 할 수 있습니까? ("return refcursor"와 같은)oracle 저장 프로 시저 반환 결과 집합

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; 

답변

0

당신은 파이프 라인 기능을 사용할 수는

이 테이블로 exacltly 작동하는 기능이

이 방법

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;