Today, we will understand how to interpret the compile time erros and fix them. Don't confuse with runtime errors which is altogether a different subject called Exception Handling.
Compilation erros are normally typing errors or lexical error/syntax errors.
For Ex: 1. Misspelling a keyword/reserved word or forgetting a keyword itself
2. Forgetting to close a brace or a delimiter etc.
3. Forgetting a semicolon.
Compiler would throw an error in such cases and this lesson is to teach you to understand those patterns of errors. Basically, there are 3 patterns as
1. Prior line
2. Current line
3. Declaration Error.
Let us start with examples.
Example 1:
SQL> BEGIN
2 dbms_output.put_line('Hello World!')
3 END;
4 /
Error report -
ORA-06550: line 3, column 1:
PLS-00103: Encountered the symbol "END" when expecting one of the following:
:= . ( % ;
The symbol ";" was substituted for "END" to continue.
Explanation: Prior line error points to an error in the prior statement line, which is mostly a missing semicolon error as in above example. observe the column no. which always says 1 for prior line error, which means beginning of the line or end of the prveious line.
Example 2:
SQL> DECLARE
2 a Number :=7;
3 b Number :=5;
4 c Number;
5 BEGIN
6 c := a b;
7 dbms_output.put_line('The value of c : '||c);
8 END;
9 /
Error report -
ORA-06550: line 6, column 11:
PLS-00103: Encountered the symbol "B" when expecting one of the following:
. ( * @ % & = - + ; < / > at in is mod remainder not rem
<> or != or ~= >= <= <> and or like like2
like4 likec between || multiset member submultiset
The symbol "." was substituted for "B" to continue.
Explanation: Current line error points to the column of the error or one column after the error. This occurs normally because of missing lexical unit as in above example. Error is at line no. 6 and column 10.
If you are using SQL* Plus, you would also get an asterisk placed right below the column or below the one column right after the error. In case of prior line error, asterisk would be placed immediately below where the error occurs in a statement line.
Example 3:
SQL> DECLARE
2 a CHAR := 'AB';
3 BEGIN
4 dbms_output.put_line('a contains : '||a);
5 END;
6 /
DECLARE
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 2
Explanation: When an error occurs in Declaration section, the above discussed logic doesn't apply. We get some less obvious error message as in the above example. Error line no. is 1, but that doesn't mean that error occurred before the declaration block.It tells you that error occurs in the declaration section and the last line in the error message points to the specific error line no. This output is from SQL* Plus, unlike other two examples and hence asterisk is placed.