存储过程以更新库存

时间:2019-03-16 03:38:31

标签: oracle

我不知道我是否建立了表来正确创建它。我必须编写一个存储过程,以从下表中提取一个product_id和一个quantity_purchased。我只是一个学生,才刚刚开始,我不知道这个程序。我可能只是想得太清楚,但是可以提供任何帮助。

我的创建和插入内容如下。

这是我程序的开始,然后我意识到我不知道如何更新手头的数量。

drop table INVENTORY cascade constraints;
drop table LINE_ITEM cascade constraints;
drop table PURCHASES cascade constraints;
drop table RESERVATION cascade constraints;
drop table PAYROLL cascade constraints;
drop table GUEST_HOUSES cascade constraints;
drop table CHURCH cascade constraints;
drop table BOOK cascade constraints;
drop table PRODUCTS cascade constraints;
drop table SCHEDULE cascade constraints;
drop table NUN cascade constraints;
drop table MONK cascade constraints;
drop table SHOPS cascade constraints;
drop table PRODUCT_TYPES cascade constraints;
drop table SHOP_TYPE cascade constraints;
drop table VISITOR cascade constraints;
drop table STATE cascade constraints;
drop table EMPLOYEE cascade constraints;
drop table VENDOR cascade constraints;
drop table VACANCY cascade constraints;

CREATE TABLE GUEST_HOUSES
(
    HOUSE_ID NUMBER(9) PRIMARY KEY,
    ROOM_NUMBER NUMBER(2) NOT NULL,
    COST NUMBER(4,2) NOT NULL
);

CREATE TABLE RESERVATION
(
     RESERVATION_ID NUMBER(9) PRIMARY KEY,
     R_VISITOR_ID NUMBER(9) NOT NULL,
     R_HOUSE_ID NUMBER(9) NOT NULL,
     ARRIVAL_DATE DATE NOT NULL,
     DEPARTURE_DATE DATE NOT NULL,
     R_MONK_ID NUMBER(9) NOT NULL
);

CREATE TABLE VISITOR
(
     VISITOR_ID NUMBER(9) PRIMARY KEY,
     FIRST_NAME VARCHAR2(50) NOT NULL,
     LAST_NAME VARCHAR2(50) NOT NULL,
     ADDRESS VARCHAR2(100) NOT NULL,
     CITY VARCHAR2(50) NOT NULL,
     V_STATE_ID VARCHAR2(2) NOT NULL,
     ZIP NUMBER(5) NOT NULL
);

CREATE TABLE STATE
(
     STATE_ID VARCHAR2(2) PRIMARY KEY,
     STATE_NAME VARCHAR2(50) NOT NULL
);

CREATE TABLE CHURCH
(
     CHURCH_ID NUMBER(9) PRIMARY KEY,
     CHURCH_NAME VARCHAR2(25) NOT NULL
);

CREATE TABLE BOOK
(
     BOOK_ID NUMBER(9) PRIMARY KEY,
     TITLE VARCHAR2(50) NOT NULL,
     PUBLISH_DATE DATE,
     AUTHOR_FIRST VARCHAR2(50),
     AUTHOR_LAST VARCHAR2(50),
     SUBJECT VARCHAR2(50),
     ISBN VARCHAR2(25) NOT NULL
);

CREATE TABLE PRODUCTS
(
     PRODUCT_ID NUMBER(9) PRIMARY KEY,
     P_VENDOR_ID NUMBER(9) NOT NULL,
     P_NAME VARCHAR2(50) NOT NULL,
     P_PRODUCT_TYPE_ID NUMBER(9) NOT NULL
);

CREATE TABLE SCHEDULE
(SCHEDULE_ID NUMBER(9) PRIMARY KEY,
S_EMPLOYEE_ID NUMBER(9),
S_SHOP_ID NUMBER(9),
START_DATE DATE,
END_DATE DATE,
START_TIME NUMBER(4,2),
END_TIME NUMBER(4,2));

create table PRODUCT_TYPES
(PRODUCT_TYPE_ID NUMBER(9) PRIMARY KEY,
PT_NAME VARCHAR2(50) NOT NULL);

create table VENDOR
(VENDOR_ID NUMBER(9) PRIMARY KEY,
VENDOR_NAME VARCHAR2(50) NOT NULL);

create table NUN
(NUN_ID NUMBER(9) PRIMARY KEY,
N_FIRST_NAME VARCHAR2(25) NOT NULL,
N_LAST_NAME VARCHAR2(25) NOT NULL,
N_VENDOR_ID NUMBER(9));

