Getting ORA-00904: : invalid identifier in oracle application express - sql

I want to create this simple table in oracle application express but i keep getting the error
ORA-00904: : invalid identifier
and I have no idea why.
CREATE TABLE ArtWork (
ArtWorkId NUMBER (6,0) CONSTRAINT aw_pk PRIMARY KEY,
Name VARCHAR2 (20),
Desc VARCHAR2 (25)
);

desc is a reserved word (it is used to to specifiy the sort direction, for example in an order by clause).
You need to either surround it with double quotes, or better yet change your column name to something that does not clash with a language keyword, so you don't need to worry about it later on:
CREATE TABLE ArtWork (
ArtWorkId NUMBER (6,0) CONSTRAINT aw_pk PRIMARY KEY,
Name VARCHAR2 (20),
Description VARCHAR2 (25)
);

Reserved keywords shouldn't be used as identifiers as they are for implicit usages. Hence change desc to some other name like description

Related

getting error while creating table as ORA-00904: : invalid identifier in oracle database sql

I am trying to create a table but get an error as ORA-00904: : invalid identifier in oracle database
create table player_info
(player_id varchar2(200) primary key,
User_id varchar2(100) not null,
Level varchar2(200) not null,
HP number(1000) not null,
Map_id varchar2(200) not null,
Model_id varchar(200) not null,
Money varchar2(10000) not null,
Boss_killed varchar2(100));
There are multiple things wrong in your statement. Each of the ones below will cause an error.
LEVEL is a "reserved word", you cannot use this as a column name. Here is the full list: https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Oracle-SQL-Reserved-Words.html#GUID-55C49D1E-BE08-4C50-A9DD-8593EB925612
NUMBER(1000) is not valid - what are you trying to achieve here ? The precision of the number should be between 1 and 38 (https://docs.oracle.com/en/database/oracle/oracle-database/21/sqlrf/Data-Types.html#GUID-7B72E154-677A-4342-A1EA-C74C1EA928E6) - what would the "1000" indicate ?
That is because LEVEL is a reserved word in Oracle, use another word instead.

Missing right parenthesis Oracle Issue

I 'm using Oracle Application Express Edition 4.0.2.00.09
While creating the table I'm getting error "ORA-00907: missing right parenthesis", I have checked previously asked question on this however could not make it through.
Create table NewOne (
PersonId Int(10),
Hire_Date varchar(255),
Tenure number(255),
Review varchar(255),
Next_Day varchar(255),
Last_day varchar(255)
)
Make the changes below
Change int to number
Change number(255) to number(38) , as 38 is the max allowed for number
It should work fine.
Check out the db fiddle link - https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=d1fecc3e55708115d2326fdeec34243d
You can't specify a length for the INT subtype, it is what it is. You should use the NUMBER type instead.
Once you fix that you'll find that your tenure column is specified with 255 digits, I don't think that's close to reality and will also error.
You should be using VARCHAR2 not VARCHAR on Oracle.
int is a perfectly acceptable Oracle type. However, int(10) is not. Number itself is limited to a max of 38. And Oracle recommend varchar2() instead of varchar(). So I would recommend:
Create table NewOne (
PersonId Int,
Hire_Date varchar2(255),
Tenure number,
Review varchar2(255),
Next_Day varchar2(255),
Last_day varchar2(255)
);
Here is a db<>fiddle

Elementary Oracle SQL Error message ORA-00900

I'm fairly new to writing SQL but I have a decent understanding of the basics at this point. I am trying to figure out why I am receiving the following error message: ORA-00900: invalid SQL statement.
Additionally, it would help if I could find which line is causing the error.
CREATE TABLE ADVENTURE_TRIP (
COLUMN CHAR(15) PRIMARY KEY,
TYPE CHAR(15),
LENGTH CHAR(15),
DECIMAL_PLACES CHAR(15),
NULLS_ALLOWED CHAR(15) NOT NULL,
DESCRIPTION CHAR(25)
);
The word COLUMN is a reserved word, and is not appropriate for a column name. You should choose a better name for the column.
Although TYPE is also a reserved word, it is allowed as a column name. I would change that too.
Also, usually VARCHAR2() is preferred over CHAR() for string types in Oracle.
The list of reserved words is here.
#Gordon described the correct justification.
Reserved keywords should be avoided.
But, If you really want to create the table as mentioned in your question then you can use the following code:
CREATE TABLE ADVENTURE_TRIP (
"COLUMN" CHAR(15) PRIMARY KEY,
"TYPE" CHAR(15),
LENGTH CHAR(15),
DECIMAL_PLACES CHAR(15),
NULLS_ALLOWED CHAR(15) NOT NULL,
DESCRIPTION CHAR(25)
);
Double quotes can be used for such purpose.
This is just to make you understand but in the real world, you must avoid using reserved keywords.
Here is the Demo

Creating table via SQL Command Line, invalid identifier

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...

Confusing error about missing left parenthesis in SQL statement

SQLPLUS says I have missing left parenthesis with this statement in my sql script..
CREATE TABLE people(
id INT NOT NULL PRIMARY KEY,
name VARCHAR2
);
I had uploaded my script with sftp, could that have played around with the script?
VARCHAR2 is a type that needs a maximum size/length. Try something like...
varchar2(50)
Your missing left parenthesis is the parenthesis that surrounds the size.
CREATE TABLE people(
id INT NOT NULL PRIMARY KEY,
name VARCHAR2(50)
);
You need to specify a size for the VARCHAR2 data type.
E.g. VARCHAR2(30)
SQL*Plus is looking for the brackets around the VARCHAR2 size definition.
You are getting this error because you didn't specify the character with datatype varchar2.
Try something like this:
CREATE TABLE people(
id INT NOT NULL PRIMARY KEY,
name VARCHAR2(20) );
You need to specify the size of Varchar2.
For example:- Name Varchar2(50)
Note:- The maximum size of the Varchar2 is 4000.