What is the cast function [message #13393] |
Sun, 11 July 2004 22:50  |
Manisha Kabre
Messages: 1 Registered: July 2004
|
Junior Member |
|
|
Hi
Please let me know, what is the cast function and how it is useful in collections.
And pls let me know what is the use of ref function ?
Thanks.
Manisha
|
|
|
Re: What is the cast function [message #13395 is a reply to message #13393] |
Sun, 11 July 2004 23:28   |
Adrian Billington
Messages: 139 Registered: December 2002
|
Senior Member |
|
|
CAST, as its name suggests, performs transformation between data types. It is useful with collections because it enables us to tell Oracle to recognise a function's return as a collection of our definition ( in 9i, Oracle went one stage further and will now automatically recognise the return from a function as long as it returns a collection type that was created on the database, using CREATE TYPE...). It also enables us to tell Oracle to load a collection of our definition from a SQL statement.
Examples:-
CREATE TYPE ntt_varchar2 AS TABLE OF VARCHAR2(4000);
/
--8i
SELECT *
FROM TABLE( CAST( function_that_returns_array() AS ntt_varchar2 ) );
--9i
SELECT *
FROM TABLE( function_that_returns_array );
--Loading ( useful for bulk loading collections "in-line" )...
SELECT some_table.col
, CAST( MULTISET ( SELECT my_table.my_col
FROM my_table
WHERE my_table.key = some_table.key )
AS ntt_varchar2
FROM some_table;
HTH.
Adrian
|
|
|
|