Is the Oracle syntax diagram for PL / SQL blocks incorrect?

I suspect that the syntax diagram for plsql_block as specified in the Oracle® Database PL / SQL Reference for Relese 2 is incorrect. (For reference here is the current link to this document)

The following PL / SQL fragment compiles fine:

 declare cursor cursor_definition is select * from dual; variable_declaration number; begin null; end; 

The following statements are assumptions that I make based on the PL / SQL snippet above and based on the Oracle syntax diagram.

  • The declare section (above) consists of a cursor definition followed by a variable declaration (which, in turn, is an item declaration ).

  • An item declaration can only be an item list 1 .

  • A cursor definition can only be an item list 2 element.

  • And item list 2 never follow item list 1 .

Now the variable declaration following the cursor definition contradicts point 4. Therefore, I conclude that the syntax diagram is incorrect.

Perhaps I am missing something, in which case I would be very grateful for that.

Please understand that the wrong syntax diagram alone does not really matter to me. But I am in the process of writing a PL / SQL parser and the parser comes across the exact situation specified in the PL / SQL code example. So, to improve the parser, I would like to have a more authoritarian sequence diagram.

+4
source share
1 answer

I agree. The syntax diagrams explicitly state that plsql_block effectively item_list_2 , which is preceded by an optional item_list_1 .

In addition, cursor definitions (with the is bit) can only be found in item_list_2 , and variable declarations (with or without = ) are part of the item_declaration set and therefore can only be found in item_list_1 .

These facts make your code incorrect, so if it manages to compile, then either:

  • The syntax diagrams are incorrect. or
  • the compiler does not follow the letter; or
  • your look at code that applies to various syntax diagrams.

At this last marker point, interestingly, the syntax diagrams for 11.1 are slightly different.

An ad section can be item_list_1 or item_list_2 or item_list_1 followed by item_list_2 .

Interestingly, item_list_1 can have any number of item_declaration entries, and this includes both variable_declaration and cursor_declaration .

In 11.1, a cursor_declaration can be either a declaration or a definition based on language elements in 11.2 (in other words, there is no type cursor_definition , because the declaration allows both in the declaration).

So, what you have is absolutely true in 11.1, so the first thing I will check is that you are actually executing 11.2 where this successful compilation takes place.

It’s still possible that you are using 11.2, and the syntax diagrams are wrong, in which case you should complain about Oracle, but I don’t know what answer you will get from a company whose flagship database product cannot tell the difference between an empty varchar and NULL (a) .


(a) I will never miss the opportunity to mention this and promote the cause of my beloved DB2 :-)

+4
source

All Articles