我创建了一些返回表的函数。我创建记录,然后将记录作为表格。
CREATE OR REPLACE PACKAGE FOR_SELECT AS TYPE NK IS RECORD (
SHT NUMBER,
VVD NUMBER,
NEKOM NUMBER,
N_GOL NUMBER);
TYPE NK_T IS TABLE OF NK; FUNCTION NEK_SLU_PR(W_KOD VARCHAR2)
RETURN NK_T PIPELINED; END FOR_SELECT;
和我的简单功能:
CREATE OR REPLACE PACKAGE BODY FOR_SELECT AS FUNCTION NEK_SLU_PR(W_KOD VARCHAR2)
RETURN NK_T PIPELINED
AS
REC NK_T;
SHT NUMBER;
VVD NUMBER;
NEKOM NUMBER;
N_GOL NUMBER;
BEGIN
SHT := 3;
VVD := 4;
NEKOM := 5;
N_GOL := 6;
SELECT SHT,
VVD,
NEKOM,
N_GOL
INTO REC
FROM DUAL;
PIPE ROW (REC);
RETURN;
END NEK_SLU_PR;END FOR_SELECT;
我有4个变量,所有选择变量都有表类型,但是ora-000947 - 没有足够的值(我做错了什么?
答案 0 :(得分:1)
REC
的类型错误。
它应该是NK
而不是NK_T
,因为您处理的是单个记录。
答案 1 :(得分:1)
- 尝试这一点,它将帮助您了解流水线功能
CREATE OR REPLACE TYPE NK IS OBJECT (
SHT NUMBER,
VVD NUMBER,
NEKOM NUMBER,
N_GOL NUMBER);
CREATE OR REPLACE TYPE NK_T IS TABLE OF NK;
CREATE OR REPLACE FUNCTION NEK_SLU_PR(
W_KOD VARCHAR2)
RETURN NK_T PIPELINED
AS
REC NK_T;
SHT NUMBER;
VVD NUMBER;
NEKOM NUMBER;
N_GOL NUMBER;
BEGIN
SHT := 3;
VVD := 4;
NEKOM := 5;
N_GOL := 6;
SELECT NK(SHT, VVD, NEKOM, N_GOL) BULK COLLECT INTO REC FROM DUAL;
FOR I IN 1..REC.COUNT
LOOP
PIPE ROW( NK( REC(I).sht,REC(I).vvd, REC(I).nekom, REC(I).n_gol ) ) ;
END LOOP ;
RETURN;
END NEK_SLU_PR;
---------------------------------------------OUTPUT-------------------------------------------
select * from table(NEK_SLU_PR('av'));
SHT VVD NEKOM N_GOL
3 4 5 6
---------------------------------------------OUTPUT-------------------------------------------