Quantcast
Channel: SCN : Discussion List - SAP HANA and In-Memory Computing
Viewing all articles
Browse latest Browse all 5653

Array iteration in SQL script.

$
0
0

Hi Experts,

I have a table as follows :

 

SNO

VARIABLE

VALUE

1

x

10

2

x

20

3

x

30

4

y

40

 

I am getting x, y variable name using forllowing query:

 

VARIABLE_NAME= SELECT DISTINCT VARIABLE,VALUE FROM table_name ;

VARIABLE_NAME_ARRAY=ARRAY_AGG(:VARIABLE_NAME.VARIABLE); */

 

Now I want to get Values related to variable x in one array i.e., [10,20,30] and y in one more [40]

I am trying to achieve it using following code

 

FOR i IN 1 ..:ROW_COUNT-1

DO

 

VALUE_ARRAY = SELECT VALUE FROM table_name WHERE VARIABLE_NAME=:VARIABLE_ARRAY[:i];

 

END FOR;

 

but the problem here is SELECT statement is not accepting VARIABLE_ARRAY[:i] in WHERE clause and I want to

declare VALUE_ARRAY as dynamic variable as number of distinct variables may vary.


-> How can I declare variables dynamically or is there a way to declare 2 dimensional array and use it in my scenario?

 

I tried using CURSORS, again there I encounter the problem of dynamic variable declaration.

 

Could you guys please let me know how can I achieve this, or is there any other method to achieve this using SQLScript?

 

Regards,

Vijay.


Viewing all articles
Browse latest Browse all 5653

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>