Oracle Pipelined function Oracle Pipelined function oracle oracle

Oracle Pipelined function


ORA 00932 inconsistent datatypes expected udt got number

You get this because your code assigns a scalar to the output type. You need to cast the variable to match the assignment target. So:

   SELECT type_struct(counter)    INTO rec    FROM dual;

You don't necessarily need a pipelined function. We can use table() with any function which returns a collection.

Here is a much simpler implementation, which requires only one UDT.

CREATE TYPE tp_numbers AS TABLE OF number;/CREATE OR REPLACE FUNCTION gen_nums (na NUMBER, nb NUMBER)RETURN tp_numbers IS    return_value tp_numbers ;BEGIN    SELECT (na + level) - 1     bulk collect    INTO return_value      FROM dual    connect by level <= nb;    RETURN return_value ;END gen_nums;/


CREATE OR REPLACE FUNCTION gen_nums (na NUMBER, nb NUMBER)RETURN sys.DBMS_DEBUG_VC2COLL PIPELINED --sys.DBMS_DEBUG_VC2COLL an oracle provided collection type.IS    counter NUMBER;BEGIN    counter := na;    WHILE (counter <= nb)    LOOP        PIPE ROW (counter);        counter := counter + 1;    END LOOP;    RETURN;END gen_nums;