{"id":1920,"date":"2025-02-16T10:41:06","date_gmt":"2025-02-16T15:41:06","guid":{"rendered":"https:\/\/molecularsciences.org\/content\/?p=1920"},"modified":"2025-03-03T15:10:55","modified_gmt":"2025-03-03T20:10:55","slug":"how-to-solve-pls-00103-encountered-the-symbol-when-expecting-one-of-the-following","status":"publish","type":"post","link":"https:\/\/molecularsciences.org\/content\/how-to-solve-pls-00103-encountered-the-symbol-when-expecting-one-of-the-following\/","title":{"rendered":"How to Solve PLS-00103: Encountered the Symbol When Expecting Once of the Following"},"content":{"rendered":"\n<p>The <strong>PLS-00103<\/strong> error is a <strong>syntax error<\/strong> in PL\/SQL that occurs when the PL\/SQL compiler encounters an <strong>unexpected symbol<\/strong> while parsing the code. This means that something in the code is <strong>incorrectly placed<\/strong>, <strong>misspelled<\/strong>, or <strong>missing<\/strong>.<\/p>\n\n\n\n<p>This error message is often accompanied by <strong>a list of expected symbols<\/strong>, which helps in identifying the issue.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Common Causes and Solutions<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Missing or Incorrect Keywords<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Cause:<\/strong><\/h4>\n\n\n\n<p>Using an incorrect or missing keyword in a PL\/SQL block.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example: Incorrect <code>DECLARE<\/code> Usage<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>DECLARE v_name VARCHAR2(50)<br>BEGIN<br>    v_name := 'John Doe';<br>    DBMS_OUTPUT.PUT_LINE(v_name);<br>END;<br>\/<br><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Error Output:<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>PLS-00103: Encountered the symbol \"BEGIN\" when expecting one of the following: := ; not null constant default<br><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Solution:<\/strong><\/h4>\n\n\n\n<p>Add a semicolon (<code>;<\/code>) after the variable declaration.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>DECLARE <br>    v_name VARCHAR2(50);  -- Fixed: Added semicolon<br>BEGIN<br>    v_name := 'John Doe';<br>    DBMS_OUTPUT.PUT_LINE(v_name);<br>END;<br>\/<br><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Using a Reserved Keyword as an Identifier<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Cause:<\/strong><\/h4>\n\n\n\n<p>Using an Oracle <strong>reserved keyword<\/strong> as a variable or table name.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example: Using <code>SELECT<\/code> as a Variable Name<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>DECLARE <br>    select VARCHAR2(50);<br>BEGIN<br>    select := 'PL\/SQL Error';<br>    DBMS_OUTPUT.PUT_LINE(select);<br>END;<br>\/<br><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Error Output:<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>PLS-00103: Encountered the symbol \"SELECT\" when expecting an identifier<br><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Solution:<\/strong><\/h4>\n\n\n\n<p>Use double quotes or rename the variable.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>DECLARE <br>    v_select VARCHAR2(50);  -- Fixed: Changed variable name<br>BEGIN<br>    v_select := 'PL\/SQL Error';<br>    DBMS_OUTPUT.PUT_LINE(v_select);<br>END;<br>\/<br><\/code><\/pre>\n\n\n\n<p>Or:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>DECLARE <br>    \"SELECT\" VARCHAR2(50);  -- Fixed: Used double quotes<br>BEGIN<br>    \"SELECT\" := 'PL\/SQL Error';<br>    DBMS_OUTPUT.PUT_LINE(\"SELECT\");<br>END;<br>\/<br><\/code><\/pre>\n\n\n\n<p>However, using double quotes is <strong>not recommended<\/strong>, as it makes maintenance difficult.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Missing <code>IS<\/code> or <code>AS<\/code> in a Procedure or Function Declaration<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Cause:<\/strong><\/h4>\n\n\n\n<p>A stored procedure is declared <strong>without <code>IS<\/code> or <code>AS<\/code><\/strong> before the <code>BEGIN<\/code> block.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example: Procedure Without <code>IS<\/code> or <code>AS<\/code><\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>CREATE OR REPLACE PROCEDURE my_proc <br>BEGIN<br>    DBMS_OUTPUT.PUT_LINE('Hello');<br>END;<br>\/<br><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Error Output:<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>PLS-00103: Encountered the symbol \"BEGIN\" when expecting one of the following: IS AS AUTHID<br><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Solution:<\/strong><\/h4>\n\n\n\n<p>Add <code>IS<\/code> or <code>AS<\/code> after the procedure name.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>CREATE OR REPLACE PROCEDURE my_proc IS  -- Fixed: Added IS<br>BEGIN<br>    DBMS_OUTPUT.PUT_LINE('Hello');<br>END;<br>\/<br><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Incorrect Usage of <code>IF<\/code> Statement<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Cause:<\/strong><\/h4>\n\n\n\n<p>Not using <code>THEN<\/code> in an <code>IF<\/code> statement.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example: Missing <code>THEN<\/code><\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>DECLARE<br>    v_salary NUMBER := 5000;<br>BEGIN<br>    IF v_salary > 4000  -- Missing THEN<br>        DBMS_OUTPUT.PUT_LINE('High Salary');<br>    END IF;<br>END;<br>\/<br><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Error Output:<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>PLS-00103: Encountered the symbol \"DBMS_OUTPUT.PUT_LINE\" when expecting one of the following: THEN<br><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Solution:<\/strong><\/h4>\n\n\n\n<p>Add <code>THEN<\/code> after the <code>IF<\/code> condition.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>DECLARE<br>    v_salary NUMBER := 5000;<br>BEGIN<br>    IF v_salary > 4000 THEN  -- Fixed: Added THEN<br>        DBMS_OUTPUT.PUT_LINE('High Salary');<br>    END IF;<br>END;<br>\/<br><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Incorrect Placement of <code>EXCEPTION<\/code> Block<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Cause:<\/strong><\/h4>\n\n\n\n<p>Placing <code>EXCEPTION<\/code> outside a <code>BEGIN-END<\/code> block.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example: Incorrect Exception Placement<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>DECLARE<br>    v_number NUMBER := 10;<br>EXCEPTION<br>    WHEN OTHERS THEN<br>        DBMS_OUTPUT.PUT_LINE('An error occurred');<br>BEGIN<br>    v_number := v_number \/ 0;<br>END;<br>\/<br><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Error Output:<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>PLS-00103: Encountered the symbol \"EXCEPTION\" when expecting one of the following: ...<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Solution:<\/strong><\/h4>\n\n\n\n<p>Move <code>EXCEPTION<\/code> inside the <code>BEGIN-END<\/code> block.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>DECLARE<br>    v_number NUMBER := 10;<br>BEGIN<br>    v_number := v_number \/ 0;<br>EXCEPTION<br>    WHEN OTHERS THEN  -- Fixed: Placed inside BEGIN-END<br>        DBMS_OUTPUT.PUT_LINE('An error occurred');<br>END;<br>\/<br><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Incorrect Loop Syntax<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Cause:<\/strong><\/h4>\n\n\n\n<p>Not using <code>LOOP<\/code> or <code>END LOOP<\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Example: Missing <code>LOOP<\/code> Keyword<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>DECLARE<br>    v_counter NUMBER := 1;<br>BEGIN<br>    WHILE v_counter &lt;= 5  -- Missing LOOP<br>        DBMS_OUTPUT.PUT_LINE(v_counter);<br>        v_counter := v_counter + 1;<br>    END LOOP;<br>END;<br>\/<br><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Error Output:<\/strong><\/h4>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>PLS-00103: Encountered the symbol \"DBMS_OUTPUT.PUT_LINE\" when expecting one of the following: LOOP<br><\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Solution:<\/strong><\/h4>\n\n\n\n<p>Add <code>LOOP<\/code> after the <code>WHILE<\/code> condition.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>DECLARE<br>    v_counter NUMBER := 1;<br>BEGIN<br>    WHILE v_counter &lt;= 5 LOOP  -- Fixed: Added LOOP<br>        DBMS_OUTPUT.PUT_LINE(v_counter);<br>        v_counter := v_counter + 1;<br>    END LOOP;<br>END;<br>\/<br><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Summary of Solutions<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th><strong>Cause<\/strong><\/th><th><strong>Solution<\/strong><\/th><\/tr><\/thead><tbody><tr><td><strong>Missing semicolon (<code>;<\/code>)<\/strong><\/td><td>Add <code>;<\/code> where required<\/td><\/tr><tr><td><strong>Using reserved keywords<\/strong><\/td><td>Rename variables or use double quotes<\/td><\/tr><tr><td><strong>Incorrect procedure\/function syntax<\/strong><\/td><td>Ensure <code>IS<\/code> or <code>AS<\/code> is present<\/td><\/tr><tr><td><strong>Missing <code>THEN<\/code> in <code>IF<\/code> statement<\/strong><\/td><td>Add <code>THEN<\/code> after the condition<\/td><\/tr><tr><td><strong>Placing <code>EXCEPTION<\/code> outside <code>BEGIN-END<\/code><\/strong><\/td><td>Move <code>EXCEPTION<\/code> inside the block<\/td><\/tr><tr><td><strong>Incorrect <code>LOOP<\/code> structure<\/strong><\/td><td>Ensure <code>LOOP<\/code> and <code>END LOOP<\/code> are used<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>The <strong>PLS-00103<\/strong> error is one of the most common PL\/SQL errors, but it is also <strong>one of the easiest to fix<\/strong> once you identify the cause. By carefully checking for <strong>syntax issues, missing keywords, misplaced statements, and incorrect variable names<\/strong>, you can quickly resolve this error and ensure that your PL\/SQL code runs smoothly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[515],"tags":[529],"class_list":["post-1920","post","type-post","status-publish","format-standard","hentry","category-oracle","tag-pl-sql"],"_links":{"self":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/comments?post=1920"}],"version-history":[{"count":2,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1920\/revisions"}],"predecessor-version":[{"id":1935,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/posts\/1920\/revisions\/1935"}],"wp:attachment":[{"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/media?parent=1920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/categories?post=1920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/molecularsciences.org\/content\/wp-json\/wp\/v2\/tags?post=1920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}