Simple question I hope. Using 12, 16 and 17 can I leave a for loop in a procedure FOR LoopName AS CursorName INSENSITIVE CURSOR FOR SELECT STATEMENT DO IF Condition Exists THEN LEAVE LoopName; END IF; END FOR; |
The "beginning statement-label" in Volker's reply is not the "FOR LoopName" but a separate label in front of the FOR. It can be the same text name, however... there's no collision: BEGIN LoopName: FOR LoopName AS CursorName INSENSITIVE CURSOR FOR SELECT row_num AS @row_num FROM rowgenerator ORDER BY row_num DO IF @row_num > 2 THEN LEAVE LoopName; END IF; MESSAGE STRING ( '@row_num = ', @row_num ) TO CONSOLE; END FOR; MESSAGE STRING ( 'done' ) TO CONSOLE; END; @row_num = 1 @row_num = 2 done |
From the FOR statement doc topic:
Here's a variant of Breck's sample with LEAVE without a statement-lable: BEGIN FOR LoopName AS CursorName INSENSITIVE CURSOR FOR SELECT row_num AS @row_num FROM rowgenerator ORDER BY row_num DO IF @row_num > 2 THEN LEAVE; END IF; MESSAGE STRING ( '@row_num = ', @row_num ) TO CONSOLE; END FOR; MESSAGE STRING ( 'done leaving without a statement name' ) TO CONSOLE; END; displays @row_num = 1 @row_num = 2 done leaving without a statement name Breck/Vollker - Thanks very much. I'm working on an interesting application in which we are using SQL Anywhere to interface with an IIoT appliance running Linux and MySQL. The appliance interfaces with an OPC UA server stores the data in the local MySQL database for eventual retrieval by SQL Anywhere using the integral HTTP Get statements which is fired via a database Event. This loop enumerates the data available and must validate several variables before saving to both a local SQL Anywhere table as well as outputting in a compressed format to a SQL Anywhere directory server. It's amazing how easy SQL Anywhere flows this to happen with all built in functionality. Thanks Again Jim PS See my next question on directory server free space
(29 Jan '19, 07:16)
J Diaz
|