Error at line 1: ORA-00907: missing right parenthesis - sql

I believe I have the right syntax for SQL plus command, I have tried different ways to do it but I am getting the same error message. I don't know why i am getting this "missing right parenthesis error" any help will be appreciated thank you in advance.
here is my code:
create table PUBLISHERS (
NAME varchar2(50) primary key,
address varchar2(50), phone integer(10)
);

The integer data type does not use a length qualifier. integer is equivalent to number(38,0).
SQL> ed
Wrote file afiedt.buf
1 create table PUBLISHERS (
2 NAME varchar2(50) primary key,
3 address varchar2(50),
4 phone integer
5* )
SQL> /
Table created.
If you want to limit the size, use a number
SQL> ed
Wrote file afiedt.buf
1 create table PUBLISHERS (
2 NAME varchar2(50) primary key,
3 address varchar2(50),
4 phone number(10)
5* )
SQL> /
Table created.
Since you are never going to do numeric operations on a phone number, however, while it is generally likely that you will perform string manipulation on it to format phone numbers for display, it would generally make sense to store a phone number as a character string rather than as a number. You can add a CHECK constraint that ensures the format is correct.
SQL> ed
Wrote file afiedt.buf
1 create table PUBLISHERS (
2 NAME varchar2(50) primary key,
3 address varchar2(50),
4 phone varchar2(10)
5* )
SQL> /
Table created.

INTEGER is not a Oracle Built-In data type. It is just a ANSI format that is supported in oracle. The oracle representation of INTEGER is NUMBER (38). Use NUMBER datatype instead.
CREATE TABLE publishers(
name VARCHAR2(50) PRIMARY KEY,
address VARCHAR2(50),
phone NUMBER(10)
);