create table EMPLOYEE
(EMPLOYEE_ID NUMBER(9) PRIMARY KEY,
E_FIRST_NAME VARCHAR2(25) NOT NULL,
E_LAST_NAME VARCHAR2(25) NOT NULL,
HOURLY_RATE NUMBER(4,2));

create table MONK
(MONK_ID NUMBER(9) PRIMARY KEY,
M_FIRST_NAME VARCHAR2(25) NOT NULL,
M_LAST_NAME VARCHAR2(25) NOT NULL,
M_VENDOR_ID NUMBER(9),
M_EMPLOYEE_ID NUMBER(9));

create table PURCHASES
(PURCHASE_ID NUMBER(9) PRIMARY KEY,
DATE_OF_PURCHASE DATE NOT NULL,
P_VISITOR_ID NUMBER(9) NOT NULL,
P_SHOP_ID NUMBER(9) NOT NULL);

create table INVENTORY
(INVENTORY_ID NUMBER(9) PRIMARY KEY,
I_PRODUCT_ID NUMBER(9) NOT NULL,
QUANTITY_ON_HAND NUMBER(9) NOT NULL,
QUANTITY_SOLD NUMBER(9),
QUANTITY_PURCHASED NUMBER(9),
COST DECIMAL NOT NULL);

create table SHOPS
(SHOP_ID NUMBER(9) PRIMARY KEY,
SHOP_NAME VARCHAR2(25) NOT NULL,
S_SHOP_TYPE_ID NUMBER(9) NOT NULL);

create table PAYROLL
(PAYROLL_ID NUMBER(9) PRIMARY KEY,
P_EMPLOYEE_ID NUMBER(9) NOT NULL,
HOURS_WORKED NUMBER(3),
PAY_DATE DATE);

create table LINE_ITEM
(LINE_ITEM_ID NUMBER(9) PRIMARY KEY,
L_PURCHASE_ID NUMBER(9) NOT NULL,
L_PRODUCT_ID NUMBER(9) NOT NULL,
QUANTITY NUMBER(3) NOT NULL,
PRICE DECIMAL NOT NULL);

create table SHOP_TYPE
(SHOP_TYPE_ID NUMBER(9) PRIMARY KEY,
SHOP_TYPE_NAME VARCHAR2(25) NOT NULL);

create table VACANCY
(VACANCY_ID NUMBER(9) PRIMARY KEY,
V_RESERVATION_ID NUMBER(9) NOT NULL,
BOOKED_DATE DATE NOT NULL);

alter table VISITOR
ADD CONSTRAINT V_STATE_ID
FOREIGN KEY (V_STATE_ID)
REFERENCES STATE(STATE_ID);

alter table PRODUCTS
ADD CONSTRAINT P_VENDOR_ID
FOREIGN KEY (P_VENDOR_ID)
REFERENCES VENDOR(VENDOR_ID);

alter table PRODUCTS
ADD CONSTRAINT P_PRODUCT_TYPE_ID
FOREIGN KEY (P_PRODUCT_TYPE_ID)
REFERENCES PRODUCT_TYPES(PRODUCT_TYPE_ID);

alter table SCHEDULE
ADD CONSTRAINT S_EMPLOYEE_ID
FOREIGN KEY (S_EMPLOYEE_ID)
REFERENCES EMPLOYEE(EMPLOYEE_ID);

alter table SCHEDULE
ADD CONSTRAINT S_SHOP_ID
FOREIGN KEY (S_SHOP_ID)
REFERENCES SHOPS(SHOP_ID);

alter table NUN
ADD CONSTRAINT N_VENDOR_ID
FOREIGN KEY (N_VENDOR_ID)
REFERENCES VENDOR(VENDOR_ID);

alter table MONK
ADD CONSTRAINT M_VENDOR_ID
FOREIGN KEY (M_VENDOR_ID)
REFERENCES VENDOR(VENDOR_ID);

alter table MONK
ADD CONSTRAINT M_EMPLOYEE_ID
FOREIGN KEY (M_EMPLOYEE_ID)
REFERENCES EMPLOYEE(EMPLOYEE_ID);

alter table PURCHASES
ADD CONSTRAINT P_VISITOR_ID
FOREIGN KEY (P_VISITOR_ID)
REFERENCES VISITOR(VISITOR_ID);

alter table PURCHASES
ADD CONSTRAINT P_SHOP_ID
FOREIGN KEY (P_SHOP_ID)
REFERENCES SHOPS(SHOP_ID);

alter table SHOPS
ADD CONSTRAINT S_SHOP_TYPE_ID
FOREIGN KEY (S_SHOP_TYPE_ID)
REFERENCES SHOP_TYPE(SHOP_TYPE_ID);

