Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I slice a PL/SQL collection?

I've got a PL/SQL VArray that I'm filling with a BULK COLLECT query like this:

SELECT id
BULK COLLECT INTO myarray
FROM aTable

Now I'd like to pass a slice of this collection into another collection, something like this:

newarray := myarray(2..5)

This should pass the elements 2,3,4 and 5 from myarray to newarray.

I could write a loop and copy the elements, but is there a more compact way to do this?

like image 969
Thorsten Avatar asked Oct 29 '09 10:10

Thorsten


People also ask

Can we create multi dimensional collection in PL SQL?

Description PL/SQL doesn't offer native support for multi-dimensional arrays, as you will find in other programming languages. You can, however, emulate these structures using nested collections.

What is PL SQL collection?

A collection is an ordered group of elements having the same data type. Each element is identified by a unique subscript that represents its position in the collection. PL/SQL provides three collection types − Index-by tables or Associative array.

Which of the following is not true about PL SQL packages?

Answer : C. Q 2 - Which of the following is not true about the PL/SQL language? A - PL/SQL's general syntax is based on that of ADA and Pascal programming language. B - Apart from Oracle, PL/SQL is available in TimesTen in-memory database and IBM DB2.

Why do we use collections in PL SQL?

Using PL/SQL Collections with SQL Statements. Collections let you manipulate complex datatypes within PL/SQL. Your program can compute subscripts to process specific elements in memory, and use SQL to store the results in database tables.


1 Answers

Generally, you don't want to do this. You have a large collection in memory, and now you want to make a copy of it. That would use even more memory. Usually in cases like this you pass the entire collection around (by reference, not value) and also provide a start and stop index. Leave it to the other functions to only process the range specified.

like image 160
Adam Hawkes Avatar answered Oct 13 '22 23:10

Adam Hawkes