building table but get "missing right parenthesis" - sql

I try to build this table
CREATE TABLE OFFICER
(
ID int(8) PRIMARY KEY,
FIRST_NAME varchar2(20) NOT NULL,
LAST_NAME varchar2(20) NOT NULL,
HIRE_DATE date NOT NULL,
UNHIRE_DATE date,
SALARY int(7),
PHONE_NUMBER int(10),
TYPE varchar2(15) NOT NULL
);
Do I have to use any constraint, reference? and What I lack for this code?

INT data type doesn't allow scale specification. Try either ID int primary key or Id NUMBER(8) primary key.

Try this,
CREATE TABLE OFFICER
(
ID NUMBER(8) PRIMARY KEY,
FIRST_NAME varchar2(20) NOT NULL,
LAST_NAME varchar2(20) NOT NULL,
HIRE_DATE date NOT NULL,
UNHIRE_DATE date,
SALARY NUMBER(7),
PHONE_NUMBER NUMBER(10),
TYPE varchar2(15) NOT NULL
);

Related

I'm getting this error: "Missing right parenthesis"

CREATE TABLE CUSTOMER
(
CUSTOMER_NO INT(3) PRIMARY KEY,
CUSTOMER_NAME VARCHAR2(200),
CUSTOMER_ADDRESS VARCHAR2(200),
CUSTOMER_PHONE INT(10),
GENDER VARCHAR2(10)
);
Error
Missing right parenthesis
In Oracle, the INT type is not parameterizable. INT is an alias for NUMBER(38).
Either remove the parameters (ie INT(3) and INT(10) should be just INT):
CREATE TABLE CUSTOMER (
CUSTOMER_NO INT PRIMARY KEY,
CUSTOMER_NAME VARCHAR2(200),
CUSTOMER_ADDRESS VARCHAR2(200),
CUSTOMER_PHONE INT,
GENDER VARCHAR2(10)
);
or, if you want to limit the number of digits, use NUMBER(p):
CREATE TABLE CUSTOMER (
CUSTOMER_NO NUMBER(3) PRIMARY KEY,
CUSTOMER_NAME VARCHAR2(200),
CUSTOMER_ADDRESS VARCHAR2(200),
CUSTOMER_PHONE NUMBER(10),
GENDER VARCHAR2(10)
);

How to fix invalid data type size in this sql query?

The query i wrote as
CREATE TABLE Shopper (
Shopperid NUMBER(4) CONSTRAINT shpr_shprid_pk PRIMARY KEY,
ShopperName VARCHAR2(20) CONSTRAINT shpr_shprname_nn NOT NULL,
Gender CHAR(6) CONSTRAINT shpr_gdr_chk CHECK(Gender IN ('Male','Female')),
MobileNo NUMBER(10) CONSTRAINT shpr_mobno_nn NOT NULL,
Address VARCHAR2(50)
);
The issue is with NUMBER type definitions, try:
CREATE TABLE Shopper (
Shopperid NUMBER CONSTRAINT shpr_shprid_pk PRIMARY KEY,
ShopperName VARCHAR2(20) CONSTRAINT shpr_shprname_nn NOT NULL,
Gender CHAR(6) CONSTRAINT shpr_gdr_chk CHECK(Gender IN ('Male','Female')),
MobileNo NUMBER CONSTRAINT shpr_mobno_nn NOT NULL,
Address VARCHAR2(50)
);

Which SQL datatype can be used to store mobile numbers in numeric forms, without including characters like brackets and hyphens?