alter table PAYROLL
ADD CONSTRAINT P_EMPLOYEE_ID
FOREIGN KEY (P_EMPLOYEE_ID)
REFERENCES EMPLOYEE(EMPLOYEE_ID);

alter table LINE_ITEM
ADD CONSTRAINT L_PURCHASE_ID
FOREIGN KEY (L_PURCHASE_ID)
REFERENCES PURCHASES(PURCHASE_ID);

alter table LINE_ITEM
ADD CONSTRAINT L_PRODUCT_ID
FOREIGN KEY (L_PRODUCT_ID)
REFERENCES PRODUCTS(PRODUCT_ID);

alter table INVENTORY
ADD CONSTRAINT I_PRODUCT_ID
FOREIGN KEY (I_PRODUCT_ID)
REFERENCES PRODUCTS(PRODUCT_ID);

alter table RESERVATION
ADD CONSTRAINT R_MONK_ID
FOREIGN KEY (R_MONK_ID)
REFERENCES MONK(MONK_ID);

alter table RESERVATION
ADD CONSTRAINT R_VISITOR_ID
FOREIGN KEY (R_VISITOR_ID)
REFERENCES VISITOR(VISITOR_ID);

alter table RESERVATION
ADD CONSTRAINT R_HOUSE_ID
FOREIGN KEY (R_HOUSE_ID)
REFERENCES GUEST_HOUSES(HOUSE_ID);

alter table VACANCY
ADD CONSTRAINT V_RESERVATION_ID
FOREIGN KEY (V_RESERVATION_ID)
REFERENCES RESERVATION(RESERVATION_ID);


