Oracle的PL/SQL块语法图是否错误? [英] Is Oracle's syntax diagram for PL/SQL blocks wrong?

查看:112
本文介绍了Oracle的PL/SQL块语法图是否错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怀疑plsql_block的语法图如 Relese 2的Oracle®数据库PL/SQL语言参考错误. (作为参考,此处是当前链接该文档)

下面的PL/SQL可以很好地编译:

declare

  cursor 
    cursor_definition 
  is select * from dual;

  variable_declaration number;

begin
  null;
end;

以下陈述是基于上面的PL/SQL和Oracle的语法图做出的假设.

  1. 声明部分(上面)由cursor definition和后面的variable declaration(依次为item declaration)组成.

  2. item declaration只能 item list 1的元素.

  3. cursor definition只能 item list 2的元素.

  4. item list 2绝不能跟在item list 1之后.

现在,cursor definition之后的variable declaration第4点相矛盾.因此,我得出的结论是 语法图是错误的.

也许我忽略了某些事情,在这种情况下,我会非常感激向我指出这一点.

请理解,错误的语法图本身对我来说并不重要.但是我正在编写一个PL/SQL解析器 并且解析器偶然发现了示例PL/SQL代码给出的确切情况.因此,为了改善解析器,我想 以获得更具权威性的序列图.

解决方案

我同意.语法图明确指出,plsql_block实际上是item_list_2,后面是可选的item_list_1.

此外,游标定义(带有is位)只能出现在item_list_2中,而变量声明(带有或不带有=)是item_declaration设置的一部分,并且因此只能在item_list_1中.

这些事实使您的代码示例不正确,因此,如果成功进行编译,则可以:

  • 语法图是错误的;或
  • 编译器没有遵循它们;或
  • 您查看的不同语法图所涵盖的代码.

在最后一个要点上,有趣的是,here's the current link to that document)

The following piece of PL/SQL 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 piece of PL/SQL above and based on Oracle's syntax diagram.

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

  2. An item declaration can only be an element of an item list 1.

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

  4. An item list 2 can never be followed by an item list 1.

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

Maybe I am overlooking something, in which case I'd be very grateful for pointing this out to me.

Please understand that a wrong syntax diagram per se is no big deal to me. But I am in the process of writing a PL/SQL parser and the parser stumbles for the exact situation given with the example PL/SQL code. So, in order to improve the parser, I'd like to have a more authorative sequence diagram.

解决方案

I concur. The syntax diagrams explicitly state that a plsql_block is effectively item_list_2 preceded by an optional item_list_1.

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

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

  • the syntax diagrams are wrong; or
  • the compiler doesn't follow them to the letter; or
  • your looking at code that's covered by different syntax diagrams.

On that last bullet point, interestingly enough, the syntax diagrams for 11.1 are slightly different.

The declare section can be item_list_1 or item_list_2 or item_list_1 followed by item_list_2.

Where it gets interesting is that 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 the language elements in 11.2 (in other words, there is no cursor_definition type since the declaration allows both in the declaration).

So what you have is perfectly valid in 11.1 so the first thing I'd check is that you're actually running 11.2 where that successful compilation is taking place.

It's still possible of course that you're running 11.2 and the syntax diagrams are wrong, in which case you should complain bitterly to Oracle but I don't know what sort of a response you'll get from a company whose flagship database product can't tell the difference between an empty varchar and a NULL (a).


(a) I'll never pass up an opportunity to mention this and advance the cause of my beloved DB2 :-)

这篇关于Oracle的PL/SQL块语法图是否错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