Reputation: 23
I'm currently learning SQL and I've installed oracle 11g express on my system. I'm trying to create a table however when I try to run the below command I get the following Error Message:
ERROR at line 3: ORA-00904 : invalid identifier
CREATE TABLE PROJECTS (
proID NUMBER(4) NOT NULL,
Desc CHAR(20),
sDate DATE,
eDate DATE,
Budget NUMBER(7,2),
maxStaff NUMBER(2)
);
Can anybody please tell me what I'm doing wrong?
Thanks for all the replies, I ran this command succesfully:
CREATE TABLE PROJECTS (
proID NUMBER(4) NOT NULL,
description CHAR(20),
sDate DATE,
eDate DATE,
Budget NUMBER(7,2),
maxStaff NUMBER(2)
);
Really Appreciate the fast replies!
Chris
Upvotes: 1
Views: 770
Reputation: 51980
As already said several times, the error is caused here by the use of a reserved keyword unquoted as an identifier. For sake of completeness:
So:
CREATE TABLE T (DESC INT);
ORA-00904: : invalid identifier as
DESC
is a keyword
CREATE TABLE T (Desc INT);
ORA-00904: : invalid identifier same reason as unquoted identifiers are converted all upper-case
CREATE TABLE T ("DESC" INT);
Table created by using quotes,
"DESC"
is no longer recognized as a reserved keywordINSERT INTO T("Desc") VALUES (1);
ORA-00904: "Desc": invalid identifier Quoted identifiers are case-sensitive.
"DESC"
is not the same columns as"Desc"
INSERT INTO T("DESC") VALUES (1);
1 row(s) inserted
That being said, you should avoid using a keyword as an identifier...
Upvotes: 1
Reputation: 15085
Since DESC is a reserved word, you would have to enclose it in double quotes.
However, I would not recommend using reserved words for fields names, perhaps change to description or something similar
Upvotes: 1
Reputation: 3019
You have DESC
in as a column name. While you can use it you will have to encompass it in quotes:
CREATE TABLE PROJECTS (
proID NUMBER(4) NOT NULL,
"Desc" CHAR(20),
sDate DATE,
eDate DATE,
Budget NUMBER(7,2),
maxStaff NUMBER(2)
);
You will also have to use quotes every time you call it in a query. I recommend just changing that column to something else (maybe DESCRIPTION
?)
Upvotes: 1