INSERT INTO STATE (STATE_ID, STATE_NAME) VALUES ('OR', 'OREGON');
INSERT INTO STATE (STATE_ID, STATE_NAME) VALUES ('WA', 'WASHINGTON');
INSERT INTO STATE (STATE_ID, STATE_NAME) VALUES ('CA', 'CALIFORNIA');
INSERT INTO STATE (STATE_ID, STATE_NAME) VALUES ('AK', 'ALASKA');
INSERT INTO STATE (STATE_ID, STATE_NAME) VALUES ('ID', 'IDAHO');
INSERT INTO STATE (STATE_ID, STATE_NAME) VALUES ('NY', 'NEW YORK');
INSERT INTO STATE (STATE_ID, STATE_NAME) VALUES ('UT', 'UTAH');
INSERT INTO STATE (STATE_ID, STATE_NAME) VALUES ('AL', 'ALABAMA');
INSERT INTO STATE (STATE_ID, STATE_NAME) VALUES ('AZ', 'ARIZONA');
INSERT INTO STATE (STATE_ID, STATE_NAME) VALUES ('AR', 'ARKANSAS');
INSERT INTO SHOP_TYPE(SHOP_TYPE_ID, SHOP_TYPE_NAME) VALUES (123, 'SHOPS');
INSERT INTO SHOP_TYPE(SHOP_TYPE_ID, SHOP_TYPE_NAME) VALUES (456, 'RESTAURANTS');
INSERT INTO CHURCH(CHURCH_ID, CHURCH_NAME) VALUES (287, 'BEST CHURCH EVER');
INSERT INTO PRODUCT_TYPES(PRODUCT_TYPE_ID, PT_NAME) VALUES (01, 'TEA');
INSERT INTO PRODUCT_TYPES(PRODUCT_TYPE_ID, PT_NAME) VALUES (02, 'COOKIES');
INSERT INTO PRODUCT_TYPES(PRODUCT_TYPE_ID, PT_NAME) VALUES (03, 'SNACKS');
INSERT INTO PRODUCT_TYPES(PRODUCT_TYPE_ID, PT_NAME) VALUES (04, 'BOOKS');
INSERT INTO PRODUCT_TYPES(PRODUCT_TYPE_ID, PT_NAME) VALUES (05, 'CLOTHES');
INSERT INTO PRODUCT_TYPES(PRODUCT_TYPE_ID, PT_NAME) VALUES (06, 'OFFICE SUPPLIES');
INSERT INTO PRODUCT_TYPES(PRODUCT_TYPE_ID, PT_NAME) VALUES (07, 'MEALS');
INSERT INTO PRODUCT_TYPES(PRODUCT_TYPE_ID, PT_NAME) VALUES (08, 'ACCESSORIES');
INSERT INTO PRODUCT_TYPES(PRODUCT_TYPE_ID, PT_NAME) VALUES (09, 'LUGGAGE');
INSERT INTO VENDOR(VENDOR_ID, VENDOR_NAME) VALUES (10, 'STAPLES');
INSERT INTO VENDOR(VENDOR_ID, VENDOR_NAME) VALUES (11, 'MCDONALD WHOLESALE');
INSERT INTO VENDOR(VENDOR_ID, VENDOR_NAME) VALUES (12, 'BARNEYS');
INSERT INTO VENDOR(VENDOR_ID, VENDOR_NAME) VALUES (13, 'SALLY NUNSEN');
INSERT INTO VENDOR(VENDOR_ID, VENDOR_NAME) VALUES (14, 'EDWARD MONKERSON');
INSERT INTO NUN(NUN_ID, N_FIRST_NAME, N_LAST_NAME, N_VENDOR_ID) VALUES (15, 'SALLY', 'NUNSEN', 13);
INSERT INTO NUN(NUN_ID, N_FIRST_NAME, N_LAST_NAME) VALUES (16, 'CARLEEN', 'CABELSON');
INSERT INTO NUN(NUN_ID, N_FIRST_NAME, N_LAST_NAME) VALUES (17, 'GLENDA', 'GILBERT');
INSERT INTO EMPLOYEE(EMPLOYEE_ID, E_FIRST_NAME, E_LAST_NAME, HOURLY_RATE) VALUES (18, 'ROSE', 'PETERSON', 15.25);
INSERT INTO EMPLOYEE(EMPLOYEE_ID, E_FIRST_NAME, E_LAST_NAME, HOURLY_RATE) VALUES (19, 'HANNAH', 'SOBRINSKI', 12.50);
INSERT INTO EMPLOYEE(EMPLOYEE_ID, E_FIRST_NAME, E_LAST_NAME, HOURLY_RATE) VALUES (20, 'MITCH', 'HILBERT', 14.75);
INSERT INTO EMPLOYEE(EMPLOYEE_ID, E_FIRST_NAME, E_LAST_NAME, HOURLY_RATE) VALUES (21, 'JOE', 'PLANK', 13.00);
INSERT INTO EMPLOYEE(EMPLOYEE_ID, E_FIRST_NAME, E_LAST_NAME, HOURLY_RATE) VALUES (22, 'EDWARD', 'MONKERSON', 20.50);
INSERT INTO MONK(MONK_ID, M_FIRST_NAME, M_LAST_NAME, M_VENDOR_ID) VALUES (23, 'EDWARD', 'MONKERSON', 14);
INSERT INTO MONK(MONK_ID, M_FIRST_NAME, M_LAST_NAME) VALUES (24, 'JOE', 'PLANK');
INSERT INTO MONK(MONK_ID, M_FIRST_NAME, M_LAST_NAME) VALUES (25, 'RICHARD', 'NIXON');
INSERT INTO MONK(MONK_ID, M_FIRST_NAME, M_LAST_NAME) VALUES (26, 'JOSEPH', 'BIDEN');
INSERT INTO MONK(MONK_ID, M_FIRST_NAME, M_LAST_NAME) VALUES (27, 'JOHN', 'SMITH');
INSERT INTO MONK(MONK_ID, M_FIRST_NAME, M_LAST_NAME) VALUES (28, 'GEORGE', 'WASHINGTON');
INSERT INTO MONK(MONK_ID, M_FIRST_NAME, M_LAST_NAME) VALUES (29, 'WINSTON', 'CHURCHILL');
INSERT INTO MONK(MONK_ID, M_FIRST_NAME, M_LAST_NAME) VALUES (30, 'DAVID', 'BECKHAM');
INSERT INTO MONK(MONK_ID, M_FIRST_NAME, M_LAST_NAME) VALUES (31, 'JERAMY', 'CARD');
INSERT INTO MONK(MONK_ID, M_FIRST_NAME, M_LAST_NAME) VALUES (32, 'BILL', 'BELLAMY');
INSERT INTO MONK(MONK_ID, M_FIRST_NAME, M_LAST_NAME) VALUES (33, 'RYAN', 'TUCKER');
INSERT INTO MONK(MONK_ID, M_FIRST_NAME, M_LAST_NAME) VALUES (34, 'RINGO', 'STARR');
INSERT INTO MONK(MONK_ID, M_FIRST_NAME, M_LAST_NAME) VALUES (35, 'BRUCE', 'WAYNE');
INSERT INTO MONK(MONK_ID, M_FIRST_NAME, M_LAST_NAME) VALUES (36, 'DICK', 'VAN DYKE');
INSERT INTO MONK(MONK_ID, M_FIRST_NAME, M_LAST_NAME) VALUES (37, 'JAMES', 'DEAN');
INSERT INTO SHOPS(SHOP_ID, SHOP_NAME, S_SHOP_TYPE_ID) VALUES (38, 'MONASTIC SHOP', 123);
INSERT INTO SHOPS(SHOP_ID, SHOP_NAME, S_SHOP_TYPE_ID) VALUES (39, 'GRANGE RESTAURANT', 456);
INSERT INTO SHOPS(SHOP_ID, SHOP_NAME, S_SHOP_TYPE_ID) VALUES (40, 'GIFT SHOP', 123);
INSERT INTO SHOPS(SHOP_ID, SHOP_NAME, S_SHOP_TYPE_ID) VALUES (41, 'BOOK SHOP', 123);
INSERT INTO GUEST_HOUSES(HOUSE_ID, ROOM_NUMBER, COST) VALUES (42, 01, 60.00);
INSERT INTO GUEST_HOUSES(HOUSE_ID, ROOM_NUMBER, COST) VALUES (43, 02, 60.00);
INSERT INTO GUEST_HOUSES(HOUSE_ID, ROOM_NUMBER, COST) VALUES (44, 03, 60.00);
INSERT INTO GUEST_HOUSES(HOUSE_ID, ROOM_NUMBER, COST) VALUES (45, 04, 60.00);
INSERT INTO GUEST_HOUSES(HOUSE_ID, ROOM_NUMBER, COST) VALUES (46, 05, 60.00);
INSERT INTO GUEST_HOUSES(HOUSE_ID, ROOM_NUMBER, COST) VALUES (47, 06, 60.00);
INSERT INTO GUEST_HOUSES(HOUSE_ID, ROOM_NUMBER, COST) VALUES (48, 07, 60.00);
INSERT INTO GUEST_HOUSES(HOUSE_ID, ROOM_NUMBER, COST) VALUES (49, 08, 60.00);
INSERT INTO GUEST_HOUSES(HOUSE_ID, ROOM_NUMBER, COST) VALUES (50, 09, 60.00);
INSERT INTO GUEST_HOUSES(HOUSE_ID, ROOM_NUMBER, COST) VALUES (51, 10, 60.00);
INSERT INTO GUEST_HOUSES(HOUSE_ID, ROOM_NUMBER, COST) VALUES (52, 11, 60.00);
INSERT INTO GUEST_HOUSES(HOUSE_ID, ROOM_NUMBER, COST) VALUES (53, 12, 60.00);
INSERT INTO VISITOR(VISITOR_ID, FIRST_NAME, LAST_NAME, ADDRESS, CITY, V_STATE_ID, ZIP) VALUES (54, 'ERICA', 'CARD', '123 MAIN ST', 'SPRINGFIELD', 'OR', 97477);
INSERT INTO VISITOR(VISITOR_ID, FIRST_NAME, LAST_NAME, ADDRESS, CITY, V_STATE_ID, ZIP) VALUES (55, 'RICK', 'JAMES', '567 ALABASTER LN', 'PORT ORCHARD', 'WA', 99567);
INSERT INTO VISITOR(VISITOR_ID, FIRST_NAME, LAST_NAME, ADDRESS, CITY, V_STATE_ID, ZIP) VALUES (56, 'SANTA', 'CLAUSE', '248 NORTH POLE LOOP', 'NORTH POLE', 'AK', 57489);
INSERT INTO VISITOR(VISITOR_ID, FIRST_NAME, LAST_NAME, ADDRESS, CITY, V_STATE_ID, ZIP) VALUES (57, 'HARRY', 'HENDERSON', '23185 10TH AVE', 'NEW YORK', 'NY', 01587);
INSERT INTO VISITOR(VISITOR_ID, FIRST_NAME, LAST_NAME, ADDRESS, CITY, V_STATE_ID, ZIP) VALUES (58, 'CHRIS', 'SWIRES', '5165 YOLANDA RD', 'GREENBOUGH', 'AL', 25478);
INSERT INTO VISITOR(VISITOR_ID, FIRST_NAME, LAST_NAME, ADDRESS, CITY, V_STATE_ID, ZIP) VALUES (59, 'MICHELE', 'WURGES', '8456 ANCHOR WAY', 'POULSBO', 'WA', 92475);
INSERT INTO VISITOR(VISITOR_ID, FIRST_NAME, LAST_NAME, ADDRESS, CITY, V_STATE_ID, ZIP) VALUES (60, 'MONICA', 'ROSENKRANCE', '3547 HAYDEN BRIDGE DR', 'SPRINGFIELD', 'OR', 97477);
INSERT INTO VISITOR(VISITOR_ID, FIRST_NAME, LAST_NAME, ADDRESS, CITY, V_STATE_ID, ZIP) VALUES (61, 'ALLEN', 'MASTERS', '14785 MEADOW LARK RD', 'BOISE', 'ID', 84222);
INSERT INTO VISITOR(VISITOR_ID, FIRST_NAME, LAST_NAME, ADDRESS, CITY, V_STATE_ID, ZIP) VALUES (62, 'MICHAEL', 'JACKSON', '61002 NEVERLAND ST', 'SANTA CRUZ', 'CA', 99854);
INSERT INTO PRODUCTS(PRODUCT_ID, P_VENDOR_ID, P_NAME, P_PRODUCT_TYPE_ID) VALUES (63, 10, 'PENS', 06);
INSERT INTO PRODUCTS(PRODUCT_ID, P_VENDOR_ID, P_NAME, P_PRODUCT_TYPE_ID) VALUES (64, 11, 'OATMEAL RAISIN', 02);
INSERT INTO PRODUCTS(PRODUCT_ID, P_VENDOR_ID, P_NAME, P_PRODUCT_TYPE_ID) VALUES (65, 12, 'T-SHIRT', 05);
INSERT INTO PRODUCTS(PRODUCT_ID, P_VENDOR_ID, P_NAME, P_PRODUCT_TYPE_ID) VALUES (66, 13, 'RED SCARF', 08);
INSERT INTO PRODUCTS(PRODUCT_ID, P_VENDOR_ID, P_NAME, P_PRODUCT_TYPE_ID) VALUES (67, 14, 'HAND SEWN BAG', 09);
INSERT INTO PRODUCTS(PRODUCT_ID, P_VENDOR_ID, P_NAME, P_PRODUCT_TYPE_ID) VALUES (68, 11, 'STEAK and EGGS', 07);
INSERT INTO SCHEDULE(SCHEDULE_ID, S_EMPLOYEE_ID, S_SHOP_ID, START_DATE, END_DATE, START_TIME, END_TIME) VALUES (69, 18, 39, TO_DATE('06/01/2019','MM/DD/YYYY'), TO_DATE('06/08/2019','MM/DD/YYYY'), 08.00, 21.00);
INSERT INTO SCHEDULE(SCHEDULE_ID, S_EMPLOYEE_ID, S_SHOP_ID, START_DATE, END_DATE, START_TIME, END_TIME) VALUES (70, 19, 40, TO_DATE('06/01/2019','MM/DD/YYYY'), TO_DATE('06/08/2019','MM/DD/YYYY'), 08.00, 21.00);
INSERT INTO SCHEDULE(SCHEDULE_ID, S_EMPLOYEE_ID, S_SHOP_ID, START_DATE, END_DATE, START_TIME, END_TIME) VALUES (71, 22, 38, TO_DATE('06/01/2019','MM/DD/YYYY'), TO_DATE('06/08/2019','MM/DD/YYYY'), 08.00, 21.00);
INSERT INTO SCHEDULE(SCHEDULE_ID, S_EMPLOYEE_ID, S_SHOP_ID, START_DATE, END_DATE, START_TIME, END_TIME) VALUES (72, 21, 41, TO_DATE('06/01/2019','MM/DD/YYYY'), TO_DATE('06/08/2019','MM/DD/YYYY'), 08.00, 21.00);
INSERT INTO PURCHASES(PURCHASE_ID, DATE_OF_PURCHASE, P_VISITOR_ID, P_SHOP_ID) VALUES (73, TO_DATE('06/01/2019','MM/DD/YYYY'), 54, 40);
INSERT INTO PURCHASES(PURCHASE_ID, DATE_OF_PURCHASE, P_VISITOR_ID, P_SHOP_ID) VALUES (74, TO_DATE('06/01/2019','MM/DD/YYYY'), 54, 38);
INSERT INTO PURCHASES(PURCHASE_ID, DATE_OF_PURCHASE, P_VISITOR_ID, P_SHOP_ID) VALUES (75, TO_DATE('07/15/2019','MM/DD/YYYY'), 59, 39);
INSERT INTO PURCHASES(PURCHASE_ID, DATE_OF_PURCHASE, P_VISITOR_ID, P_SHOP_ID) VALUES (76, TO_DATE('08/01/2019','MM/DD/YYYY'), 56, 40);
INSERT INTO LINE_ITEM(LINE_ITEM_ID, L_PURCHASE_ID, L_PRODUCT_ID, QUANTITY, PRICE) VALUES (77, 73, 63, 5, 3.00);
INSERT INTO LINE_ITEM(LINE_ITEM_ID, L_PURCHASE_ID, L_PRODUCT_ID, QUANTITY, PRICE) VALUES (78, 74, 67, 2, 25.50);
INSERT INTO LINE_ITEM(LINE_ITEM_ID, L_PURCHASE_ID, L_PRODUCT_ID, QUANTITY, PRICE) VALUES (79, 75, 68, 1, 12.25);
INSERT INTO LINE_ITEM(LINE_ITEM_ID, L_PURCHASE_ID, L_PRODUCT_ID, QUANTITY, PRICE) VALUES (80, 76, 65, 3, 13.75);
INSERT INTO INVENTORY(INVENTORY_ID, I_PRODUCT_ID, QUANTITY_ON_HAND, QUANTITY_SOLD, QUANTITY_PURCHASED, COST) VALUES (81, 63, 25, 5, 0, 1.15);
INSERT INTO INVENTORY(INVENTORY_ID, I_PRODUCT_ID, QUANTITY_ON_HAND, QUANTITY_SOLD, QUANTITY_PURCHASED, COST) VALUES (82, 64, 12, 0, 0, .75);
INSERT INTO INVENTORY(INVENTORY_ID, I_PRODUCT_ID, QUANTITY_ON_HAND, QUANTITY_SOLD, QUANTITY_PURCHASED, COST) VALUES (83, 65, 32, 3, 0, 5.00);
INSERT INTO INVENTORY(INVENTORY_ID, I_PRODUCT_ID, QUANTITY_ON_HAND, QUANTITY_SOLD, QUANTITY_PURCHASED, COST) VALUES (84, 66, 11, 0, 0, 7.00);
INSERT INTO INVENTORY(INVENTORY_ID, I_PRODUCT_ID, QUANTITY_ON_HAND, QUANTITY_SOLD, QUANTITY_PURCHASED, COST) VALUES (85, 67, 65, 2, 0, 15.00);
INSERT INTO INVENTORY(INVENTORY_ID, I_PRODUCT_ID, QUANTITY_ON_HAND, QUANTITY_SOLD, QUANTITY_PURCHASED, COST) VALUES (86, 68, 12, 1, 0, 7.00);
INSERT INTO RESERVATION(RESERVATION_ID, R_VISITOR_ID, R_HOUSE_ID, ARRIVAL_DATE, DEPARTURE_DATE, R_MONK_ID) VALUES (87, 54, 42, TO_DATE('06/01/2019','MM/DD/YYYY'), TO_DATE('06/14/2019','MM/DD/YYYY'), 26);
INSERT INTO RESERVATION(RESERVATION_ID, R_VISITOR_ID, R_HOUSE_ID, ARRIVAL_DATE, DEPARTURE_DATE, R_MONK_ID) VALUES (88, 58, 43, TO_DATE('06/15/2019','MM/DD/YYYY'), TO_DATE('06/30/2019','MM/DD/YYYY'), 27);
INSERT INTO RESERVATION(RESERVATION_ID, R_VISITOR_ID, R_HOUSE_ID, ARRIVAL_DATE, DEPARTURE_DATE, R_MONK_ID) VALUES (89, 57, 44, TO_DATE('07/25/2019','MM/DD/YYYY'), TO_DATE('07/30/2019','MM/DD/YYYY'), 28);
INSERT INTO RESERVATION(RESERVATION_ID, R_VISITOR_ID, R_HOUSE_ID, ARRIVAL_DATE, DEPARTURE_DATE, R_MONK_ID) VALUES (90, 59, 45, TO_DATE('07/01/2019','MM/DD/YYYY'), TO_DATE('07/16/2019','MM/DD/YYYY'), 29);
INSERT INTO RESERVATION(RESERVATION_ID, R_VISITOR_ID, R_HOUSE_ID, ARRIVAL_DATE, DEPARTURE_DATE, R_MONK_ID) VALUES (91, 56, 46, TO_DATE('08/01/2019','MM/DD/YYYY'), TO_DATE('08/10/2019','MM/DD/YYYY'), 30);
INSERT INTO RESERVATION(RESERVATION_ID, R_VISITOR_ID, R_HOUSE_ID, ARRIVAL_DATE, DEPARTURE_DATE, R_MONK_ID) VALUES (92, 54, 47, TO_DATE('07/01/2019','MM/DD/YYYY'), TO_DATE('07/30/2019','MM/DD/YYYY'), 31);
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (92, 87, TO_DATE('06/01/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (94, 87, TO_DATE('06/02/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (95, 87, TO_DATE('06/03/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (96, 87, TO_DATE('06/04/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (97, 87, TO_DATE('06/05/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (98, 87, TO_DATE('06/06/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (99, 87, TO_DATE('06/07/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (100, 87, TO_DATE('06/08/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (101, 87, TO_DATE('06/09/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (102, 87, TO_DATE('06/10/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (103, 87, TO_DATE('06/11/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (104, 87, TO_DATE('06/12/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (105, 87, TO_DATE('06/13/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (106, 88, TO_DATE('06/15/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (107, 88, TO_DATE('06/16/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (108, 88, TO_DATE('06/17/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (109, 88, TO_DATE('06/18/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (110, 88, TO_DATE('06/19/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (111, 88, TO_DATE('06/20/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (112, 88, TO_DATE('06/21/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (113, 88, TO_DATE('06/22/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (114, 88, TO_DATE('06/23/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (115, 88, TO_DATE('06/24/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (116, 88, TO_DATE('06/25/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (117, 88, TO_DATE('06/26/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (118, 88, TO_DATE('06/27/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (119, 88, TO_DATE('06/28/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (120, 88, TO_DATE('06/29/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (121, 89, TO_DATE('07/25/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (122, 89, TO_DATE('07/26/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (123, 89, TO_DATE('07/27/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (124, 89, TO_DATE('07/28/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (125, 89, TO_DATE('07/29/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (126, 90, TO_DATE('07/01/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (127, 90, TO_DATE('07/02/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (128, 90, TO_DATE('07/03/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (129, 90, TO_DATE('07/04/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (130, 90, TO_DATE('07/05/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (131, 90, TO_DATE('07/06/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (132, 90, TO_DATE('07/07/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (133, 90, TO_DATE('07/08/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (134, 90, TO_DATE('07/09/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (135, 90, TO_DATE('07/10/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (136, 90, TO_DATE('07/11/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (137, 90, TO_DATE('07/12/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (138, 90, TO_DATE('07/13/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (139, 90, TO_DATE('07/14/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (140, 91, TO_DATE('08/01/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (141, 91, TO_DATE('08/02/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (142, 91, TO_DATE('08/03/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (143, 91, TO_DATE('08/04/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (144, 91, TO_DATE('08/05/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (145, 91, TO_DATE('08/06/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (146, 91, TO_DATE('08/07/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (147, 91, TO_DATE('08/08/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (148, 91, TO_DATE('08/09/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (149, 92, TO_DATE('07/01/2019','MM/DD/YYYY'));
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (150, 92, TO_DATE('07/02/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (151, 92, TO_DATE('07/03/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (152, 92, TO_DATE('07/04/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (153, 92, TO_DATE('07/05/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (154, 92, TO_DATE('07/06/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (155, 92, TO_DATE('07/07/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (156, 92, TO_DATE('07/08/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (157, 92, TO_DATE('07/09/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (158, 92, TO_DATE('07/10/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (159, 92, TO_DATE('07/11/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (160, 92, TO_DATE('07/12/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (161, 92, TO_DATE('07/13/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (162, 92, TO_DATE('07/14/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (163, 92, TO_DATE('07/15/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (164, 92, TO_DATE('07/16/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (165, 92, TO_DATE('07/17/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (166, 92, TO_DATE('07/18/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (167, 92, TO_DATE('07/19/2019','MM/DD/YYYY'));  
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (168, 92, TO_DATE('07/20/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (169, 92, TO_DATE('07/21/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (170, 92, TO_DATE('07/22/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (171, 92, TO_DATE('07/23/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (172, 92, TO_DATE('07/24/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (173, 92, TO_DATE('07/25/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (174, 92, TO_DATE('07/26/2019','MM/DD/YYYY')); 
INSERT INTO VACANCY(VACANCY_ID, V_RESERVATION_ID, BOOKED_DATE) VALUES (175, 92, TO_DATE('07/27/2019','MM/DD/YYYY')); 

1 个答案:

答案 0 :(得分:0)

好像您的过程可以使用来更新INVENTORY

update inventory
set    quantity_on_hand = quantity_on_hand - p_quantity
     , quantity_sold = quantity_sold + p_quantity
     , quantity_purchased = quantity_purchased + p_quantity
where  i_product_purchased = p_product_id

p_product_idp_quantity作为参数传递。

我不确定quantity_soldquantity_purchased之间有什么区别。

如果您想在PURCHASES中记录购买的商品,则需要了解访客和商店,但这也许是另一个过程的任务。

我不确定僧侣,修女和教堂与这个问题有什么关系。