|Oracle® OLAP DML Reference
10g Release 1 (10.1)
Part Number B10339-02
The name of a label elsewhere in the program constructed following the "Guidelines for Constructing a Label". Execution of the program branches to the line directly following the specified label.
Note that label, as specified in GOTO, must not be followed by a colon. However, the actual label elsewhere in the program must end with a colon.
The first character in the label must be a letter, period (
.), or underscore (
The remaining characters in a label can be any combination of letters, numbers, periods, or underscores.
A label must be followed immediately by a colon (
Make sure that the first eight bytes in the label are unique. (Remember that, in your character set, a byte might or might not be equivalent to one character.) A label can contain up to 3999 bytes (the maximum length of a text line minus 1 byte for the colon that identifies a label). However, because only the first eight bytes of a label name are used, you can experience problems with label names greater than eight bytes when the first eight bytes are not unique.
When an actual label that corresponds to label does not exist elsewhere in the same program, execution stops with an error.
THEN GOTO label1
ELSE GOTO label2
However, to preserve the clarity of your programming logic, you should minimize your use of GOTO. You can often replace GOTO with one or more statements executed conditionally using FOR, IF...THEN...ELSE, or WHILE. You can also use the SWITCH command to handle different cases within the same program.
You can use the GOTO command in a FOR loop to branch within, or out of, the loop. This changes the sequence of statement execution, depending on where the GOTO command and the label are positioned.
A GOTO in a FOR loop that branches to a label within the same loop makes execution continue at the label without affecting the current dimension status. Subsequent repetitions of the loop continue normally. To branch to the end of the loop, just before the DOEND command, you should consider using the CONTINUE command instead.
A GOTO in a FOR loop that branches to a label outside the loop terminates the effect of the FOR command. Execution continues at the specified label and dimension status is restored to what it was before the loop. To branch to the statement immediately following the DOEND of a loop, you should consider using the BREAK command instead.
When you use a GOTO command outside a FOR loop to branch into the loop (that is, to a label inside the loop), an error occurs after execution passes through the rest of the loop once.
While GOTO makes it easy to branch within a program, frequent use of it can obscure the logic of your program, making it difficult to follow its flow. This is particularly true when you have a complex program with several labels and GOTO commands that skip over large portions of code.
To keep the logic of your programs clear, minimize your use of GOTO.
Sometimes a GOTO command is the best programming technique, but often there are better alternatives. For example:
When each set of commands is long or you want to use them in more than one place in your program, then you might consider placing them in subprograms. Then, you can use the IF...THEN...ELSE command to choose between two different programs, or use the SWITCH command to choose among many different programs.
Example 14-2 Using GOTO with IF
This example shows a program that will produce a report for one of three areas, depending on what argument the user supplies when running the program. When the user specifies
CENTRAL, execution branches to a corresponding label, and the statements following it (statement group 1, 2, or 3) are executed. When the user specifies anything else, execution branches to the
argerror label, after which statements will handle the error.
DEFINE flexrpt PROGRAM PROGRAM IF NOT INLIST('East\nWest\nCentral', UPCASE(ARG(1))) THEN GOTO argerror SWITCH &UPCASE(ARG(1)) DO CASE 'EAST': ..." (statement group 1) BREAK CASE 'WEST': ... "(statement group 2) BREAK CASE 'CENTRAL': ..." (statement group 3) BREAK DOEND argerror: ..." statements to handle error) END