Skip to Main Content

Loop labels

Sort OrderLoop NameX
1A1
2B101
3A2
4B101

Loop labels can come in handy, but it turns out you can put them in the wrong place and still get valid pl/sql code.

In this example, the closing label of loop_b has a "typo" and the closing label of loop_a should have been "loop_a", not "loop_b". I would expect both of these lines to result in a compilation error, but they don't.
The Oracle documentation states: "Labels improve readability, especially when LOOP statements are nested, but only if you ensure that the label in the END LOOP statement matches a label at the beginning of the same LOOP statement (the compiler does not check)."
So it works as advertised, but it did catch me by surprise.

Note that the exit statement also still works OK, so the end labels are indeed simply ignored.

Code

Region

Identification
Sequence
Title
Type
Source
Location
Query Type
Region Source

Package

Package
Name
Source

Package Body

Package Body
Name
Source