I tried to execute an SQL
INSERT
with Toad for oracle
:
INSERT INTO GRAT_ACTIVITY
(UUID, IP_ADRESS, SEND_MAIL, DATE_CREA, DATE_UPD, CREATOR, CENTER, ETAT, REQUEST)
VALUES('555-vgd9-pllkd-5513', '172.12.23.130', 'N', SYSDATE, SYSDATE, '1554', 'M18', 'I', 8842);
--COMMIT;
the GRAT_ACTIVITY
table structure is as below:
CREATE TABLE CASH.GRAT_ACTIVITY
(
UUID VARCHAR2(64 BYTE) NOT NULL,
IP_ADRESS VARCHAR2(15 BYTE),
SEND_MAIL VARCHAR2(1 BYTE),
DATE_CREA DATE,
DATE_UPD DATE,
CREATOR VARCHAR2(4 BYTE),
CENTER VARCHAR2(4 BYTE),
ETAT VARCHAR2(1 BYTE),
REQUEST NUMBER
)
the error message:
ORA-00911: invalid character
Cause: identifiers may not start with any ASCII character other than letters and numbers. $#_ are also allowed after the first
character. Identifiers enclosed by doublequotes may contain any
character other than a doublequote. Alternative quotes (q’#…#’)
cannot use spaces, tabs, or carriage returns as delimiters. For all
other contexts, consult the SQL Language Reference Manual.Action: None
How can I solve it?
Are you getting an “ORA-00911 invalid character” error when running an SQL statement? Find out what causes it and how to resolve it in this article.
ORA-00911 Cause
So, you’ve tried to run an SQL statement, such as INSERT or SELECT, and gotten this error:
ORA-00911: invalid character
Why did this happen?
According to the Oracle error message:
Identifiers may not start with any ASCII character other than letters and numbers. $#_ are also allowed after the first character. Identifiers enclosed by doublequotes may contain any character other than a doublequote. Alternative quotes (q'#...#') cannot use spaces, tabs, or carriage returns as delimiters. For all other contexts, consult the SQL Language Reference Manual.
This error occurred because there was a special character in your SQL statement. It could be a special character in the WHERE clause that is not enclosed in single quotes.
Oracle mentions that identifiers (such as table names) cannot start with any character other than letters or numbers. A few symbols (such as $#_) are allowed after the first character.
To resolve this error, you need to remove the special character from your statement or enclose it in single quotes.
Let’s take a look at some examples of where you might get this error, and how to resolve it.
While you’re here, if you want an easy-to-use list of the main features in Oracle SQL, get my SQL Cheat Sheet here:
ORA-00911 invalid character While Inserting
If you’re getting this error when running an INSERT statement, it could be that you have:
- Added a special character to one of the column names
- Added a special character to the VALUES without enclosing it in single quotes.
An example of a query that would cause this error is:
INSERT INTO student (student_id, first_name, last_name)
VALUES (21, ##, 'Hanson');
To resolve it, change your query to remove the special character:
INSERT INTO student (student_id, first_name, last_name)
VALUES (21, 'Maria', 'Hanson');
Or, enclose it in single quotes so it is treated like a string, if you need the value:
INSERT INTO student (student_id, first_name, last_name)
VALUES (21, '##', 'Hanson');
You can read my guide on the INSERT statement for more information.
ORA-00911 invalid character in Oracle SELECT
If you’re getting this error in a SELECT statement, then it’s also probably because there is a special character where there shouldn’t be.
An example of a query that causes this error is:
SELECT student_id, first_name, last_name
FROM student
WHERE student_id = #9;
To resolve it, you can change your query to remove the special character:
SELECT student_id, first_name, last_name
FROM student
WHERE student_id = 9;
ORA-00911 invalid character In Toad
If you’re running Toad, you might be seeing some strange behaviour.
Your query might look like this:
INSERT INTO student (student_id, first_name, last_name)
VALUES (21, 'Maria', 'Hanson');--COMMIT;
If you run this command, you might be getting an ORA-00911: invalid character in Toad.
But, if you look closely, there’s no special characters in the query!
Why is this happening?
It’s because Toad has some strange behaviour when it comes to semicolons and comments (which you can read more about here)
The error is happening because the semicolon from the commented-out section is being included – even though it is commented out.
To resolve the issue and make your query run, remove the commented-out section.
INSERT INTO student (student_id, first_name, last_name)
VALUES (21, 'Maria', 'Hanson');
Now the query should run successfully.
So, that’s how you resolve the “ORA-00911: invalid character” error in Oracle.
While you’re here, if you want an easy-to-use list of the main features in Oracle SQL, get my SQL Cheat Sheet here:
ORA-00911
ORA-00911: неправильный символ
Причина:
Специальные символы правильны только в определенных местах. Если специальные символы такие как $, ~, # используются в имени и имя не заключено в двойные кавычки, то последует сообщение.
Действие:
Уберите неправильный символ из оператора (выражения), или заключите имя объекта в двойные кавычки.
ORA-00911: invalid character error occurs when a special character or a non-printable character is added to the SQL Statement. If a special character other than $, _, or # is used in the column or table name, it must be surrounded by double quotation marks. Oracle SQL statements do not allow special characters, non-printable characters, or non-ascii characters. Otherwise, an error ORA-00911: invalid character will be thrown
When SQL statements are copied, non-printable characters are occasionally introduced to the SQL statement. Non-ascii characters are added to sql statements if you use an editor that supports Unicode. Oracle will throw the error ORA-00911: invalid character if it detects any special characters other than $, _, or #, as well as non-printable or non-ascii characters.
When the ORA-00911 error occur
Oracle will throw this error if any special characters other than $, _, or #, as well as non-printable or non-ascii characters, are discovered in the oracle sql query. The SQL Statement must be written in ascii characters. Non-ascii strings should be surrounded by single or double quotation marks.
Problem
create table dept(
id% number primary key,
name varchar2(100)
);
Error
Error report -
ORA-00911: invalid character
00911. 00000 - "invalid character"
*Cause: The identifier name started with an ASCII character other than a
letter or a number. After the first character of the identifier
name, ASCII characters are allowed including "$", "#" and "_".
Identifiers enclosed in double quotation marks may contain any
character other than a double quotation. Alternate quotation
marks (q'#...#') cannot use spaces, tabs, or carriage returns as
delimiters. For all other contexts, consult the SQL Language
Reference Manual.
*Action: Check the Oracle identifier naming convention. If you are
attempting to provide a password in the IDENTIFIED BY clause of
a CREATE USER or ALTER USER statement, then it is recommended to
always enclose the password in double quotation marks because
characters other than the double quotation are then allowed.
Root Cause
The identifier name started with an ASCII character other than a letter or a number. After the first character of the identifier name, ASCII characters are allowed including “$”, “#” and “_”. Identifiers enclosed in double quotation marks may contain any character other than a double quotation. Alternate quotation marks (q’#…#’) cannot use spaces, tabs, or carriage returns as delimiters.
Solution 1
If a special character is added to a column or table name, the special character should be deleted for consistency. Otherwise, a double quotation mark should be used around the column or table name. In this instance, the column or table name must always be surrounded in double quotation marks.
Problem
create table dept(
id% number primary key,
name varchar2(100)
);
Error report -
ORA-00911: invalid character
00911. 00000 - "invalid character"
Solution
create table dept(
id number primary key,
name varchar2(100)
);
create table dept(
"id%" number primary key,
name varchar2(100)
);
Solution 2
The string in the SQL Statement should be surrounded by single quotation marks. Oracle will give an error if the string is not enclosed in single quotes. This occurs when you copy SQL statements from one editor to another. The single quotation can be replaced with other characters. The error will be fixed if you enclose the strings in the SQL statement with single quotation marks.
Problem
select * from dept where name = `a`;
Error report -
ORA-00911: invalid character
00911. 00000 - "invalid character"
Solution
select * from dept where name = 'a';
Solution 3
The error will be thrown if you use any special characters in the SQL Statement. If any special characters are used in the sql query, they must be deleted. If special characters are used in a string, they should be surrounded by single or double quotation marks.
Problem
select * from dept where name like a%;
Error report -
ORA-00911: invalid character
00911. 00000 - "invalid character"
Solution
select * from dept where name like 'a%';
Solution 4
When you copy a SQL Statement from one editor to another, the non-printable character is occasionally included. These characters are not visible. The error will be thrown when you execute the SQL Statement. To fix this issue, the SQL Statement needs be manually rewritten. This issue may be resolved by copying the ascii-based editor and pasting it into the sql editors.
As per OERR,ORA-00911: invalid character
Cause: identifiers may not start with any ASCII character other than letters and numbers. $#_ are also allowed after the first character. Identifiers enclosed by double quotes may contain any character other than a double quote. Alternative quotes (q’#…#’) cannot use spaces, tabs, or carriage returns as delimiters. For all other contexts, consult the SQL Language Reference Manual.
Action: None
ORA-00911 exception is very common and usually occurs for common syntax mistakes. Some of the common causes and resolution are given below
Check list to run for ORA-00911 error
1. Sometimes when you copy the sql from another editor,it may non-printable/special character added (usually Acute instead of quote)
SQL> select * from APPS.FND_PROFILE_OPTION_NAME where profile_name like 'USER%`;
select * from APPS.FND_PROFILE_OPTION_NAME where profile_name like 'USER%`;
*
ERROR at line 1:
ORA-00911: invalid character
The correct way is to remove those character and try again
SQL> select * from APPS.FND_PROFILE_OPTION_NAME where profile_name like 'USER%';
2. This error occurs when a special character is used in a SQL WHERE clause and the value is not enclosed in single quotations.
SQL> select * from APPS.FND_PROFILE_OPTION_NAME where profile_name like USER%; select * from APPS.FND_PROFILE_OPTION_NAME where profile_name like USER%; * ERROR at line 1: ORA-00911: invalid character
The correct query is
SQL> select * from APPS.FND_PROFILE_OPTION_NAME where profile_name like 'USER%';
3. when a extra semicolon (;) is added to end the query
SQL> select * from APPS.FND_PROFILE_OPTION_NAME where profile_name like 'USER%';;
select * from APPS.FND_PROFILE_OPTION_NAME where profile_name like 'USER%';
*
ERROR at line 1:
ORA-00911: invalid character
Oracle has improved this 11g and above
select CHECKPOINT_CHANGE# from v$database;;
select CHECKPOINT_CHANGE# from v$database;
*
ERROR at line 1:
ORA-00933: SQL command not properly ended
The correct way is to use single semi colon
SQL> select * from APPS.FND_PROFILE_OPTION_NAME where profile_name like 'USER%'; SQL> select CHECKPOINT_CHANGE# from v$database;
4. when semicolon (;) is added to end the query in execute immediate of pl/sql
SQL> begin
execute immediate 'select * from v$database;';
end;
/
begin
*
ERROR at line 1:
ORA-00911: invalid character
ORA-06512: at line 2
Oracle has improved this 11g and above
begin
execute immediate 'select * from v$database;';
end;
/
begin
*
ERROR at line 1:
ORA-00933: SQL command not properly ended
ORA-06512: at line 2
The correct way is
begin execute immediate 'select * from v$database'; end; /
5. it also occurs when you try to use a special character in a SQL statement. If a special character other than $, _, and # is used in the name of a column or oracle table, the name must be enclosed in double quotations.
create table example (j% number);
create table example (j% number)
*
ERROR at line 1:
ORA-00911: invalid character
Correct way
We should enclose them in double quotes “”
SQL> create table example ("j%" number); Table created.
6. when semicolon (;) is added to end the query executing from programming language like .net or java
Hope you like this content to resolve the ORA-00911: invalid character in oracle database.Please do provide the feedback to improve and include more stuff in this post
Related Articles
ORA-00936 missing expression
ORA-01017: invalid username/password
ora-29913: error in executing odciexttableopen callout
ORA-00001 unique constraint violated
ORA-00257: archiver error. Connect internal only, until freed.
ORA-03113: end-of-file on communication channel
Oracle Documentation