on 11-21-2014 3:15 PM
hi all,
I am new to HANA and got a requirement as under:
I have a cursor_1 and from it I built another cursor_2 and looping the cursor_2 inside of cursor_1. and the logic is something like this:
For tab1 as cursor_1....
For tab2 as cursor_2....
->here I get 3 fields from the tab2 as tab2.hana_table, tab2.field1 and tab2.field2 -> these will dynamically changed...
now, I need to go to the respective tab2.hana_table and fetch the data present in tab2.field1 and tab2.field2 -> which are also dynamic...
I used different ways of selects as under:
1)va_sql := 'select' || '' || tab2.field1 || '' || tab2.field2 || '' 'into :va_field1_out, :va_field2_out' || '' || 'from' || '' || tab2.hana_table;
execute immediate(va_sql);
2)va_sql := 'select' || ' ' || ‘“’ ||tab2.field1 || ‘“’ || ‘,’ || ‘“’ || tab2.field2 || ‘“’ || 'into :va_field1_out, :va_field2_out' || '' || 'from' || ' ' || tab2.hana_table;
execute immediate(va_sql);
3)va_sql := 'select "tab2.field1" , "tab2.field2" from "tab2.hana_table" into ":va_field1_out" , ":va_field2_out" ';
execute immediate(va_sql);
4)execute immediate 'select ' || :va_field1_in || ', ' || :va_field2_in || 'from ' || :va_hana_table || 'into' || ' ' || :va_field1_out || ', ' || :va_field2_out ;
5)exec 'select ' || tab2.field1 || ' ,' || tab2.field2 || ' from ' || tab2.hana_table || ' into ' || :va_field1_out || ' ,' || :va_field2_out;
I was getting issues like: INTO can't be used in the EXEC or EXECUTE IMMEDIATE and finally I was not able to get values into local variables of the Stored procedure.... Even I tried to achieve the requirement by creating another procedure and thereby get the dynamic table contents, but it did not work out fine....
Please provide inputs on how to write a dynamic select query with fields tab2.hana_table, tab2.field1 and tab2.field2....
Thanks for your help in advance...
Regards,
Vishnu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.