How many ways are there to name the output columns of a pipelined table function?
My understanding is the only way is via a RECORD type like this:
CREATE PACKAGE blah_blah_blah IS
TYPE abc_rec IS RECORD (ID NUMBER,
SUBJECT VARCHAR2(30),
BODY VARCHAR2(4000));
TYPE abc_rec_table IS TABLE OF abc_rec;
FUNCTION xyz RETURN abc_rec_table PIPELINED;
END blah_blah_blah;
SELECT *
FROM blah_blah_blah.xyz;
ID SUBJECT BODY
== =========== ========
1 Subject One Body One
2 Subject Two Body Two
3 Subject Three Body Three
I had hoped that it was possible to name them after cursor columns, but that results in the columns being named: ATTR_1, ATTR_2, ATTR_3, etc. instead.
CREATE PACKAGE blah_blah_blah IS
CURSOR C1 IS
SELECT CAST(ID AS NUMBER) AS ID,
CAST(SUBJECT AS VARCHAR2(30)) AS SUBJECT,
CAST(BODY AS VARCHAR2(4000)) AS BODY
FROM <my table>;
TYPE abc_rec_table IS TABLE OF C1%ROWTYPE;
FUNCTION xyz RETURN abc_rec_table PIPELINED;
END blah_blah_blah;
ATTR_1 ATTR_2 ATTR_3
====== ============= ========
1 Subject One Body One
2 Subject Two Body Two
3 Subject Three Body Three
I don't know of a way to override the ATTR* names you get when using cursor-based data types.
So I believe you have to use records (or object types) as in your first example.