Home » SQL & PL/SQL » SQL & PL/SQL » What is the cast function
What is the cast function [message #13393] Sun, 11 July 2004 22:50 Go to next message
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 Go to previous messageGo to next message
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
Re: What is the cast function [message #13396 is a reply to message #13395] Sun, 11 July 2004 23:29 Go to previous message
Adrian Billington
Messages: 139
Registered: December 2002
Senior Member
Ooops, missing a closing bracket on the last example. Should read CAST( MULISET ( SELECT ... ) AS ntt_varchar2 )...
Previous Topic: function return values
Next Topic: What Oracle Version is best suited for VB 6.0?
Goto Forum:
  


Current Time: Sun Aug 03 21:43:31 CDT 2025