create table doctor_details(doctor_id number(10),
username varchar2(30) not null,
password varchar2(30) not null,
name varchar2(30) not null,
father_name varchar2(30) not null,
gender varchar2(6) not null check(gender in('male','female)),
email varchar2(50) not null,
contact_no number(10) not null,
qualification varchar2(50) not null,
specialization varchar2(5) not null,
date_of_birth date not null,
date_of_joining date not null,
primary key(doctor_id))
error is right parenthesis missing

Related

SQL CREATE TABLE missing left parentheses error

CREATE TABLE residents
(
R_ID NUMBER(4), CONSTRAINTS pk_residents_R_ID PRIMARY KEY,
R_FN VARCHAR2(15), NOT NULL,
R_LN VARCHAR2(15), NOT NULL,
R_Contact NUMBER(10), NOT NULL,
DoB DATE, NOT NULL
);
Tried a few changes but I'm unable to resolve this error. Any help would be appreciated!
It works for Oracle in this way:
CREATE TABLE residents(
R_ID NUMBER(4),
R_FN VARCHAR2(15) NOT NULL,
R_LN VARCHAR2(15) NOT NULL,
R_Contact NUMBER(10) NOT NULL,
DoB DATE NOT NULL,
pk_residents_R_ID NUMBER(4) PRIMARY KEY
);
Code which is the closest to your attempt is:
SQL> CREATE TABLE residents
2 (
3 r_id NUMBER (4) CONSTRAINT pk_residents_r_id PRIMARY KEY,
4 r_fn VARCHAR2 (15) NOT NULL,
5 r_ln VARCHAR2 (15) NOT NULL,
6 r_contact NUMBER (10) NOT NULL,
7 dob DATE NOT NULL
8 );
Table created.
SQL>
keyword is constraint, not constraintS
don't separate NOT NULL (or any other constraint) from its column with a comma
Also, using mixed letter case is irrelevant as Oracle - by default - stores object names in UPPERCASE. That's so unless you decide to enclose names into double quotes, but then you'll always have to use double quotes and exactly match letter case so - that's not what anyone should do, not in Oracle.

SQL keeps throwing "missing left parenthesis"

I don't understand what I am doing here but I keep getting a "missing left parenthesis" error in the following SQL code. Can anyone please tell me what I am doing wrong? Newbie here.
CREATE TABLE AGENT_INFO
(AgentID SMALLINT PRIMARY KEY, AgentName VARCHAR, PhoneNumber VARCHAR);
The VARCHAR data type needs a size (and should probably be VARCHAR2 in Oracle and SMALLINT is an alias for NUMBER(38)):
CREATE TABLE AGENT_INFO(
AgentID SMALLINT PRIMARY KEY,
AgentName VARCHAR2(10),
PhoneNumber VARCHAR2(10)
);
If you want a string column that can accept text without specifying a maximum size then use CLOB:
CREATE TABLE AGENT_INFO(
AgentID NUMBER(38) PRIMARY KEY,
AgentName CLOB,
PhoneNumber CLOB
);
db<>fiddle here
varchar datatype requires size:
SQL> CREATE TABLE AGENT_INFO
2 (AgentID SMALLINT PRIMARY KEY,
3 AgentName VARCHAR2(20),
4 PhoneNumber VARCHAR2(20));
Table created.
SQL>
(Note that Oracle recommends varchar2 instead of varchar.)

Can't figure out what datatype is incorrect in my SQL table

I am trying to create a SQL table, but I keep getting this error.
Error report -
ORA-00902: invalid datatype
00902. 00000 - "invalid datatype"
Here is my code.
CREATE TABLE viewers
(
user_id SEQUENCE PRIMARY KEY,
first_name VARCHAR2(30),
last_name VARCHAR2(40) NOT NULL,
email VARCHAR2(40) CHECK(LENGTH(email) > 8),
DOB DATE,
CONSTRAINT contact_email UNIQUE (email)
);
CREATE SEQUENCE user_id_seq
START WITH 100000 INCREMENT BY 1
MINVALUE 100000 MAXVALUE 999999;
Your intention is correct but the usage syntactically is not.
You need to create the sequence as first step,
create sequence seq_user_id;
CREATE TABLE viewers
(
user_id number default seq_user_id.nextval PRIMARY KEY,
first_name VARCHAR2(30),
last_name VARCHAR2(40) NOT NULL,
email VARCHAR2(40) CHECK(LENGTH(email) > 8),
DOB DATE,
CONSTRAINT contact_email UNIQUE (email)
);
P.S. If you are using 12c and above then consider using identity column which is a nice feature. I am providing you the link.

Trying to run script through Oracle 11g

I am trying to run SQL statements in the Oracle 11g Express edition, where I am to create tables. Here is my SQL code:
CREATE TABLE STORE
(
StoreID INT PRIMARY KEY,
StoreName VARCHAR2(30) NOT NULL,
City VARCHAR2(30) NOT NULL,
Country VARCHAR2(30) NOT NULL CHECK Country in ('China','Egypt','United States','Spain','New Zealand','Mexico','Africa'),
Phone VARCHAR2(30) NOT NULL,
Fax VARCHAR2(30),
Email VARCHAR2(50) UNIQUE,
Contact VARCHAR2(30) NOT NULL,
UNIQUE (StoreName, City)
);
CREATE TABLE PURCHASE_ITEM
(
PurchaseItemID INT PRIMARY KEY,
StoreID INT NOT NULL REFERENCES STORE(StoreID) ON DELETE CASCADE ON UPDATE CASCADE,
"Date" DATE NOT NULL,
Description VARCHAR2(30) NOT NULL,
Category VARCHAR2(30),
PriceUsed NUMBER(15, 2)
);
CREATE SEQUENCE pur_seq
START WITH 500
INCREMENT BY 5;
CREATE OR REPLACE TRIGGER Purchase
BEFORE INSERT ON PURCHASE_ITEM
FOR EACH ROW
BEGIN
SELECT pur_seq.NEXTVAL
INTO :new.PurchaseItemID
FROM dual;
END;
CREATE TABLE SHIPPER
(
ShipperID INT PRIMARY KEY,
ShipperName VARCHAR2(30) NOT NULL,
Phone VARCHAR2(30) NOT NULL,
Fax VARCHAR2(30),
Email VARCHAR2(50) UNIQUE,
Contact VARCHAR2(30) NOT NULL
);
CREATE TABLE SHIPMENT
(
ShipmentID INT PRIMARY KEY Auto Increment,
ShipperID INT NOT NULL REFERENCES SHIPPER(ShipperID) ON DELETE CASCADE ON UPDATE CASCADE,
ShipperInvoiceNumber INT NOT NULL UNIQUE,
Origin VARCHAR2(30) NOT NULL,
Destination VARCHAR2(30) NOT NULL,
DepartureDate DATE,
ArrivalDate DATE
);
ALTER TABLE SHIPMENT AUTO_INCREMENT = 100;
CREATE TABLE SHIPMENT_ITEM
(
ShipmentID INT NOT NULL REFERENCES SHIPMENT(ShipmentID) ON DELETE CASCADE ON UPDATE CASCADE,
ShipmentItemID INT NOT NULL,
PurchaseItemID INT NOT NULL REFERENCES PURCHASE_ITEM(PurchaseItemID) ON DELETE CASCADE ON UPDATE CASCADE,
InsuredValue NUMBER(15, 2) NOT NULL defaut 100,
PRIMARY KEY (ShipmentID, ShipmentItemID)
);
It only ends up processing 4 statements and I keep getting these error messages:
CREATE TABLE STORE ( StoreID INT PRIMARY K - ORA-00906: missing left parenthesis
CREATE TABLE PURCHASE_ITEM ( PurchaseItemID INT - ORA-00907: missing right parenthesis
CREATE SEQUENCE pur_seq START WITH 500 INCREMENT BY 5 - ORA-00955: name is already used by an existing object
CREATE OR REPLACE TRIGGER Purchase BEFORE INSERT ON PURCHASE - ORA-00942: table or view does not exist
I am wholly unfamiliar with Oracle 11g. I am unsure if I am using the correct application in it for my assignment. I am only going by these instructions:
"For this assignment you are to write scripts to create tables and insert records. In oracle 11g I don’t want you to use the tools to generate the tables, you are required to write scripts to create the tables and records and will need to include the scripts for your submission."
Please, what am I doing wrong?
Let me summarize the problems with your scripts
First you have to enclose the check constraint with braces like below
CREATE TABLE STORE
(
StoreID INT PRIMARY KEY,
StoreName VARCHAR2(30) NOT NULL,
City VARCHAR2(30) NOT NULL,
Country VARCHAR2(30) NOT NULL CHECK (Country in ('China','Egypt','United States','Spain','New Zealand','Mexico','Africa')),
Phone VARCHAR2(30) NOT NULL,
Fax VARCHAR2(30),
Email VARCHAR2(50) UNIQUE,
Contact VARCHAR2(30) NOT NULL,
UNIQUE (StoreName, City)
);
Second, there is no ON UPDATE CASCADE in Oracle 11g so you need to remove it from the CREATE TABLE statement
Third, there is no Auto increment in Oracle 11G for columns So refer this SO for a workaround
Please let me know with these corrections whether your issue is resolved

Oracle error sql

I have to create a table and insert values into the tables. The tables is being created but it wont insert values.
heres my code-
CREATE TABLE CUSTOMER(
CID number(20) not null primary key,
FNAME varchar2(50) not null,
MIDDLE varchar2(50) null,
LNAME varchar2(50) not null,
STREET varchar2(50) not null,
CITY varchar2(50) not null,
STATE char(2) not null,
ZIP varchar2(5) not null,
PHONE varchar2(20) not null,
BIRTH_YR date);
INSERT INTO CUSTOMER VALUES(
'1','john','paul','connor','Broad st','newark','nj','07103','2018643110','1992');
I keep getting an error
[Error] Script lines: 12-14 ------------------------
ORA-01861: literal does not match format string
Script line 14, statement line 2, column 85
Can somebody help me out? What am i doing wrong?
You must change the table definition to something like below to allow insertion of year in the format you need:
CREATE TABLE CUSTOMER(
CID number(20) not null primary key,
FNAME varchar2(50) not null,
MIDDLE varchar2(50) null,
LNAME varchar2(50) not null,
STREET varchar2(50) not null,
CITY varchar2(50) not null,
STATE char(2) not null,
ZIP varchar2(5) not null,
PHONE varchar2(20) not null,
BIRTH_YR char(4) not null);
Otherwise, you have to provide literal date values in the default format accepted by your Oracle database. You can use this query to find out what is the date format accepted by your system:
SELECT *
FROM nls_database_parameters
WHERE parameter LIKE '%DATE%'
For me, it returns:
NLS_DATE_FORMAT | DD-MON-RR
---------------------------------
NLS_DATE_LANGUAGE | AMERICAN
which means instead of '1992', I should insert values such as '01-Jan-1992' in the BIRTH_YR column:
INSERT INTO CUSTOMER
VALUES('1','john','paul','connor','Broad st','newark','nj','07103','2018643110', '01-Jan-1992');
BIRTH_YR being a DATE field should be given in 'yyyy-MM-dd' format, '1992-01-01'.