0

Can we declare and open a cursor for UPDATE query also or is it only for SELECT queries?

   EXEC SQL PREPARE S FROM :query;
   EXEC SQL DECLARE C CURSOR FOR S;
   DbUtilT::set_bind_variables(bind_dp,&paramList);
   EXEC SQL OPEN C USING DESCRIPTOR bind_dp;
   EXEC SQL WHENEVER NOT FOUND GOTO end_update_loop;
   EXEC SQL FETCH C USING DESCRIPTOR bind_dp;
   EXEC SQL COMMIT WORK;

Is this fine? Or should we use cursor only for SELECT statments then how do we execute UPDATE queries?

user862833
  • 299
  • 2
  • 5
  • 16

1 Answers1

1

If query is something like:

SELECT id FROM mytable WHERE ... FOR UPDATE OF id

then you can do:

...
EXEC SQL FETCH C USING DESCRIPTOR bind_dp;
EXEC SQL UPDATE mytable SET id = <something> WHERE CURRENT OF C;

I'm not quite sure what you mean though; you don't have to use a cursor to do an update, you can do:

EXEC SQL UPDATE mytable SET id = <something> WHERE ...;

... or the equivalent prepared statement.

Have I completely misunderstood the question?

Alex Poole
  • 183,384
  • 11
  • 179
  • 318
  • Ya thats right when we donot have bind variables in the query. If i am using bind variables in the query.. Update set =:BIND_VAR1 where =:BINDVAR2 and =:BINDVAR3 how to go by? – user862833 Apr 17 '13 at 10:16