Oracle Live SQL : ORA-00907: missing right parenthesis - - sql

I saw many others opened a question related to same problem however none of the answer addresses to the problem I have.
I am running below code on Oracle Live SQL and getting the error
ORA-00907: missing right parenthesis
create table CUST_ORDER (
ord_id NUMBER(38) CONSTRAINT cusordtb_ordid_pk PRIMARY KEY,
cust_id NUMBER(38) NOT NULL,
order_date DATE(12) NOT NULL
);
I am pretty sure I am not missing any parenthesis. Does anyone have the solution?

The Oracle date datatype does not take a length.
Consider:
create table CUST_ORDER (
ord_id NUMBER(38) CONSTRAINT cusordtb_ordid_pk PRIMARY KEY,
cust_id NUMBER(38) NOT NULL,
order_date DATE NOT NULL
);

Date doenot take a length. So you need not specify the same

Related

i cant create a table because name is invalid [duplicate]

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)
);

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

Missing Right Parenthesis in SQL

I'm new to learning SQL. When I create this table, it has an Asterix (*) under the first parenthesis of the "(dbClassID)" and says "missing right parenthesis"
Does anyone know why it does that and how I can fix it?
CREATE TABLE vod_classification (
dbClassId CHAR(4) NOT NULL,
dbDescription VARCHAR2(100)
CONSTRAINT vod_classification_PK PRIMARY KEY (dbClassId)
);
CONSTRAINT is part of table creation and need to be comma delimited as other column:
CREATE TABLE zz_classification (
dbClassId CHAR(4) NOT NULL,
dbDescription VARCHAR2(100),
CONSTRAINT vod_classification_PK PRIMARY KEY( dbClassId)
);
Tables contain columns and constraints
you are missing , here try this VARCHAR2(100),
For a single-column constraint, it's neater to define it inline as part of the column:
create table vod_classification
( dbclassid varchar2(4) not null constraint vod_classification_pk primary key
, dbdescription varchar2(100) not null constraint vod_classification_uk unique
);
I have corrected the CHAR column to the standard string type which is VARCHAR2 in Oracle.
(PK columns will be not null automatically, but I've left it in for completeness and in case you later create table as select.)
When using the "Create" code, you must use a comma in the line where you define each column of the table. Except the last column. You can read the oracle sql syntax link as follows: https://docs.oracle.com/cd/E11882_01/server.112/e41085/sqlqr01001.htm#SQLQR110

Oracle Apex 5 Error, ORA-00907: missing right parenthesis. Can't see missing parenthesis?

I have this code, and cannot work out why I am getting issues. Can anyone help? It executes the generate sequence command, but not the create tables one, so I therefore cannot see it on the object browser.
If this helps:
QuizID is to be generated by a sequence.
QuizTitle, is at most 15 characters, and is not null.
Category is to default to Music with Sports and Geography as the only other available options.
SQL code:
CREATE TABLE Quiz_NLB_2
(
QuizID NUMBER,
QuizTitle VARCHAR2(15) NOT NULL,
Category VARCHAR2(9) DEFAULT 'Music',
CONSTRAINT pk_QuizID PRIMARY KEY (QuizID),
CONSTRAINT chk_Category CHECK (Category='Music', 'Sports', 'Geography')
);
CREATE SEQUENCE QuizID_Sequence_Gen START WITH 100;
The check constraint should look like this:
CONSTRAINT chk_Category
CHECK (Category IN ('Music', 'Sports', 'Geography'))

SQL Error: ORA-00907: missing right parenthesis when trying to creating table

This is the query I am trying to execute against an Oracle database which apparently has no parenthesis missing.
CREATE TABLE P_DOG(
DOG_ID CHAR(5) NOT NULL,
DOG_NAME VARCHAR2(30) NOT NULL DEFAULT 'UNKNOWN',
DOG_BIRTHDAY_MONTH NUMBER(2) NULL CHECK(DOG_BIRTH_MONTH>=1 AND DOG_BIRTH_MONTH<=12),
DOG_BIRTHDAY_YEAR NUMBER(4) NOT NULL CHECK(DOG_BIRTH_YEAR>=1980 AND DOG_BIRTH_YEAR<= 2030),
SEX CHAR(1) NOT NULL,
SPAYED_OR_NEUTERED CHAR(1) NOT NULL DEFAULT 'N',
CONSTRAINT DOG_PK PRIMARY KEY(DOG_ID),
);
Besides the extra comma at the end that Mat pointed out in a comment, NOT NULL should come after the defaults - and the check constraints should have the correct column names: the column names have BIRTHDAY but the conditions use BIRTH, change either the column name or what you have in the conditions so they match.
Specifically the "missing right parenthesis" error is caused by having a DEFAULT after NOT NULL. Wrong order.