I recently learned that you can return a collection in a sql query, for example like this:
select cast (multiset (select поле from таблица) as тип коллекции) from dual Why is it necessary in sql, if you can work with collections in pl / sql code?
I recently learned that you can return a collection in a sql query, for example like this:
select cast (multiset (select поле from таблица) as тип коллекции) from dual Why is it necessary in sql, if you can work with collections in pl / sql code?
In your example, the cast function with the multiset keyword converts a set of relational data into an sql collection. The main purpose is to manipulate data in tables with columns declared as collections.
Another application is the mapping of a classical schema with a relational data model with an object-relational through object representations.
A small example:
create or replace type myItemType as object (id number, name varchar(32)); / --Type MYITEMTYPE compiled create type myItemArrayType as table of myItemType; / --Type MYITEMARRAYTYPE compiled create table myItems (items myItemArrayType) nested table items store as items_table; / --Table MYITEMS created. -- обычное занесение одного значения insert into myItems values (myItemArrayType(myItemType(0, 'item 0'))); --1 row inserted. -- заполнене коллекции из реляционной таблицы (вместо dual здесь одна или несколько таблиц) insert into myItems select cast(multiset( select level, 'item ' || level from dual connect by level <= 5 ) as myItemArrayType) from dual ; --1 row inserted. select items.* from myItems, table(items) items; ID NAME -- ------ 0 item 0 1 item 1 2 item 2 3 item 3 4 item 4 5 item 5 Conclusion - item 0 from the first line, item 1 - item 5 from the second.
Previous answer
The question was changed and in the original version it was about applying methods for working with collections in sql expressions.
Methods for working with collections can not be used in SQL expressions.
In the Oracle documentation:
A collection method of PL / SQL can be used, where you can find a SQL statement .
PS Maybe you mean something else under the definition of "methods for working with collections"? See an example.
Source: https://ru.stackoverflow.com/questions/579176/
All Articles