What is the use of Table-CAST
and CAST-Multiset
?
Example of Table-Cast
SELECT count(1)
INTO v_Temp
FROM TABLE(CAST(Pi_Save_Data_List AS Property_data_list))
WHERE Column_Value LIKE '%Contact';
Example of Cast-Multiset
SELECT e.last_name,
CAST(MULTISET(SELECT p.project_name
FROM projects p
WHERE p.employee_id = e.employee_id
ORDER BY p.project_name)
AS project_table_typ)
FROM emps_short e;
What isthe performance gain or impact on the code?
If expr is an instance of an ANYDATA type, CAST will try to extract the value of the ANYDATA instance and return it if it matches the cast target type, otherwise, null will be returned. MULTISET informs Oracle Database to take the result set of the subquery and return a collection value.
The MULTISET data type is a collection type that stores a non-ordered set that can include duplicate element values. The elements in a MULTISET have no ordinal position. That is, there is no concept of a first, second, or third element in a MULTISET.
Multiset operators combine the results of two nested tables into a single nested table.
ODCINUMBERLIST is a varying array (or varray) of NUMBER. ODCIDATELIST (10g) is an array of DATE, ODCIRAWLIST (10g) is an array of RAW(2000) and ODCIVARCHAR2LIST (10g) is an array of VARCHAR2(4000). Note the inaccurate row count! TABLE is a function that transforms the collection in a table.
The TABLE() function casts a nested table type to a relational result set. This is allows us to query a previously populated collection in SQL.
The CAST(MULTISET()) function call converts a relational result set into a collection type. This is primarily of use when inserting into a table with column defined as a nested table.
Few sites employ object-relational features in their permanent data structures so the second usage is pretty rare. But being able to use collections in embedded SQL statements is a very cool technique, and widely used in PL/SQL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With