Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table-cast vs cast-multiset in pl-sql

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?

like image 623
Plymouth Rock Avatar asked May 20 '14 09:05

Plymouth Rock


People also ask

What is cast and multiset in Oracle?

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.

What is a multiset in SQL?

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.

What type of operators are used to perform set operations on nested tables?

Multiset operators combine the results of two nested tables into a single nested table.

What is Odcinumberlist?

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.


1 Answers

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.

like image 180
APC Avatar answered Sep 17 '22 19:09

APC