CREATE TABLE Shopper
(
Shopperid INTEGER PRIMARY KEY,
ShopperName VARCHAR2(20) NOT NULL,
Gender VARCHAR2(6) CHECK(Gender IN ('Male', 'Female')),
MobileNo NUMBER NOT NULL,
Address VARCHAR2(50)
);
I'm trying to create a table and I want my mobile no. to be devoid of any hyphens and brackets.
Store the value as a string with a check constraint:
CREATE TABLE Shopper (
Shopperid INTEGER PRIMARY KEY,
ShopperName VARCHAR2(20) NOT NULL,
Gender VARCHAR2(6) CHECK (Gender IN ('Male', 'Female')),
MobileNo VARCHAR2(30) NOT NULL CHECK (REGEXP_LIKE(MobileNo, '^[0-9]*$')),
Address VARCHAR2(50)
);
This is the code posted in the question by Jazir Ahammed
CREATE TABLE Shopper
(
Shopperid INTEGER PRIMARY KEY,
ShopperName VARCHAR2(20) NOT NULL,
Gender VARCHAR2(6) CHECK(Gender IN ('Male', 'Female')),
MobileNo NUMBER NOT NULL,
Address VARCHAR2(50)
);
This is the post by Gordon Linoff
CREATE TABLE Shopper (
Shopperid INTEGER PRIMARY KEY,
ShopperName VARCHAR2(20) NOT NULL,
Gender VARCHAR2(6) CHECK (Gender IN ('Male', 'Female')),
MobileNo VARCHAR2(30) NOT NULL CHECK (REGEXP_LIKE(MobileNo, '^[0-9]$')),
Address VARCHAR2(50)
);
This is the answer for INFYTQ's collaboration assignment 2 on DBMS
CREATE TABLE Shopper(
Shopperid INTEGER,
ShopperName VARCHAR2(20) NOT NULL,
Gender CHAR(6),
MobileNo NUMBER NOT NULL,
Address VARCHAR2(50),
CONSTRAINT s_id_pk PRIMARY KEY(ShopperId),
CONSTRAINT s_gender_ck CHECK(Gender IN ('Male', 'Female'))
)
image of output at InfyTQ

Foreign key missing parenthesis

CREATE TABLE EMPLOYEE (
EID CHAR(3) NOT NULL PRIMARY KEY,
ENAME VARCHAR2(50) NOT NULL,
JOB_TYPE VARCHAR2(50) NOT NULL,
MANAGER CHAR(3) FOREIGN KEY REFERENCES EMPLOYEE(EID),
HIRE_DATE DATE NOT NULL,
DNO INTEGER FOREIGN KEY REFERENCES DEPARTMENT(DNO),
COMMISSION DECIMAL(10,2),
SALARY DECIMAL(7,2) NOT NULL,
);
CREATE TABLE DEPARTMENT (
DNO INT NOT NULL PRIMARY KEY,
DNAME VARCHAR(50),
LOCATION VARCHAR(50) DEFAULT('NEW DELHI')
);
in creation of the employee table
this is giving me an error of right parenthesis
and the department table is already created
You have an extra comma in the line
SALARY DECIMAL(7,2) NOT NULL,
Delete that comma and the Employee table should be created.
You need to Create the Department Table first to use one of its
Columns as FOREIGN KEY.
Also, check your database. There might already be a Department Table. To avoid getting that error when the table needed is already created, use the keyword IF NOT EXISTS
CREATE TABLE IF NOT EXISTS Department(
DNO INT NOT NULL PRIMARY KEY,
DNAME VARCHAR(50),
LOCATION VARCHAR(50) DEFAULT('NEW DELHI')
);
The error is caused by the trailing comma, but you have other issues:
The FOREIGN KEY is not needed for an inline reference.
You need to define the tables in the right order.
So . . .
CREATE TABLE DEPARTMENT (
DNO INT NOT NULL PRIMARY KEY,
DNAME VARCHAR(50),
LOCATION VARCHAR(50) DEFAULT('NEW DELHI')
);
CREATE TABLE EMPLOYEE (
EID CHAR(3) NOT NULL PRIMARY KEY,
ENAME VARCHAR2(50) NOT NULL,
JOB_TYPE VARCHAR2(50) NOT NULL,
MANAGER CHAR(3) REFERENCES EMPLOYEE(EID),
HIRE_DATE DATE NOT NULL,
DNO INTEGER REFERENCES DEPARTMENT(DNO),
COMMISSION DECIMAL(10,2),
SALARY DECIMAL(7,2) NOT NULL
);
Here is an example of it working.

SQL Error: ORA-00907: missing right parenthesis - CANNOT FIND ERROR

