2

While refactoring some complex PL/SQL packages for performance, several times I had the following situation:

Input: Two PL/SQL VARRAYs A and B or TABLEs of the same length (for example, SYS.ODCIVarchar2List), e.g.

A := SYS.ODCIVarchar2List('Summer', 'Winter');
B := SYS.ODCIVarchar2List('hot', 'cold');

(The entries in the lists at a given index correspond to each other).

Now, I have a more or less complex SQL statement (e.g. a MERGE INTO) where I need the hypothetical "zip(A,B)" as input.

The only solution I have found until now is a construct like this:

with t1 as (select rownum rn, column_value as season from table(:A))
   , t2 as (select rownum rn, column_value as temperature from table(:B))
   , input as (select t1.season, t2.temperature
               from t1, t2
               where t1.rn = t2.rn
              )
-- Now do something with the input. For demonstration purpose, just show it:
select * from input;

This works, but it seems overly complicated for such a simple task.

Is there a better solution?

Remark: I know about the theoretical uncertainty regarding the order of "select from table(...)". This has always worked, so let's not discuss that here until one day someone can show an example where it doesn't.

As a side note (and to clarify the question further): In Python, I can do this:

L=[1,2]
M=["A","B"]
list(zip(L,M))

and this returns a list of the same length as L and M with the entries combined:

[(1, 'A'), (2, 'B')]

What I need is something like this in SQL.

4

0 回答 0