问题描述:
工作中碰到SQL error,搞不懂的时候就会上网一顿狠查。但因为网文的质量参差不齐,难免会走弯路。今天发现了一个Oracle官方文档《Oracle Database Error Messages》(https://docs.oracle.com/cd/E11882_01/server.112/e17766/toc.htm),感觉是值得参考的。
如,运行以下PL/SQL代码,
--For Example ch11_1b.sql
DECLARE
CURSOR C_MyCursor IS
SELECT *
FROM zipcode
WHERE state = 'NY';
会报错:
ORA-06550: line 6, column 26:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
begin function pragma procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior
推荐方法:
这时,可以在《Oracle Database Error Messages》中查看弹出的error message code,查到的结果如下:
ORA-06550: line string, column string: string
Cause: Usually a PL/SQL compilation error.
Action: None
PLS-00103: string
Cause: This error message is from the parser. It found a token (language element) that is inappropriate in this context.
Action: Check previous tokens as well as the one given in the error message. The line and column numbers given in the error message refer to the end of the faulty language construct.
通过阅读以上说明,我们可以对这两条error message有更深刻的理解,有助于提高调试效率并在今后避免错误。