Thursday, March 15, 2007

Pipelined functions implicitly create SQL level TYPES

In the "I learn something new every day" category, Solomon Yakobson pointed out something in a post on the Quest Pipelines forum, "under PL/SQL Tables, Nested Tables, & VARRAYS » Problem in executing Function which returns collection".

Apparently, under the sheets a PIPELINED function will create SQL types and collection types.

If you run...

CREATE OR REPLACE PACKAGE PFP_CONSTANTS_PKG IS
TYPE v_rec IS RECORD
(
v_date DATE,
v_mon NUMBER(2)
);
TYPE v_array IS TABLE OF v_rec;
function dummy return v_array pipelined;
END;
/
and then check USER_TYPES, you'll find that it creates three types prefixed by SYS_PLSQL_, followed by a number (which looks like it corresponds to the OBJECT_ID visible in USER_OBJECTS) and the rest of the identifier.

So if you find some types with that sort of prefix, you'll be able to track back to the package which created them.

2 comments:

Laurent Schneider said...

> I learn something new every day

me too, thank YOU

Tim... said...

I've had some problems with this implicit object creation in the past. The major one being the record type defined in the package getting out of step with the schema object type. It shouldn't happen, as Oracle should manage it, but it does, and it's very confusing for developers if they don't know what is going on.

As a result, I never use this feature, preferring to explicitly create the relevant database object types. That way they get a decent name also. :)

Cheers

Tim...