Oracle 에서 Pipelined FUNCTION(파이프라인 함수)을 이용한 

테이블 함수(Table Functions)의 간단한 사용

 

 

사용 이유>

테이블 함수의 실행을 병렬화 한다는 의미는 전체의 결과를 기다리지않고

바로 받아서 처리가 가능하고, 메모리 소비도 줄일 수 있다는 장점이 있다.

데이터 양이 많을 수록 유용 할 듯 하다.

 

자세한 내용은 아래의 출처를 참고하자.

 

 

타입과 함수 만들기>

여기서는 최소한의 예제를 사용한다.

 

-- 테이블 타입의 유형(TYPE)을 생성

CREATE OR REPLACE TYPE TYPE_STR 
AS TABLE OF VARCHAR2(200);

 

-- 함수(FUNCTIONS) 생성

CREATE OR REPLACE FUNCTION F_MY
  RETURN TYPE_STR PIPELINED 
IS 
  v_str VARCHAR2(200);
BEGIN
  v_str := '가';
  PIPE ROW(v_str);
  v_str := '나';
  PIPE ROW(v_str);
  v_str := '다';
  PIPE ROW(v_str);
  RETURN;
END;

 

 

쿼리 사용하기>
SELECT

    COLUMN_VALUE

  FROM TABLE(F_MY_PIPELINED('한글'));

 

질의 결과(Query Result)>

COLUMN_VALUE



 

 

출처>

오라클 공식문서

https://docs.oracle.com/cd/B19306_01/appdev.102/b14289/dcitblfns.htm

 

Database Data Cartridge Developer's Guide,

13 Using Pipelined and Parallel Table Functions

...

Execution of a table function can be parallelized, and returned rows can be streamed directly to the next process without intermediate staging. Rows from a collection returned by a table function can also be pipelined—that is, iteratively returned as they are produced instead of in a batch after all processing of the table function's input is completed.

Streaming, pipelining, and parallel execution of table functions can improve performance:

  • By enabling multithreaded, concurrent execution of table functions

  • By eliminating intermediate staging between processes

  • By improving query response time: With non-pipelined table functions, the entire collection returned by a table function must be constructed and returned to the server before the query can return a single result row. Pipelining enables rows to be returned iteratively, as they are produced. This also reduces the memory that a table function requires, as the object cache does not need to materialize the entire collection.

  • By iteratively providing result rows from the collection returned by a table function as the rows are produced instead of waiting until the entire collection is staged in tables or memory and then returning the entire collection

 

 

광고>

728x90

+ Recent posts