The PLS-00103 error is a syntax error in PL/SQL that occurs when the PL/SQL compiler encounters an unexpected symbol while parsing the code. This means that something in the code is incorrectly placed, misspelled, or missing.
This error message is often accompanied by a list of expected symbols, which helps in identifying the issue.
Common Causes and Solutions
1. Missing or Incorrect Keywords
Cause:
Using an incorrect or missing keyword in a PL/SQL block.
Example: Incorrect DECLARE
Usage
DECLARE v_name VARCHAR2(50)
BEGIN
v_name := 'John Doe';
DBMS_OUTPUT.PUT_LINE(v_name);
END;
/
Error Output:
PLS-00103: Encountered the symbol "BEGIN" when expecting one of the following: := ; not null constant default
Solution:
Add a semicolon (;
) after the variable declaration.
DECLARE
v_name VARCHAR2(50); -- Fixed: Added semicolon
BEGIN
v_name := 'John Doe';
DBMS_OUTPUT.PUT_LINE(v_name);
END;
/
2. Using a Reserved Keyword as an Identifier
Cause:
Using an Oracle reserved keyword as a variable or table name.
Example: Using SELECT
as a Variable Name
DECLARE
select VARCHAR2(50);
BEGIN
select := 'PL/SQL Error';
DBMS_OUTPUT.PUT_LINE(select);
END;
/
Error Output:
PLS-00103: Encountered the symbol "SELECT" when expecting an identifier
Solution:
Use double quotes or rename the variable.
DECLARE
v_select VARCHAR2(50); -- Fixed: Changed variable name
BEGIN
v_select := 'PL/SQL Error';
DBMS_OUTPUT.PUT_LINE(v_select);
END;
/
Or:
DECLARE
"SELECT" VARCHAR2(50); -- Fixed: Used double quotes
BEGIN
"SELECT" := 'PL/SQL Error';
DBMS_OUTPUT.PUT_LINE("SELECT");
END;
/
However, using double quotes is not recommended, as it makes maintenance difficult.
3. Missing IS
or AS
in a Procedure or Function Declaration
Cause:
A stored procedure is declared without IS
or AS
before the BEGIN
block.
Example: Procedure Without IS
or AS
CREATE OR REPLACE PROCEDURE my_proc
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello');
END;
/
Error Output:
PLS-00103: Encountered the symbol "BEGIN" when expecting one of the following: IS AS AUTHID
Solution:
Add IS
or AS
after the procedure name.
CREATE OR REPLACE PROCEDURE my_proc IS -- Fixed: Added IS
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello');
END;
/
4. Incorrect Usage of IF
Statement
Cause:
Not using THEN
in an IF
statement.
Example: Missing THEN
DECLARE
v_salary NUMBER := 5000;
BEGIN
IF v_salary > 4000 -- Missing THEN
DBMS_OUTPUT.PUT_LINE('High Salary');
END IF;
END;
/
Error Output:
PLS-00103: Encountered the symbol "DBMS_OUTPUT.PUT_LINE" when expecting one of the following: THEN
Solution:
Add THEN
after the IF
condition.
DECLARE
v_salary NUMBER := 5000;
BEGIN
IF v_salary > 4000 THEN -- Fixed: Added THEN
DBMS_OUTPUT.PUT_LINE('High Salary');
END IF;
END;
/
5. Incorrect Placement of EXCEPTION
Block
Cause:
Placing EXCEPTION
outside a BEGIN-END
block.
Example: Incorrect Exception Placement
DECLARE
v_number NUMBER := 10;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('An error occurred');
BEGIN
v_number := v_number / 0;
END;
/
Error Output:
PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following: ...
Solution:
Move EXCEPTION
inside the BEGIN-END
block.
DECLARE
v_number NUMBER := 10;
BEGIN
v_number := v_number / 0;
EXCEPTION
WHEN OTHERS THEN -- Fixed: Placed inside BEGIN-END
DBMS_OUTPUT.PUT_LINE('An error occurred');
END;
/
6. Incorrect Loop Syntax
Cause:
Not using LOOP
or END LOOP
.
Example: Missing LOOP
Keyword
DECLARE
v_counter NUMBER := 1;
BEGIN
WHILE v_counter <= 5 -- Missing LOOP
DBMS_OUTPUT.PUT_LINE(v_counter);
v_counter := v_counter + 1;
END LOOP;
END;
/
Error Output:
PLS-00103: Encountered the symbol "DBMS_OUTPUT.PUT_LINE" when expecting one of the following: LOOP
Solution:
Add LOOP
after the WHILE
condition.
DECLARE
v_counter NUMBER := 1;
BEGIN
WHILE v_counter <= 5 LOOP -- Fixed: Added LOOP
DBMS_OUTPUT.PUT_LINE(v_counter);
v_counter := v_counter + 1;
END LOOP;
END;
/
Summary of Solutions
Cause | Solution |
---|---|
Missing semicolon (; ) | Add ; where required |
Using reserved keywords | Rename variables or use double quotes |
Incorrect procedure/function syntax | Ensure IS or AS is present |
Missing THEN in IF statement | Add THEN after the condition |
Placing EXCEPTION outside BEGIN-END | Move EXCEPTION inside the block |
Incorrect LOOP structure | Ensure LOOP and END LOOP are used |
Conclusion
The PLS-00103 error is one of the most common PL/SQL errors, but it is also one of the easiest to fix once you identify the cause. By carefully checking for syntax issues, missing keywords, misplaced statements, and incorrect variable names, you can quickly resolve this error and ensure that your PL/SQL code runs smoothly.