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

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

Related

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

ORA-00907: missing right parenthesis !! im trying to create tables, should i add a foreign key?

CREATE TABLE brunch
(
br_id INT NOT NULL PRIMARY KEY,
br_name INT NOT NULL
)
CREATE TABLE employee
(
e_id INT NOT NULL PRIMARY KEY,
bdate DATE,
fname VARCHAR2(30),
lname VARCHAR2(30),
sal NUMBER,
sex VARCHAR2(1),
address VARCHAR2(50),
super_id INT REFERENCES employee(e_id)
)
ALTER TABLE brunch ADD mgr_id int REFERENCES employee(e_Id);
ALTER TABLE employee ADD b_id INT REFERENCES brunch(br_id);
CREATE TABLE client
(
c_id INT NOT NULL PRIMARY KEY,
c_name VARCHAR2(40),
c_oemail VARCHAR2(40),
c_email VARCHAR2(40),
b_id reference brunch(b_id)
)
The problem is with the last table, table client, and it give me an error message that says
ORA-00907: missing right parenthesis
but I don't see any problem with the syntax. Thank you
The last DDL should be
create table client
(
c_id int primary key,
c_name varchar2(40),
c_oemail varchar2(40),
c_email varchar2(40),
b_id references brunch(br_id)
);
where column name b_id should be br_id and
there's no keyword called reference but references
P.S. There's no need to use NOT NULL for a column defined as PRIMARY KEY(already includes NOT NULL).

Need help in the query (oracle 11 g)

First of all, these are my create_table statements.
/*--- Base tables ---*/
CREATE TABLE CUSTOMER (
CUST_ID VARCHAR(10) NOT NULL,
CUST_FNAME VARCHAR(15),
CUST_LNAME VARCHAR(15),
CUST_HP NUMBER(10),
CUST_EMAIL VARCHAR(40),
primary key (CUST_ID)
);
CREATE TABLE STAFF(
STAFF_ID NUMBER(12) NOT NULL,
STAFF_FNAME VARCHAR(15),
STAFF_LNAME VARCHAR(15),
STAFF_DOB Date,
STAFF_AGE NUMBER(2),
STAFF_ADDRESS VARCHAR(70),
STAFF_HP NUMBER(10),
STAFF_SALARY NUMBER(6,2),
primary key (STAFF_ID)
);
CREATE TABLE SUPPLIER(
SUPP_ID VARCHAR(10) NOT NULL,
SUPP_NAME VARCHAR(30),
SUPP_TEL NUMBER(10),
SUPP_EMAIL VARCHAR(25),
SUPP_ADDRESS VARCHAR(80),
SUPP_CITY VARCHAR(20),
SUPP_STATE VARCHAR(10),
SUPP_ZIP NUMBER(5),
primary key (SUPP_ID)
);
CREATE TABLE PRODUCT(
PROD_ID VARCHAR(10) NOT NULL,
PROD_NAME VARCHAR(30),
PROD_DESC VARCHAR(70),
R_UNIT_PRICE NUMBER(3,2) DEFAULT 4.50,
L_UNIT_PRICE NUMBER(3,2) DEFAULT 5.00,
primary key (PROD_ID)
);
CREATE TABLE INGREDIENT(
ING_ID VARCHAR(10) NOT NULL,
ING_NAME VARCHAR(20),
ING_DESC VARCHAR(60),
primary key (ING_ID)
);
CREATE TABLE TOPPING(
TOP_ID VARCHAR(10) NOT NULL,
TOP_NAME VARCHAR(20),
TOP_DESC VARCHAR(40),
TOP_PRICE NUMBER(2,2),
primary key (TOP_ID)
);
/*--- Child tables ---*/
CREATE TABLE ORDERS(
ORDERS_ID VARCHAR(10) NOT NULL,
CUST_ID VARCHAR(10) NOT NULL,
STAFF_ID NUMBER(12) NOT NULL,
TOTAL_PRICE NUMBER(5,2),
ORDERS_DATE DATE,
primary key (ORDERS_ID),
foreign key (CUST_ID) references CUSTOMER(CUST_ID),
foreign key (STAFF_ID) references STAFF(STAFF_ID)
);
CREATE TABLE ORD_DETAIL(
SK1_ID NUMBER(4) NOT NULL,
ORDERS_ID VARCHAR(10) NOT NULL,
PROD_ID VARCHAR(10) NOT NULL,
TOP_ID VARCHAR(10) NOT NULL,
TEATYPE VARCHAR(8),
CUPSIZE CHAR(1),
QTY NUMBER(2),
CONSTRAINT CHK_CUPSIZE CHECK (CUPSIZE = 'R' OR CUPSIZE = 'L'),
CONSTRAINT CHK_TEATYPE CHECK (TEATYPE = 'Oolong' OR TEATYPE = 'Jasmine'),
primary key (SK1_ID),
foreign key (ORDERS_ID) references ORDERS(ORDERS_ID),
foreign key (PROD_ID) references PRODUCT(PROD_ID),
foreign key (TOP_ID) references TOPPING(TOP_ID)
);
CREATE TABLE PROD_ING(
PROD_ID VARCHAR(10) NOT NULL,
ING_ID VARCHAR(10) NOT NULL,
primary key (PROD_ID , ING_ID),
foreign key (PROD_ID) references PRODUCT(PROD_ID),
foreign key (ING_ID) references INGREDIENT(ING_ID)
);
CREATE TABLE ING_SUPP(
ING_ID VARCHAR(10) NOT NULL,
SUPP_ID VARCHAR(10) NOT NULL,
SUPP_PRICE NUMBER(6,2),
primary key (ING_ID, SUPP_ID),
foreign key (ING_ID) references INGREDIENT(ING_ID),
foreign key (SUPP_ID) references SUPPLIER(SUPP_ID)
);
And my query is this:Which employee served the most number of customers?
But when I executed these statements:
SELECT MAX (COUNT (O.CUST_ID)) AS "Served customer"
FROM STAFF S, ORDERS O
WHERE (S.STAFF_ID = O.STAFF_ID)
GROUP BY O.STAFF_ID
HAVING COUNT (O.CUST_ID) > 0;
What I got was there was a column named "Served customer" with the maximum number only.
So, now my question is how to display the employee's ID, first name and last name along with
"Served customer" column.
The question is: "Which employee served the most number of customers? " Your query does not even return information about the employee, only about the number of customers.
The following aggregation returns for each staff member, the number of customers who were served:
SELECT O.STAFF_ID, COUNT(O.CUST_ID) AS "Served customer"
FROM STAFF SS JOIN
ORDERS O
ON S.STAFF_ID = O.STAFF_ID
GROUP BY O.STAFF_ID;
To get the maximum number we just need to order this by the count and take the first row. In Oracle, this uses a subquery:
SELECT so.*
FROM (SELECT O.STAFF_ID, COUNT(O.CUST_ID) AS "Served customer"
FROM STAFF SS JOIN
ORDERS O
ON S.STAFF_ID = O.STAFF_ID
GROUP BY O.STAFF_ID
ORDER BY COUNT(O.CUST_ID) DESC
) so
WHERE rownum = 1;

