Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Storing result set as a variable in a procedure - response (3) by akhilkotak

$
0
0

Hi,
Thank you for your reply. I have got a cursor working, but currently it does it stop at the end of the result set. It ends up stuck in the loop and repeatedly processes the last row of the column until I cancel the query.
 
I know the part 'sqlcode=0' may not be the most appropriate but any ideas what could replace this. I was thinking about doing a SELECT COUNT(*) from table1 and somehow passing it into the while loop but not sure how.
 
Another question I have is, instead of the INSERT statement, I want to concatenate all the rows of the column into the following format: 'row1','row2','row3' etc.

I tried the following: SET param3 = '' param3 ||',' field1 '';    with the intention that every time the loop goes around, the new row will be added to the end of param3, but this gives me the error 'Illegal attempt to modify symbol 'param3'.'

This is all because I need to pass the combination of the rows as one string, as a variable, into a function.
 

I have pasted the code below. Thanks!
 
 
REPLACE PROCEDURE test (IN param1 VARCHAR(200), INOUT param2 VARCHAR(200), OUT param3 VARCHAR (200))
BEGIN 
DECLARE field1 VARCHAR(200);
DECLARE my_cursor CURSOR FOR
   SELECT column1 FROM table1 WHERE column2 = :param1;
   OPEN my_cursor;
   MainLoop:WHILE (sqlcode=0) DO
        FETCH  my_cursor INTO field1, param2;
        INSERT INTO table2 VALUES (:field1, :param2);
   END WHILE MainLoop;
  CLOSE my_cursor;
END;

 


Viewing all articles
Browse latest Browse all 14773

Trending Articles



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