Error
Error Code:
ORA-30117
Oracle ORA-30117: Syntax Error
Description
The ORA-30117 error indicates a syntax error at the beginning of an input string within Oracle Database. This typically occurs when executing SQL, PL/SQL, or other commands where the initial syntax is invalid.
Error Message
ORA-30117: syntax error at ' string ' at the start of input
Known Causes
4 known causesInvalid SQL Syntax
The SQL statement begins with an incorrect keyword, missing keyword, or invalid character, causing the parser to fail immediately.
Incorrect PL/SQL Block
The PL/SQL block starts with an invalid keyword (e.g., misspelled DECLARE, BEGIN) or a missing keyword, leading to a syntax error.
Typographical Error
A simple typo at the start of the input string, such as a misspelled keyword or an unexpected character, can cause the error.
Missing Semicolon
For some tools and environments, the lack of a semicolon to terminate the previous statement might cause a syntax error when attempting to execute a new statement.
Solutions
3 solutions available1. Correct Syntax for String Literals easy
Ensure string literals are enclosed in single quotes.
1
Review the SQL statement or PL/SQL code that is causing the ORA-30117 error. Identify the ' string ' part mentioned in the error message.
2
If the ' string ' is intended to be a literal string value, ensure it is properly enclosed within single quotes ('). If double quotes or no quotes were used, correct them.
Example of incorrect syntax:
SELECT * FROM my_table WHERE my_column = my_string_variable;
Example of correct syntax:
SELECT * FROM my_table WHERE my_column = 'my_string_value';
Or if using a variable:
DECLARE
my_string_variable VARCHAR2(100) := 'my_string_value';
BEGIN
SELECT * INTO some_variable FROM my_table WHERE my_column = my_string_variable;
END;
/
3
Re-execute the SQL statement or PL/SQL block.
2. Verify Reserved Words as Identifiers medium
Avoid using Oracle reserved words as identifiers without proper quoting.
1
Examine the SQL statement or PL/SQL code for any identifiers (table names, column names, variable names, etc.) that might be Oracle reserved words.
2
If an identifier is a reserved word, it must be enclosed in double quotes ("). For example, if you have a column named 'SELECT', you must refer to it as "SELECT".
Example of incorrect syntax:
CREATE TABLE my_table (SELECT VARCHAR2(10));
Example of correct syntax:
CREATE TABLE my_table ("SELECT" VARCHAR2(10));
SELECT "SELECT" FROM my_table;
3
If the ' string ' at the start of the input is indeed a reserved word being used as an identifier without quotes, correct it by adding double quotes.
4
Re-execute the SQL statement or PL/SQL block.
3. Inspect Dynamic SQL Construction advanced
Thoroughly check dynamic SQL strings for syntax errors.
1
If the error occurs within a PL/SQL block that constructs dynamic SQL (e.g., using `EXECUTE IMMEDIATE` or `DBMS_SQL`), carefully review the SQL string being built.
2
Pay close attention to how string literals, variable values, and keywords are concatenated into the dynamic SQL string. Ensure that all string literals within the dynamic SQL are correctly quoted (using single quotes).
Example of problematic dynamic SQL:
DECLARE
v_sql VARCHAR2(200);
v_value VARCHAR2(50) := 'some_value';
BEGIN
v_sql := 'SELECT * FROM my_table WHERE my_column = ' || v_value;
-- This will likely cause ORA-30117 if v_value is not a number, as it's treated as an identifier.
EXECUTE IMMEDIATE v_sql;
END;
/
Corrected dynamic SQL:
DECLARE
v_sql VARCHAR2(200);
v_value VARCHAR2(50) := 'some_value';
BEGIN
v_sql := 'SELECT * FROM my_table WHERE my_column = ''' || v_value || ''''; -- Double single quotes to represent a literal single quote
EXECUTE IMMEDIATE v_sql;
END;
/
3
Use `DBMS_OUTPUT.PUT_LINE` to print the constructed dynamic SQL string before execution to visually inspect it for any syntax irregularities.
DECLARE
v_sql VARCHAR2(200);
v_value VARCHAR2(50) := 'some_value';
BEGIN
v_sql := 'SELECT * FROM my_table WHERE my_column = ''' || v_value || '''';
DBMS_OUTPUT.PUT_LINE('Executing SQL: ' || v_sql);
EXECUTE IMMEDIATE v_sql;
END;
/
4
Re-execute the PL/SQL block after correcting any identified syntax errors in the dynamic SQL.