pl/sql fukcja zwracająca tabelę

0

Witam.
Napisałem funkcję która zwraca tabelę. Przy jej wywołaniu select * from table(test_package_1.test_function()); wyrzuca błąd 'ORA-00902: niepoprawny typ danych'.
Co jest nie tak z moim kodem?

create or replace package test_package_1 is
type test_record is record
(
a VARCHAR2(50),
b VARCHAR2(50)
);
type test_table is table of test_record;
FUNCTION test_function RETURN test_table;
end;

create or replace package body test_package_1 is
function test_function return test_table is
t test_table;

begin
t.extend;
t(1).a := 'a';
t(1).b := 'a';

t.extend;
t(2).a := 'a;
t(2).b := 'b';

return t;
end test_function; 

end test_package_1;

0
Bogaty Kaczor napisał(a):

Co jest nie tak z moim kodem?

Jest niesformatowany - źle się czyta

0

create or replace package test_package_1 is
type test_record is record
(
a VARCHAR2(50),
b VARCHAR2(50)
);
type test_table is table of test_record;
FUNCTION test_function RETURN test_table;
end;
create or replace package body test_package_1 is
function test_function return test_table is
t test_table;

begin
t.extend;
t(1).a := 'a';
t(1).b := 'a';

t.extend;
t(2).a := 'a;
t(2).b := 'b';

return t;
end test_function;
end test_package_1;

0

Poprawiłem formatowanie kodu, przepraszam za wcześniejsze. Będę wdzięczny za pomoc.

CREATE OR REPLACE PACKAGE test_package_1 IS
	TYPE test_record IS RECORD (a VARCHAR2(50), b VARCHAR2(50));
	TYPE test_table IS TABLE OF test_record;
	FUNCTION test_function RETURN test_table;
END;

CREATE OR REPLACE PACKAGE BODY test_package_1 IS
	FUNCTION test_function RETURN test_table IS
	t test_table;

	BEGIN
	
	t.EXTEND;
	t(1).a := 'a';
	t(1).b := 'a';

	t.EXTEND;
	t(2).a := 'a;
	t(2).b := 'b';

	RETURN t;
	END test_function; 
END test_package_1;

Przy wywołaniu funkcji wyrzuca błąd: 'ORA-00902: niepoprawny typ danych'

SELECT * FROM TABLE(test_package_1.test_function()) 
0

albo

CREATE OR REPLACE TYPE test_record AS object (
  a VARCHAR2(50),
  b VARCHAR2(50));
/

CREATE OR REPLACE TYPE test_table AS TABLE OF test_record;
/

CREATE OR REPLACE PACKAGE test_package_1 IS 
FUNCTION test_function 
  RETURN test_table;
END;
/

CREATE OR replace package body test_package_1 IS 
  FUNCTION test_function RETURN test_table IS 
    t test_table;
  BEGIN
    t := test_table();
    t.extend;
    t(1) := test_record('a', 'b');
    t.extend;
    t(2) := test_record('a', 'b');
    return t;
  end test_function;
end test_package_1;
/

select * from table(test_package_1.test_function);

albo

CREATE OR REPLACE PACKAGE test_package_2 IS 
  type test_record is record(
    a VARCHAR2(50),
    b VARCHAR2(50));
  type test_table is table of test_record;
  FUNCTION test_function RETURN test_table PIPELINED;
END;
/

CREATE OR replace package body test_package_2 IS 
  FUNCTION test_function RETURN test_table PIPELINED IS 
    t test_record;
  BEGIN
    t.a := 'a';
    t.b := 'b';
    pipe ROW(t);
    t.a := 'c';
    t.b := 'd';
    pipe ROW(t);
    return;
  end test_function;
end test_package_2;
/

select * from table(test_package_2.test_function);

1 użytkowników online, w tym zalogowanych: 0, gości: 1