Having started at the same statements over and over again, I still cannot find the missing right parenthesis. It's appeared when running both of these statements and in order to run the rest of my tables I need to be able to locate the right parenthesis.
I've selected the parenthesis used in the statements and all seemed to match up to the right ones. Can anyone suggest anything?
CREATE TABLE booking (
bookingNo NUMBER(8) PRIMARY KEY,
customerNo NUMBER(8) NOT NULL
REFERENCES customer(customerNo),
registrationNo VARCHAR2(10) NOT NULL
REFERENCES vehicle(registrationNo),
dateOfBooking DATE NOT NULL
DEFAULT SYSDATE,
pickupStreetAddressLine VARCHAR2(30) NOT NULL,
pickupTown VARCHAR2(30) NOT NULL,
pickupPostcode VARCHAR2(10) NOT NULL,
startTime NUMBER(4,2) NOT NULL,
startDate DATE NOT NULL
DEFAULT SYSDATE,
endTime NUMBER(4,2) NOT NULL,
endDate DATE NOT NULL
DEFAULTSYSDATE,
noOfPassengers NUMBER(3) NOT NULL
CONSTRAINT CHECK(noOfPassengers > 0 AND noOfPassengers <= 73)
price NUMBER(8,2) NOT NULL
);
CREATE TABLE employees (
nationalInsuranceNo VARCHAR2(10) PRIMARY KEY,
fullName VARCHAR2(50) NOT NULL,
streetAddress VARCHAR2(30) NOT NULL,
town VARCHAR2(30),
postcode VARCHAR2(10) NOT NULL,
homeNo NUMBER(11)
dateOfBirth DATE NOT NULL,
gender VARCHAR2(8) NOT NULL
CONSTRAINT CHECK(gender="Male" OR gender="Female"),
jobDescription VARCHAR2(30) NOT NULL,
currentSalary NUMBER(6) NOT NULL
CONSTRAINT CHECK(currentSalary>0)
);
Try using a standard indentation scheme to visually verify your formatting.
Here I moved each significant paren to a newline and indented each piece separately.
I put comments next to a few items that seem wrong:
CREATE TABLE
booking
(
bookingNo NUMBER(8) PRIMARY KEY,
customerNo NUMBER(8) NOT NULL
REFERENCES customer(customerNo),
registrationNo VARCHAR2(10) NOT NULL
REFERENCES vehicle(registrationNo),
dateOfBooking DATE NOT NULL
DEFAULT SYSDATE,
pickupStreetAddressLine VARCHAR2(30) NOT NULL,
pickupTown VARCHAR2(30) NOT NULL,
pickupPostcode VARCHAR2(10) NOT NULL,
startTime NUMBER(4,2) NOT NULL,
startDate DATE NOT NULL
DEFAULT SYSDATE,
endTime NUMBER(4,2) NOT NULL,
endDate DATE NOT NULL
DEFAULT SYSDATE, -- THERE WAS A MISSING SPACE HERE *********************
noOfPassengers NUMBER(3) NOT NULL, -- MISSING COMMA ********
CONSTRAINT Check_noOfPassengers CHECK -- ADD A CONSTRAINT NAME *********
(
noOfPassengers > 0
AND noOfPassengers <= 73
), -- THERE WAS A MISSING COMMA HERE *******************
price NUMBER(8,2) NOT NULL
);
CREATE TABLE
employees
(
nationalInsuranceNo VARCHAR2(10) PRIMARY KEY,
fullName VARCHAR2(50) NOT NULL,
streetAddress VARCHAR2(30) NOT NULL,
town VARCHAR2(30),
postcode VARCHAR2(10) NOT NULL,
homeNo NUMBER(11), -- THERE WAS A MISSING COMMA HERE ***************
dateOfBirth DATE NOT NULL,
gender VARCHAR2(8) NOT NULL, -- MISSING COMMA *****
CONSTRAINT Check_gender CHECK -- ADD A CONSTRAINT NAME *********
(
gender="Male"
OR gender="Female"
),
jobDescription VARCHAR2(30) NOT NULL,
currentSalary NUMBER(6) NOT NULL, -- MISSING COMMA
CONSTRAINT Check_currentSalary CHECK -- ADD A CONSTRAINT NAME *********
(
currentSalary>0
)
);
I don't have Oracle installed to test, but is there a missing comma for the column noOfPassengers above? More generally, it may not be a missing right parens, but a parens that is out of place because of another syntax error. Hope that helps.
Change this DEFAULTSYSDATE to this DEFAULT SYSDATE on the 17th line
Also, add the column name before each CHECK and after the CONSTRAINT words. And add a comma after the first CONSTRAINT statement.
Hope it helps :)