Oracle的PL/SQL块语法图是否错误? [英] Is Oracle's syntax diagram for PL/SQL blocks wrong?
问题描述
我怀疑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的语法图做出的假设.
-
声明部分(上面)由
cursor definition
和后面的variable declaration
(依次为item declaration
)组成. -
item declaration
只能 是item list 1
的元素. -
cursor definition
只能 是item list 2
的元素. -
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.
The declare section (above) consists of a
cursor definition
followed by avariable declaration
(which in turn is anitem declaration
).An
item declaration
can only be an element of anitem list 1
.A
cursor definition
can only be an element of anitem list 2
.An
item list 2
can never be followed by anitem 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屋!