题
我有一些问题的功能表在ORACLE。
SET SERVEROUTPUT ON SIZE 100000;
DECLARE
int_position NUMBER(20);
TYPE T_REC_EMP IS RECORD ( nameFile VARCHAR2(200) );
R_EMP T_REC_EMP ; -- variable enregistrement de type T_REC_EMP
TYPE TAB_T_REC_EMP IS TABLE OF T_REC_EMP index by binary_integer ;
t_rec TAB_T_REC_EMP ; -- variable tableau d''enregistrements
PROCEDURE Pc_Insert ( v_value IN VARCHAR2) IS
BEGIN
if t_rec.exists(t_rec.Last) then
int_position := t_rec.last;
int_position := int_position +1;
t_rec(int_position).nomFichier := v_value;
else
t_rec(1).nomFichier :=v_value;
end if;
END;
FUNCTION calice_ORACLE( n IN NUMBER) RETURN T_REC_EMP PIPELINED IS
BEGIN
FOR i in 1 .. n LOOP
PIPE ROW(t_rec(i));
END LOOP;
RETURN;
END;
BEGIN
Pc_Insert('allo1');
Pc_Insert('allo2');
Pc_Insert('allo3');
SELECT * fROM TABLE(calice_ORACLE(2));
END;
/
我的一些错误有关的功能并不支持在SQL statement(我在9i9.2vr)
解决方案
首先你无法pipline assosiative阵列。检查这对集合类型的详细信息。 HTTP://www.developer。 COM /分贝/ article.php / 10920_3379271_2 / Oracle的编程与 - PLSQL-Collections.htm
其次需要选择成或使用光标在PL / SQL。
我写了一些演示代码,这样就可以查了一下它如何能工作。我不太清楚你真正想做的事,但至少这种编译,这是很好的。
create or replace type t_rec_emp as object (namefile varchar2(200));
/
create or replace type tab_t_rec_emp is table of t_rec_emp;
/
create or replace package mydemopack as
t_rec tab_t_rec_emp := tab_t_rec_emp();
procedure pc_insert ( v_value in varchar2);
function calice_oracle( n in integer) return tab_t_rec_emp pipelined;
end;
/
create or replace package body mydemopack as
procedure pc_insert ( v_value in varchar2) is
begin
t_rec.extend(1);
t_rec(t_rec.count):= t_rec_emp(v_value);
end;
function calice_oracle( n in integer) return tab_t_rec_emp pipelined is
begin
for i in 1 .. n loop
pipe row(t_rec(i));
end loop;
return;
end;
end;
/
declare
cursor c_cur is
select * from table(myDemoPack.calice_oracle(2));
begin
myDemoPack.pc_insert('allo1');
myDemoPack.pc_insert('allo2');
myDemoPack.pc_insert('allo3');
for rec in c_cur loop
dbms_output.put_line(rec.namefile);
end loop;
end;
/
其他提示
(如已经指出的评论意见)你有一个选择的发言嵌入PL/SQL没有说明在做什么用的查询的结果。你可以
SELECT INTO
一个当地宣布可变的,或者可以循环将结果与一个标,例如FOR rec IN (SELECT...) LOOP .. END LOOP
;也许你想要建立一个包而不是匿名块;然后,你呼吁程序的你可以的问题查询喜欢你的
SELECT * FROM TABLE(mypackagename.calice_ORACLE(2))
.
不隶属于 StackOverflow