building table but get "missing right parenthesis"

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

Oracle SQL error ORA-00907: missing right parenthesis

How are you all?
Basically I've written up this bit of SQL code to create a table but I keep getting the error stated in the title, any idea as to why?
Here's the code:
CREATE TABLE staff(
staffID INT NOT NULL PRIMARY KEY,
firstName VARCHAR2(20),
lastName VARCHAR2(20),
addressLine_1 VARCHAR2(30),
city VARCHAR2(15),
postcode VARCHAR2(7),
telephone VARCHAR2(15),
salary DECIMAL (19,4),
branchID INT FOREIGN KEY REFERENCES branches(branchID)
);
Also here is the code for my 'branches' table
CREATE TABLE branches
(branchID int NOT NULL PRIMARY KEY,
addressLine_1 VARCHAR2(30),
city VARCHAR2(15),
postcode VARCHAR2(7),
telephone VARCHAR2(15),
manager VARCHAR2(20));
Any help would be appreciated!
Thank you!
A few suggestions:
First make sure that the branches table has been created.
Second, I would alter the create table code to the following:
CREATE TABLE staff(
staffID INT NOT NULL PRIMARY KEY,
firstName VARCHAR(20),
lastName VARCHAR(20),
addressLine_1 VARCHAR2(30),
city VARCHAR2(15),
postcode VARCHAR2(7),
telephone VARCHAR2(15),
salary DECIMAL (19,4),
branchID INT,
constraint fk_branchId FOREIGN KEY (branchID) REFERENCES branches(branchID)
);
See SQL Fiddle with Demo. The syntax to create a FOREIGN KEY during table creation is:
CREATE TABLE table_name
(
column1 datatype null/not null,
column2 datatype null/not null,
...
CONSTRAINT fk_column
FOREIGN KEY (column1, column2, ... column_n)
REFERENCES parent_table (column1, column2, ... column_n)
);
Here is the creation of table staff1
CREATE TABLE staff
(
staffID INT NOT NULL PRIMARY KEY,
firstName VARCHAR2(20),
lastName VARCHAR2(20),
addressLine_1 VARCHAR2(30),
city VARCHAR2(15),
postcode VARCHAR2(7),
telephone VARCHAR2(15),
branchID int,
salary DECIMAL (19,4),
CONSTRAINT BRANCH_fk FOREIGN KEY(branchID) REFERENCES branches(branchID)
)
SQL> /
Table created.
Please use constraint name such that finding an error becomes easy.
create table medication (
id int not null primary key,
name varchar(20),
mudslig price number (10),
protect date not null default (getdate()),
finish date not null default (getdate()),
company proect varchre2 (20),
shelf id int,
chemistid int,
constraint shelf_fk foreign key (shelf id) refences shelf (shelf id),
constraint chemist_fk foreign key (chemistid) refences chemist (chemistid)
);
Please use constraint name such that finding an error becomes easy.