I am creating a table and I typed this command:
SQL> create table accident(report_number integer primary key,
2 date varchar(20),
3 location varchar(20));
I got this error:
date varchar(20),
*
ERROR at line 2:
ORA-00904: : invalid identifier
Can anyone tell me where the error is and how to rectify it?
DATE is a reserved word and can't be used as a column name.
Date is a reserved word, to use it for column names, surround it with quotas "column-name"
ex:
create table abcd(
"date" date
);
insert into abcd values (sysdate);
select "date" from abcd;
But note that when using quoats, the column names will be case sensitive
ex:
select "Date" from abcd will result in an "Date": invalid identifier
Related
CREATE type recommendation as object(
descriptions varchar2(200)
);
create type recomand as table of recommendation;
create type traitement_type as object (
id_traitement number(7),
duree varchar2(25),
recome recomand,
description varchar2(250)
);
CREATE TABLE Traitement (primary key(id_traitement))
nested table recome store as Les_recommendations;
i execute these commands and at the last query i got the error :
ORA-00904: : invalid identifier
any solutions ?
Your create table statement doesn't include a column list. It's interpreting "primary key" a column and spaces are not allowed. Look up the proper format for create table statements and PK constraints.
This question already has answers here:
ORA-00904: : invalid identifier Oracle sql [closed]
(2 answers)
Closed 1 year ago.
Im trying to create a table with the name " Order " and these datatypes (Note: i dont have a table named Order and I tried to create other tables and it worked ) and the names are:
create table Order(
Onum Number(8) PRIMARY KEY,
Odate Date,
Otime Time(7),
Delivered_on_time char(1));
and the error was:
invalid table name
so I tried to name it Ordeer and try again and it gave me this error:
ORA-00907: missing right parenthesis
Otime Time(7),
Delivered_on_time char(1)
);
what to do? help please
First, you can't call the table order because order is a reserved word. (There's a tricky way to get around this, but it's a bad idea to do so.)
Second, the DATE type also includes the time, so you don't need to have separate date and time columns.
CREATE TABLE orders (
onum NUMBER(8) PRIMARY KEY,
odate DATE,
delivered_on_time CHAR(1)
);
I'm doing a very simple SQL insert, which was working fine, until I added a UID column and now it won't work. A SQL syntax checker said this code is bad, but I can't see it. What;s the obvious thing here I'm missing? I've checked spellings, column names and db name all match.
INSERT INTO
virtualTree (PATH, NPATH, PUID, NAME, LEVEL, INDEX, UID)
VALUES(
'/data/Mitsubishi/Sys Info',
'/downstream/dgapi/DSA_Dev/config/sysInfo',
'',
'Sys Info',
'1',
'1',
'1532750575860'
);
Thanks!
You didn't specify database you use.
Furthermore, saying that you got a message "this code is bad" is quite useless. Computers don't write poetry, so shouldn't you. There was probably a very specific error message, along with the error code. For example, Oracle might have told you ORA-00904: : invalid identifier which is way more clear than "this code is bad". I suggest you to be more specific.
The following example shows what happens when you try to create a table using "invalid" column names (because they might be reserved words). It is based on Oracle. I removed "valid" column names to keep it simpler.
SQL> create table virtualtree
2 (level varchar2(20),
3 index varchar2(20),
4 uid varchar2(20));
(level varchar2(20),
*
ERROR at line 2:
ORA-00904: : invalid identifier
SQL> create table virtualtree
2 (c_level varchar2(20),
3 index varchar2(20),
4 uid varchar2(20));
index varchar2(20),
*
ERROR at line 3:
ORA-00904: : invalid identifier
SQL> create table virtualtree
2 (c_level varchar2(20),
3 c_index varchar2(20),
4 uid varchar2(20));
uid varchar2(20))
*
ERROR at line 4:
ORA-00904: : invalid identifier
SQL> create table virtualtree
2 (c_level varchar2(20),
3 c_index varchar2(20),
4 c_uid varchar2(20));
Table created.
SQL>
See? I couldn't create a table whose names were LEVEL, INDEX, UID - I had to modify them, somehow; I chose to add the C_ prefix.
I suggest you try the same. If what you said is true, your database complains about the UID column name.
If it doesn't help, back to the beginning - post actual error code and message, as well as the database you use.
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
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?)
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
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:
Oracle has an impressive list of reserved keywords.
Unquoted identifiers are internally converted upper-case by Oracle.
Quoted identifiers are case-sensitive
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 keyword
INSERT 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...
when I create a table like this:
create table DBDI_HIREDETAIL(
HireID int not null,
EquipID int not null,
Quantity int,
TotalFee float,
Comment varchar(200)
);
The error occurs like this:
Error at Command Line: "TotalFee float"
Error report:
SQL Error: ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
I don't understand why my code has an error, it seems to be fine.
COMMENT is a reserved word in Oracle; it's used for adding comments to the data dictionary. You should avoid using this as a column name.
SQL> create table a ( comment number );
create table a ( comment number )
*
ERROR at line 1:
ORA-00904: : invalid identifier
If you really want to use this column name you're have to quote it, i.e. "COMMENT":
SQL> create table a ( "COMMENT" number );
Table created.
I would recommend you not doing this as you have to quote the column everywhere.
That's because COMMENT is a reserved word in SQL - use another column name (like HIREDETAIL_COMMENT) instead:
create table DBDI_HIREDETAIL(
HireID int not null,
EquipID int not null,
Quantity int,
TotalFee float,
HireDetail_Comment varchar(200)
);