SQL missing parenthesis when creating a table [closed] - sql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 12 months ago.
Improve this question
I'm trying to create a table for a college project, but when I run my code it tells me I am missing a left parenthesis, and I simply cannot see where.
please help code is below
create table booking (
booking_id number
, booking_ref varchar2
, booking_date date
, passenger_id number
, travel_class_code varchar2
, flight_id number
, airplane_id varchar2 compound key
, booking_status_id varchar2 compound key
, ticket_type_code varchar2
, payment_method varchar2
);

You need sizes on the VARCHAR2 data types and compound key is not valid.
create table booking (
booking_id number
, booking_ref varchar2(1)
, booking_date date
, passenger_id number
, travel_class_code varchar2(1)
, flight_id number
, airplane_id varchar2(1)
, booking_status_id varchar2(1)
, ticket_type_code varchar2(1)
, payment_method varchar2(1)
, CONSTRAINT BOOKING__PK PRIMARY KEY (airplane_id, booking_status_id)
);

Related

How to solve ERROR MISSING RIGHT PARENTHESIS ? (ORACLE) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
CREATE TABLE BILL
(TRANSACTION_ID VARCHAR2(10) NOT NULL ENABLE,
DATE_BILL DATE,
SERVICE_CHARGE NUMBER(10,2) AS (0.10*PRODUCT_PRICE*PRODUCT_QUANTITY) REFERENCES PRODUCT(PRODUCT_PRICE) AND PRODUCT(PRODUCT_QUANTITY),
TRANSACTION_AMOUNT NUMBER(10,2) AS ((PRODUCT_PRICE*PRODUCT_QUANTITY) + (0.10*PRODUCT_PRICE*PRODUCT_QUANTITY)) REFERENCES PRODUCT(PRODUCT_PRICE) AND PRODUCT(PRODUCT_QUANTITY),
TRANSACTION_TYPE VARCHAR2(45),
ORDER_ID VARCHAR2(45) REFERENCES ORDERS(ORDER_ID),
CUST_ID VARCHAR2(45) NOT NULL ENABLE,
PRIMARY KEY (TRANSACTION_ID)
USING INDEX ENABLE
);
Apart from the fact that syntax you "invented" doesn't even exist, you're trying to create virtual columns (service_charge and transaction_amount) that reference columns from another table(s), most probably product. Well, you can't.
Looks like you'd rather create a view.
Something like this (you didn't post how tables are related to each other so I'm just guessing):
CREATE TABLE bill
(
transaction_id VARCHAR2 (10) PRIMARY KEY,
date_bill DATE,
transaction_type VARCHAR2 (45),
order_id VARCHAR2 (45) REFERENCES orders (order_id),
cust_id VARCHAR2 (45)
);
CREATE OR REPLACE VIEW v_bill_product
AS
SELECT b.transaction_id,
b.date_bill,
b.transaction_type,
b.order_id,
b.cust_id,
--
0.1 * p.product_price * p.product_quantity AS service_charge,
1.1 * p.product_price * product_quantity AS transaction_amount
FROM bill b JOIN product p ON b.transaction_id = p.transaction_id;

