Hooplator15
Hooplator15

Reputation: 1550

PL SQL - How to iterate for each column in a select statement?

I have declared a table array type would like to add a bunch of values to the array so that I can later perform a select distinct from the array.

My values to be added to the array are strings like this:

"1","2","3", ..... 

I want to add each string to the array maybe something like:

FOR i IN SELECT "1","2","3" LOOP
    myarray(i) := ????

then later I want to select distinct values from the array. Is there an easy way to do this?

If I was doing this in SQL server, I would simply create a temp table, insert my values into the table, then select distinct from that table, but I am not sure if this is the best way with oracle?

Upvotes: 0

Views: 390

Answers (1)

Bryan Dellinger
Bryan Dellinger

Reputation: 5294

would this work select distinct t.column_value from table(sys.odcivarchar2list('1','2','3','4','5', '1'))t;

Upvotes: 2

Related Questions