Oracle Pipelined Table(轉)
管道化表函式必須返回一個集合。在函式中,PIPE ROW 語句被用來返回該集合的單個元素,該函式必須以一個空的 RETURN 語句結束,以表明它已經完成。一旦我們建立了上述函式,我們就可以使用 TABLE 操作符從 SQL 查詢中呼叫它。
管道化表函式經常被用來把資料從一種型別轉化成另一種型別。
下面是用 Pipelined Table 實現 split 函式的例子:
CREATE OR REPLACE TYPE ty_str_split IS TABLE OF VARCHAR2 (4000);
CREATE OR REPLACE FUNCTION fn_split (p_str IN VARCHAR2, p_delimiter IN VARCHAR2)
RETURN ty_str_split PIPELINED
IS
j INT := 0;
i INT := 1;
len INT := 0;
len1 INT := 0;
str VARCHAR2 (4000);
BEGIN
len := LENGTH (p_str);
len1 := LENGTH (p_delimiter);
WHILE j < len
LOOP
j := INSTR (p_str, p_delimiter, i);
IF j = 0
THEN
j := len;
str := SUBSTR (p_str, i);
PIPE ROW (str);
IF i >= len
THEN
EXIT;
END IF;
ELSE
str := SUBSTR (p_str, i, j - i);
i := j + len1;
PIPE ROW (str);
END IF;
END LOOP;
RETURN;
END fn_split;
/
測試:SELECT * FROM TABLE (fn_split ('1;;12;;123;;1234;;12345', ';;'));
結果:
1
12
123
1234
12345
又一個簡單的例子:CREATE TYPE mytype AS OBJECT (
field1 NUMBER,
field2 VARCHAR2 (50)
);
CREATE TYPE mytypelist AS TABLE OF mytype;
CREATE OR REPLACE FUNCTION pipelineme
RETURN mytypelist PIPELINEDIS
v_mytype mytype;
BEGIN
FOR v_count IN 1 .. 20
LOOP
v_mytype := mytype (v_count, 'Row ' || v_count);
PIPE ROW (v_mytype); END LOOP;
RETURN;
END pipelineme;
SELECT * FROM TABLE (pipelineme);
FIELD1 FIELD2
------ ------------------------
1 Row 1
2 Row 2
3 Row 3
4 Row 4
5 Row 5
6 Row 6
7 Row 7
8 Row 8
9 Row 9
10 Row 10
11 Row 11
12 Row 12
13 Row 13
14 Row 14
15 Row 15
16 Row 16
17 Row 17
18 Row 18
19 Row 19
20 Row 20
20 rows selected
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/756652/viewspace-242131/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Oracle Pipelined Table Functions(轉)OracleFunction
- Oracle Pipelined Table FunctionsOracleFunction
- Oracle 的管道化表函式(Pipelined Table) 轉Oracle函式
- improving performance with pipelined table functionsORMFunction
- Oracle Pipelined FunctionOracleFunction
- Multi-table insert using pipelined functionFunction
- Pipelined table function statistics and dynamic samplingFunction
- oracle cache table(轉)Oracle
- Oracle 普通table 轉換為partition tableOracle
- Pipelined FunctionsFunction
- [Oracle] Partition table exchange Heap tableOracle
- oracle temporary tableOracle
- oracle shrink tableOracle
- Oracle Table LocksOracle
- Alter table for ORACLEOracle
- Oracle Table FunctionOracleFunction
- Oracle table selectOracle
- Oracle:TABLE MONITORINGOracle
- oracle之nalyze tableOracle
- Oracle ASM Allocation TableOracleASM
- oracle cache table(1)Oracle
- oracle cache table(3)Oracle
- oracle cache table(2)Oracle
- oracle cache table(5)Oracle
- oracle cache table(4)Oracle
- oracle cache table(6)Oracle
- pipelined函式例項函式
- Oracle -- 深入體會PLAN_TABLE、PLAN_TABLE$Oracle
- Oracle --- PLAN_TABLE$和PLAN_TABLE區別Oracle
- Oracle ASM Partnership and Status TableOracleASM
- Oracle ASM Free Space TableOracleASM
- Oracle Table and tablespace CompressOracle
- oracle alter table詳解Oracle
- Oracle 基本操作之 tableOracle
- Oracle Create Table as SelectOracle
- oracle 外部表 external tableOracle
- Oracle外部表 External TableOracle
- Oracle Temp Table ConceptOracle