Quantcast

Jump to content


Photo

REPEAT in MySQL JDBC without stored procedure


  • Please log in to reply
2 replies to this topic

#1 Sida

Sida
  • Tsvetesman

  • 3865 posts

Posted 08 November 2011 - 04:13 AM

Is it possible to perform a REPEAT in MySQL without containing it within a stored procedure when using JDBC? I'm trying to do a recursive delete making use of LIMIT within a REPEAT until finished to avoid locking the table. For example:

REPEAT
DELETE FROM example WHERE eg > 1 LIMIT 5000
UNTIL row_count() = 0 END REPEAT

I've only been able to get something like this to work within a stored procedure like below, which I'd like to avoid if possible.


              """delimiter //
                 CREATE PROCEDURE untilEmpty ()
                 BEGIN
                 REPEAT """ + stmt + """ LIMIT 5000; UNTIL ROW_COUNT() = 0 END REPEAT;
                 END//
                 delimiter ;
                 CALL untilEmpty();

I'm using Groovy SQL if that helps.

#2 Pyro699

Pyro699
  • 1543 posts


Users Awards

Posted 08 November 2011 - 06:55 AM

Is it possible to perform a REPEAT in MySQL without containing it within a stored procedure when using JDBC? I'm trying to do a recursive delete making use of LIMIT within a REPEAT until finished to avoid locking the table. For example:

REPEAT
DELETE FROM example WHERE eg > 1 LIMIT 5000
UNTIL row_count() = 0 END REPEAT

I've only been able to get something like this to work within a stored procedure like below, which I'd like to avoid if possible.


              """delimiter //
                 CREATE PROCEDURE untilEmpty ()
                 BEGIN
                 REPEAT """ + stmt + """ LIMIT 5000; UNTIL ROW_COUNT() = 0 END REPEAT;
                 END//
                 delimiter ;
                 CALL untilEmpty();

I'm using Groovy SQL if that helps.


http://publib.boulde...in/r0005653.htm

Invocation

This statement can only be embedded in an SQL procedure. It is not an executable statement and cannot be dynamically prepared.



#3 Sida

Sida
  • Tsvetesman

  • 3865 posts

Posted 08 November 2011 - 07:04 AM

Bleh, thought so.

Cheers dude.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users