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;
Related
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 8 days ago.
Improve this question
I have working on a project. i found that SQL code on internet. i have not familiar with SQL. anyone help me regarding this. I have facing difficulties to execute this query in SQL work bench after login as administration.
Line number 1, 4, 5 and 6 getting error. Please correct this code what things I need to correct or change.
create user reservation identified by manager;
grant dba to reservation;
commit;
connect reservation/manager;
create table admin6(uname varchar2(40) primary key,name varchar2(40),
pword varchar2(50),mail_id varchar2(60),phone_no varchar2(12));
create table train6(tr_no number(10) primary key,tr_name varchar2(70),
from_stn varchar2(20),to_stn varchar2(20),available number(5),fare number(5));
create table register(uname varchar2(40) primary key,pword varchar2(50),
fname varchar2(40),lname varchar2(40),
addr varchar2(100), phno varchar2(12), mailid varchar2(60));
insert into admin6 values('admin','admin','admin','admin#train.com','9874561230');
insert into admin6 values('shashi','shashi','admin','shashi#train.com','98323561230');
insert into train6 values(10101,'Jodhpur Exp','Howrah','Jodhpur',152,450);
insert into train6 values(10102,'Mumbai Mail','Gaya','Mumbai',182,650);
insert into register values('shashi','shashi','Shashi','Raj','Tekari, Gaya, Bihar',954745222,'shashiraj.972#gmail.com');
commit;
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)
);
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 8 years ago.
Improve this question
I am having some difficulties with Oracle and Inner Joins:
I am trying to do the following "List patientID and ages of patients who are allergic to tree nuts.
I have set up the following query:
SELECT patientID, age
2 FROM PATIENT
3 JOIN Allergy on patient.patientID=allergy.patientID
4 WHERE Allergy ='Tree Nuts';
JOIN Allergy on patient.patientID=allergy.patientID
*
ERROR at line 3:
ORA-00904: "ALLERGY"."PATIENTID": invalid identifier
THE DDL for patient and allergy are as follows:
CREATE TABLE Patient
(patientID NUMBER NOT NULL,
patientMRN VARCHAR2(30) NOT NULL,
lastName VARCHAR2(30),
firstName VARCHAR2(30),
age NUMBER,
gender VARCHAR2(10),
street VARCHAR2(60),
city VARCHAR2(60),
state VARCHAR2(30),
zip VARCHAR2(15),
CONSTRAINT patient_PK PRIMARY KEY (patientID));
CREATE TABLE Allergy
(allergyID NUMBER NOT NULL,
allergyName VARCHAR2(60) NOT NULL,
type VARCHAR2(30),
CONSTRAINT allergy_PK PRIMARY KEY (allergyID));
CREATE TABLE PatientAllergy
(
patientID NUMBER NOT NULL,
allergyID NUMBER NOT NULL,
notedDate DATE,
severity VARCHAR2(30),
CONSTRAINT patientallergy_PK PRIMARY KEY (patientID, allergyID),
CONSTRAINT patientallergy_FK1 FOREIGN KEY (patientID)
REFERENCES Patient(patientID) ON DELETE CASCADE,
CONSTRAINT patientallergy_FK2 FOREIGN KEY(allergyID)
REFERENCES Allergy(allergyID) ON DELETE CASCADE
)
I am not sure what I am doing to obtain this error.
I tried this query:
SELECT patientID, age
FROM Patient, PatientAllergy
WHERE patient.patientID=patientallergy.patientID AND Allergy = 'Tree Nuts';
I am still getting an error of: ERROR at line 4: ORA-00904: "ALLERGY": invalid identifier
You're missing a table in your query and not qualifying the column name in your WHERE clause correctly. Table aliases also make your query more readable. The below query should work for you:
SELECT p.patientID, p.age
FROM patient p
JOIN patientallergy pa ON p.patientid = pa.patientid
JOIN allergy a ON a.allergyid = pa.allergyid
WHERE a.allergyname = 'Tree Nuts'
The error is pretty clear, you're using a column [patientID] that doesn't exist in the table Allergy.
Your table Allergy only have the following columns (if I refer to your script):
allergyID
allergyName
type
Tell me if I'm wrong but it seems to be the reason of your problem.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I want to design table for patient prescription it contains pat_id, date and more than one prescription prescribed by doctor
How to do this?
Give me a sample query to create table
This isn't really a good quetion and is a very likely candidate for someone down voting it.
Look here for an example schema
http://www.databaseanswers.org/data_models/patient_care/index.htm
Possible this be helpful for you -
CREATE TABLE dbo.Patient
(
PacientID INT IDENTITY(1,1) PRIMARY KEY
, FirstName VARCHAR(30)
, LastName VARCHAR(30)
)
GO
CREATE TABLE dbo.PatientPrescription
(
ID INT IDENTITY(1,1) PRIMARY KEY
, PacientID INT
, DoctorID INT
, [Descritpion] VARCHAR(500)
)
GO
CREATE TABLE dbo.Doctor
(
DoctorID INT IDENTITY(1,1) PRIMARY KEY
, FirstName VARCHAR(30)
, LastName VARCHAR(30)
)
GO
I want to accept only the number that is given in the number of digits that I chose. How can i do that in Oracle?
CREATE TABLE suppliers
(
supplier_id numeric(4),
supplier_name varchar2(50),
CONSTRAINT check_supplier_id
***CHECK (supplier_id BETWEEN 100 and 9999)***
);