on 2019 Jan 28 3:21 PM
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
From the FOR statement doc topic:
The LEAVE statement can be used to resume execution at the first statement after the END FOR. If the ending statement-label is specified, it must match the beginning statement-label.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
User | Count |
---|---|
79 | |
10 | |
10 | |
10 | |
10 | |
9 | |
8 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.