i keep getting a "missing right parenthesis" error. But cannot see anything visibly wrong [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed last year.
Improve this question
I am new to SQL and I have been trying to make this table however when I put the duration of the tour as an integer that would last an hour and a half. however, it keeps showing up as red and giving the error message that it's "missing the right parentheses". I've only been taught how to use integers but not sure if this is the right one to use in this situation.
and for the table that will be referenced from that table is saying that there is nothing to reference and rightfully so because I have yet to make the table. but if anybody could help with this problem it would be much appreciated!
create table qualification
( tour_id varchar2(8) not null
, guide varchar2(8) null
, date_passed date null
, primary key (tour_id, guide)
, foreign key (guide) references guide(guide_no)
, foreign key (tour_id) references tour(tour_id)
);
create table tour
( tour_id varchar2(8) primary key
, tour_name varchar2(20) not null
, duration_of_tour integer (180) null
, standard_cost integer (6,2) not null
);
Oracle has the NUMBER datatype.
INTEGER(n,m) wouldn't work anywhere.
Standard SQL would be DECIMAL(n,m) then.
So this statement will work
create table tour
( tour_id varchar2(8) primary key
, tour_name varchar2(20) not null
, duration_of_tour number(38,0) null
, standard_cost number(6,2) not null
);
But the size of duration_of_tour might be too big.
At the best of my knowledge, you can't define a column with a type of integer WITH precision. The "int" or "integer" are just aliases for type number with already defined precision. I'm almost sure it is aliases for max allowed - "number(38)"
So, it's either "integer" or "number(x,y)"
However if you updated your col type from integer(180) to number(180) you'll hit another error because number can't be 180 digits long.
Check this doc, perhaps you'll find something useful there

PostgreSQL CREATE TABLE: weird syntax error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have the following CREATE TABLE command:
create table user_payment_status(
ID serial primary key,
user_ID serial not null,
last_pay_date time with time zone,
next_pay_date time with time zone,
due_days integer,
warning_email_sent boolean not null,
user_visible boolean not null,
user_searchable boolean not null,
user_on_free_plan boolean not null,
created_at time with time zone,
CONSTRAINT fk_user
FOREIGN KEY(user_id)
REFERENCES users(id)
);
but I always get a misterious SQL Error [42601]: ERROR: syntax error at or near "not" error message for the line user_on_free_plan boolean not null,.
It doesn't matter where I place this line into the command, the problem is always in this line. Can you help me, what am I missing here, what should be the problem?
I have a lot of similar CREATE TABLE-s, all of them are executed without any problem.
Works here:
create table user_payment_status
( id SERIAL primary key
, user_id INTEGER not null -- <<--
, created_at TIMESTAMP with time zone -- <<--
, last_pay_date TIMESTAMP with time zone -- <<--
, next_pay_date TIMESTAMP with time zone -- <<--
, due_days integer
, warning_email_sent boolean not null
, user_visible boolean not null
, user_searchable boolean not null
, user_on_free_plan boolean not null
-- , CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id)
);
Some notes:
The FOREIGN KEY may refer to a serial, but it itself should be an int
the time fields should probably be timestamps
Thanks for the comments, dbfiddle and the idea of invisible not allowed ASCII character solved the issue:
between on_free_plan and boolean there was an ASCII "A0" character instead of ASCII "20" (space). Changed it to space, and works like a charm.
Thanks again! :-)

DEFAULT constraint not working in SQL Oracle? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm trying to get a constraint (this is just test code) but when I add the data (complete the whole table) and run it with leaving out Apptime data in the values it doesn't default to hello in the table it's just '-'. I'm using Oracle Live SQL. Any clue as to how this is done? Would be good if I could do it in the schema and not a constraint but if it has to be a constraint outside that's okay.
Thank you and apologies if I did anything wrong in this question, I'm new haha.
DROP TABLE Bok;
CREATE TABLE Bok (
BokID number(3) NOT NULL PRIMARY KEY,
Appdate varchar2(4),
Apptime varchar2(5) DEFAULT 'hello'
);
In order to default to work the insert query has to use DEFAULT keyword or skip the column
INSERT INTO Bok(BokID, Appdate, appTime)
VALUES (1, 'a', DEFAULT);
INSERT INTO Bok(BokID, Appdate)
VALUES (1, 'a');
One more option when DEFAULT ON NULL is defined:
CREATE TABLE Bok (
BokID number(3) NOT NULL PRIMARY KEY,
Appdate varchar2(4),
Apptime varchar2(5) DEFAULT ON NULL 'hello'
);
INSERT INTO Bok(BokID, Appdate, appTime)
VALUES (1, 'a', NULL);

Error in Code Newbie to Sql [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
Can you please tell me what is wrong with the code
CREATE TABLE VISIT
PET_ID NUMBER (25),
VET_ID VARCHAR2(20),
VISIT_DATE DATE,
BASIC_COST NUMBER (8,2),
SYMPTOM VARCHAR2 (80),
TREATMENT VARCHAR2 (25),
);
First the opening bracket '(' is missing, ie CREATE TABLE VISIT ( .
Second ',' not required after the last column, ie TREATMENT VARCHAR2 (25).
CREATE TABLE VISIT (
PET_ID NUMBER (25),
VET_ID VARCHAR2(20),
VISIT_DATE DATE,
BASIC_COST NUMBER (8,2),
SYMPTOM VARCHAR2 (80),
TREATMENT VARCHAR2 (25)
);