在oracle中创建Pipelined表函数,搞的我好累,记下来,省得以后再费事。
1. 先创建一个类型:
CREATE OR REPLACE TYPE smpl_metadata AS OBJECT
(
smpl varchar2(2000),
lauren varchar2(2000),
grade varchar2(2000)
);
2. 再用新建的类型创建一个“表类型”:
CREATE OR REPLACE TYPE smpl_metadata_table AS TABLE OF smpl_metadata
3. 然后就可以用这个“表类型”,创建“表函数”了:
CREATE OR REPLACE FUNCTION query_smpl_metadata
RETURN smpl_metadata_table PIPELINED
IS
v_smpl_metadata smpl_metadata;
BEGIN
FOR v_count IN 1 .. 20
LOOP
v_smpl_metadata := smpl_metadata ('s' || v_count, 'a', 'b');
PIPE ROW (v_smpl_metadata);
END LOOP;
RETURN;
END query_smpl_metadata;
4. 再来个复杂一点的,带参数的:
CREATE OR REPLACE FUNCTION query_smpl_metadata_detail(smpl_match varchar2)
RETURN smpl_metadata_table PIPELINED
IS
v_smpl_metadata smpl_metadata;
BEGIN
for x in
(
select * from
(
select 'a' smpl, 'b' lauren, 'c' grade from dual
)
where smpl = smpl_match
)
loop
v_smpl_metadata := smpl_metadata(x.smpl, x.lauren, x.grade);
PIPE ROW(v_smpl_metadata);
end loop;
return;
END query_smpl_metadata_detail;
1. 先创建一个类型:
CREATE OR REPLACE TYPE smpl_metadata AS OBJECT
(
smpl varchar2(2000),
lauren varchar2(2000),
grade varchar2(2000)
);
2. 再用新建的类型创建一个“表类型”:
CREATE OR REPLACE TYPE smpl_metadata_table AS TABLE OF smpl_metadata
3. 然后就可以用这个“表类型”,创建“表函数”了:
CREATE OR REPLACE FUNCTION query_smpl_metadata
RETURN smpl_metadata_table PIPELINED
IS
v_smpl_metadata smpl_metadata;
BEGIN
FOR v_count IN 1 .. 20
LOOP
v_smpl_metadata := smpl_metadata ('s' || v_count, 'a', 'b');
PIPE ROW (v_smpl_metadata);
END LOOP;
RETURN;
END query_smpl_metadata;
4. 再来个复杂一点的,带参数的:
CREATE OR REPLACE FUNCTION query_smpl_metadata_detail(smpl_match varchar2)
RETURN smpl_metadata_table PIPELINED
IS
v_smpl_metadata smpl_metadata;
BEGIN
for x in
(
select * from
(
select 'a' smpl, 'b' lauren, 'c' grade from dual
)
where smpl = smpl_match
)
loop
v_smpl_metadata := smpl_metadata(x.smpl, x.lauren, x.grade);
PIPE ROW(v_smpl_metadata);
end loop;
return;
END query_smpl_metadata_detail;