Declare result set variable in procedural SQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • FLANDERS
    New Member
    • Jul 2008
    • 8

    Declare result set variable in procedural SQL

    Hi all,
    Is it possible to declare a SQL type of result set or similar? I want to do use the IN predicate like you can in a non-procedural SQL like this:
    Code:
    UPDATE TABLE1 SET COL1 = 123 WHERE COL2 IN (SELECT COL3 FROM TABLE2)
    I want to do this in procedural SQL, but I only want to use one cursor. So to do this I have declared a cursor for selecting COL2 from TABLE1 into a variable v_COL2 and am using a loop to iterate over the values. Inside the loop I want to perform the IN predicate check as follows:

    Code:
    IF v_COL2 IN (v_SQL_RESULT_SET) THEN
         UPDATE TABLE1 SET COL1 = 123 WHERE ..........;
    My question is how do I (or can I) declare the v_SQL_RESULT_SE T so I only need to execute the query once at the start, rather than using a cursor or re-executing the query each time inside the IF. Is there a data type to allow me to do something like

    Code:
    DECLARE v_SQL_RESULT_SET <DATA_TYPE>;
    
    SELECT COL3 INTO v_SQL_RESULT_SET FROM TABLE2;
    Thanks for any info
Working...