ORA-00907: missing right parenthesis, and nothing is working - sql

I've been sitting and looking at this code for a few hours and I don't understand where I went wrong, why it doesn't work.
ORA-00907: missing right parenthesis
I saw that this is a topic that is discussed alot but for some reason none of the examples I have seen has helped me. I'm pretty sure it's all right with the parentheses.
Here is the code:
CREATE TABLE ADT_FILIALA_AGENTIE (
id_f NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE NOT NULL ENABLE,
name varchar(30) NOT NULL,
telephone varchar(30) NOT NULL,
adress varchar(30) NOT NULL,
nr_an varchar(30) NOT NULL,
id_a int(11) NOT NULL,
PRIMARY KEY(id_f),
FOREIGN KEY(id_a) REFERENCES ADT_AGENTIE_PRINCIPALA(id_a)
);

You can't specify precision for the int data type in Oracle. You are using it for column id_a. int is shorthand for number(38,0).
To get the desired effect, replace that with number(11,0) - which means precision of 11 digits, of which zero decimal places.
Other than that, you would be well advised, in Oracle, to use varchar2(n) rather than varchar(n). For a very long time Oracle has warned us that in future releases varchar may be used for something else (even though that hasn't happened and is unlikely to happen).
To explain the error message: Right after the parser reads id_a int it expects (optional space and) a comma, or a constraint, etc. What it does not expect (since it makes no sense in that position) is an opening parenthesis, as you have in (11). The error handling is written to assume that at that point the create table statement should have ended - with a closing parenthesis. It doesn't find it, so it complains about that.
That's why you saw so many unrelated mentions of "missing right parenthesis" errors - they are often thrown by the parser when it finds something unexpected in a statement. The parser doesn't know what the real error is - it just sees something that doesn't make sense somewhere, and if at that point a closing parenthesis would have ended a valid statement, it throws that error.

You can't specify precision for the int data type in Oracle. You are using it for column id_a int.
CREATE TABLE ADT_FILIALA_AGENTIE ( id_f NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE NOT NULL ENABLE,
name varchar(30) NOT NULL,
telephone varchar(30) NOT NULL,
adress varchar(30) NOT NULL,
nr_an varchar(30) NOT NULL,
id_a int NOT NULL,
PRIMARY KEY(id_f),
FOREIGN KEY(id_a) REFERENCES ADT_AGENTIE_PRINCIPALA(id_a) );

Related

Oracle SQL - "missing keyword"

I am trying to create a simple table in Oracle SQL. The counterpart code works fine in SQL management studio, but not in Oracle APEX.
The following query:
CREATE TABLE Conference(
ConferenceID NUMBER GENERATED ALWAYS AS IDENTITY
(START WITH 100
INCREMENT BY 10
MINVALUE 100
MAXVALUE 100000
NO CYCLE),
Director VARCHAR(25) NOT NULL,
School Size NUMBER NOT NULL,
Location VARCHAR(50) NOT NULL,
CONSTRAINT pk_Conference PRIMARY KEY (ConferenceID)
);
is repeatedly met with the following error:
ORA-02000: missing ( keyword
I have done my due diligence searching for a solution to this problem here, here, and here.
I checked over the identity column section, as well as the Primary Key syntax here, and everything appears to look right. Despite this, I cannot find a solution.
Okay, in the docs, take a look at the identity options for a column definition. It's a small typo in this case - the NOCYCLE option is one word; there's no space.
You have one other problem, which is that School Size is not a valid column name. There's a space in it, and it's not quoted. You could do either School_Size or "School Size". I'd recommend the first one, since double-quoted column names are case-sensitive and really annoying to use.
Edit: Also, they're technically synonyms, but Oracle recommends using VARCHAR2 instead of VARCHAR.
CREATE TABLE Conference(
ConferenceID NUMBER GENERATED ALWAYS AS IDENTITY
(START WITH 100
INCREMENT BY 10
MINVALUE 100
MAXVALUE 100000
NOCYCLE),
Director VARCHAR2(25) NOT NULL,
School_Size NUMBER NOT NULL,
Location VARCHAR2(50) NOT NULL,
CONSTRAINT pk_Conference PRIMARY KEY (ConferenceID)
);

SQL Error: Missing Right Parenthesis in Line 1 ORA-00907

I've checked other similar questions. about repeating commas, error in commands but cant find any in my error. I've also searched examples of create tables to compare with mine, but fail to find any difference :(.
Below is the CREATE table statement:
CREATE TABLE DRIVER(L# VARCHAR(15) NOT NULL
, DNAME VARCHAR(75) NOT NULL
, STATUS VARCHAR(50) NOT NULL
, NRIC VARCHAR (15) NOT NULL
, PRIMARY KEY(L#)
, CANDIDATE KEY(NRIC)
);
Anyone can help me point out that i can't see or missing something,thanks (:
You can't specify CANDIDATE KEY like that in Oracle. The right way is to create a UNIQUE CONSTRAINT on your Candidate Key(s).
Like so.
Here's a working SQLFiddle: http://sqlfiddle.com/#!4/b392d/1
CREATE TABLE DRIVER(
L# VARCHAR(15) NOT NULL,
DNAME VARCHAR(75) NOT NULL,
STATUS VARCHAR(50) NOT NULL,
NRIC VARCHAR (15) NOT NULL,
PRIMARY KEY(L#),
CONSTRAINT UK_NRIC UNIQUE (NRIC)
);
ORA-00907 pretty much always indicates a syntax error. It happens when the parser finds a word which is not a key word in a position where it is expecting either a keyword or a right-hand bracket to close the current statement (hence Missing Right Parenthesis). Although sometime it can just be that we have an unmatched left-hand bracket: a decent text editor can help trace that.
In your case the intruding word is CANDIDATE. Syntax errors can be tricky for beginners. I recommend you familarise yourself with the Oracle documentation:it is online, complete and free, and has quite a lot of examples. Check it out . The list of reserved words could have helped you, because CANDIDATE is not on it, which is a big clue.
If you are going to use odd characters in a name, wrap it in square brackets. []

Can't create new table

I'm new to SQL Server 2000 and face a problem. I want to make a new table but I encounter an error message with the following code:
create table Buku
(
Kode_Buku char(5) constraint PK_Kode_Buku Primary Key,
Judul_Buku varchar(10)not null,
Nama_Pengarang varchar(30) not null,
Penerbit varchar(30),
Kota_Terbit varchar(30) default,
Tahun_Terbit varchar(4) default,
Bahasa varchar(4) check,
Harga_Jual money,
)
and here's the error code:
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'Buku'.
You have three problems:
You have multiple cases where you say default but don't specify anything
You have a check but don't specify anything
Your last column definition says money, with a trailing comma
Now, none of these lead to the exact error message you're getting, so maybe there is more you're not telling us (is there more code before the create table bit?), but these little syntax problems are far too localized to be useful in this Q & A format.
EDIT
I just ran this on a SQL Server 2000 instance and it worked just fine:
create table Buku
(
Kode_Buku char(5) constraint PK_Kode_Buku Primary Key,
Judul_Buku varchar(10) not null, -- added space here
Nama_Pengarang varchar(30) not null,
Penerbit varchar(30),
Kota_Terbit varchar(30), -- removed default here
Tahun_Terbit varchar(4), -- removed default here
Bahasa varchar(4), -- removed check here
Harga_Jual money -- removed comma here
)
So I'm not sure what you're doing differently, but I can't get the error message you are seeing with the information you've provided in the question. If you're still getting an error message with this code (and only this code), you'll need to provide more information, such as ##VERSION, what interface you're using to submit the create table statement to SQL Server, etc.

SQL Not Auto-incrementing

I have the following SQL I trigger in a C# app.
All works well but the ID table doesn't auto increment. It creates the value of 1 for the first entry then will not allow other inserts due to not being able to create a unquie ID.
Here is the SQL:
CREATE TABLE of_mapplist_raw (
id integer PRIMARY KEY NOT NULL,
form_name varchar(200) NOT NULL,
form_revi varchar(200) NOT NULL,
source_map varchar(200),
page_num varchar(200) NOT NULL,
fid varchar(200) NOT NULL,
fdesc varchar(200) NOT NULL
)";
I'm sure its a schoolboy error at play here.
you need to specify its seed and increment.( plus , i dont think there is integer keyword ....)
id [int] IDENTITY(1,1) NOT NULL,
the first value is the seed
the second one is the delta between increases
A Question you might ask :
delta between increases ? why do i need that ? its always 1 ....??
well - yes and no. sometimes you want to leave a gap between rows - so you can later insert rows between... specially if its clustered index by that key....and speed is important... so you can pre-design it to leave gaps.
p.s. ill be glad to hear other scenarios from watchers.
You need to mention the Identity.
id int IDENTITY(1,1) NOT NULL

ORA-00907 when trying to create a CHECK constraint

I need your help with this error:
ORA-00907 on Check CONSTRAINT
Query:
CREATE TABLE S_NEWS.T_UTILISATEUR_USR (
USR_ID INTEGER NOT NULL PRIMARY KEY,
USR_MAIL VARCHAR(256) NOT NULL,
USR_TITRE CHAR(6) NULL DEFAULT 'M.'CHECK (USR_TITRE IN ('M.' , 'Mlle.','Mme.' )),
USR_NOM CHAR(32) NOT NULL,
USR_PRENOM VARCHAR(32) NULL,
USR_ORGANISATION VARCHAR(128) NULL
);
The error message is
ORA-00907: missing right parenthesis
It almost always points to a syntax error rather than a missing bracket. In this case the parser is objecting to the order of the elements in your column definition. Specifically, the DEFAULT clause must come before the CONSTRAINT clause, which includes the NULL/NOT NULL declaration. So try
USR_TITRE CHAR(6) DEFAULT 'M.'CHECK (USR_TITRE IN ('M.' , 'Mlle.','Mme.' )) NULL
Incidentally, you're going to a problem with that constraint. A CHAR datatype is always padded to the declared length. Thus if you enter 'M.' into the column it will pad out to 'M. ', which value will cause the constraint to hurl an exception. I suggest you use VARCHAR2(6) instead.
CHAR declarations are almost always a mistake, just a bug waiting to happen.