Advertisement
Guest User

Data insertion code

a guest
Aug 31st, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 8.97 KB | None | 0 0
  1. DECLARE
  2.   numberOfInvoices NUMBER;
  3.   numberOfReservations NUMBER;
  4.   numberOfRooms NUMBER;
  5.   numberOfCustomers NUMBER;
  6.   numberOfBranches NUMBER;
  7. BEGIN
  8.   SELECT COUNT(*) INTO numberOfInvoices
  9.   FROM invoice_table;
  10.   SELECT COUNT(*) INTO numberOfReservations
  11.   FROM reservation_table;
  12.   SELECT COUNT(*) INTO numberOfRooms
  13.   FROM room_table;
  14.   SELECT COUNT(*) INTO numberOfCustomers
  15.   FROM customer_table;
  16.   SELECT COUNT(*) INTO numberOfBranches
  17.   FROM branch_table;
  18.  
  19.  
  20.  
  21. /*Deleting in order in seperate loops so child dependencies don't break*/
  22.   FOR i IN 1 .. numberOfInvoices LOOP
  23.     DELETE FROM invoice_table
  24.     WHERE res_id = i;
  25.   END LOOP;
  26.   FOR i IN 1 .. numberOfReservations LOOP
  27.     DELETE FROM reservation_table
  28.     WHERE res_id = i;
  29.   END LOOP;
  30.   FOR i IN 1 .. numberOfRooms LOOP
  31.     DELETE FROM room_table
  32.     WHERE room_id = i;
  33.   END LOOP;
  34.   FOR i IN 1 .. numberOfCustomers LOOP
  35.     DELETE FROM customer_table
  36.     WHERE cust_id = i;
  37.   END LOOP;
  38.   FOR i IN 1 .. numberOfBranches LOOP
  39.     DELETE FROM branch_table
  40.     WHERE branch_id = i;
  41.   END LOOP;
  42.  
  43. /*Inserting all the data*/
  44.   INSERT INTO branch_table (branch_id, branch_name, branch_city, branch_email, branch_phone, branch_address)
  45.   VALUES(1, 'A-Hotels', 'Auckland', 'hotelAuck@gmail.com', 098775667, '231, Pukeiti Rd');
  46.   INSERT INTO branch_table (branch_id, branch_name, branch_city, branch_email, branch_phone, branch_address)
  47.   VALUES(2, 'Church Hotels', 'Christchurch', 'hotelChurch@gmail.com', 098775666, '135, Hawdon St');
  48.   INSERT INTO branch_table (branch_id, branch_name, branch_city, branch_email, branch_phone, branch_address)
  49.   VALUES(3, 'Rocky Hotels', 'Rotorua', 'hotelRot@gmail.com', 098775665, '15, McKenzie Rd');
  50.   INSERT INTO branch_table (branch_id, branch_name, branch_city, branch_email, branch_phone, branch_address)
  51.   VALUES(4, 'Windy Hotels', 'Wellington', 'hotelWell@gmail.com', 098775664, '115, Fiona Grove');
  52.   INSERT INTO branch_table (branch_id, branch_name, branch_city, branch_email, branch_phone, branch_address)
  53.   VALUES(5, 'Lower Hut', 'Invercargill', 'hotelInv@gmail.com', 098775663, '177, Preston Street');
  54.  
  55.   INSERT INTO customer_table (cust_id, cust_fname, cust_lname, cust_address, cust_homephone, cust_mobilephone, cust_email, cust_fax)
  56.   VALUES(1, 'Eleanor', 'Alcaraz', '57, Webster Ave', 0261508439, 273569256, 'EA@gmail.com', NULL);
  57.   INSERT INTO customer_table (cust_id, cust_fname, cust_lname, cust_address, cust_homephone, cust_mobilephone, cust_email, cust_fax)
  58.   VALUES(2, 'Harry', 'Potter', '9-3/4 Place Ave', 23423454, 23234234, 'harryPotterWizard@gmail.com', NULL);
  59.   INSERT INTO customer_table (cust_id, cust_fname, cust_lname, cust_address, cust_homephone, cust_mobilephone, cust_email, cust_fax)
  60.   VALUES(3, 'Johnn', 'Pwertwy', '8th Bonnerstine Place', 234234234, 234234266, 'magicmagickek@gmail.com', NULL);
  61.   INSERT INTO customer_table (cust_id, cust_fname, cust_lname, cust_address, cust_homephone, cust_mobilephone, cust_email, cust_fax)
  62.   VALUES(4, 'Katty', 'Lola', '6th Maori Rd', 21342344, 123123333, 'Aeoteroa@gmail.com', NULL);
  63.   INSERT INTO customer_table (cust_id, cust_fname, cust_lname, cust_address, cust_homephone, cust_mobilephone, cust_email, cust_fax)
  64.   VALUES(5, 'Terry', 'Utan', '5930 Jackson Rd', 2342344, 55556566, 'Utanterry@gmail.com', NULL);
  65.  
  66.   INSERT INTO room_table (room_id, branch_id, room_type, room_desc, bathroom_count, bed_count, price)
  67.   VALUES(1, 5, 'PENTHOUSE', 'Great room with stunning vista', 3, 3, 98);
  68.   INSERT INTO room_table (room_id, branch_id, room_type, room_desc, bathroom_count, bed_count, price)
  69.   VALUES(2, 4, 'KING', 'Honeymoon Room suited for kings', 2, 4, 67);
  70.   INSERT INTO room_table (room_id, branch_id, room_type, room_desc, bathroom_count, bed_count, price)
  71.   VALUES(3, 2, 'SMALL', 'A small quiet place to stay', 1, 1, 25);
  72.   INSERT INTO room_table (room_id, branch_id, room_type, room_desc, bathroom_count, bed_count, price)
  73.   VALUES(4, 3, 'QUEEN', 'View of the ocean', 2, 2, 45);
  74.   INSERT INTO room_table (room_id, branch_id, room_type, room_desc, bathroom_count, bed_count, price)
  75.   VALUES(5, 4, 'PENTHOUSE', 'Increadable view of the ocean', 2, 4, 105);
  76.   INSERT INTO room_table (room_id, branch_id, room_type, room_desc, bathroom_count, bed_count, price)
  77.   VALUES(6, 1, 'SMALL', 'Small window room', 1, 1, 23);
  78.   INSERT INTO room_table (room_id, branch_id, room_type, room_desc, bathroom_count, bed_count, price)
  79.   VALUES(7, 1, 'SMALL', 'No windows, simply a room', 1, 1, 14);
  80.   INSERT INTO room_table (room_id, branch_id, room_type, room_desc, bathroom_count, bed_count, price)
  81.   VALUES(8, 1, 'LARGE', 'Large deck that opens out to wellington', 2, 2, 56);
  82.   INSERT INTO room_table (room_id, branch_id, room_type, room_desc, bathroom_count, bed_count, price)
  83.   VALUES(9, 2, 'SMALL', 'Christchurchs best room for cheap', 1, 1, 10);
  84.   INSERT INTO room_table (room_id, branch_id, room_type, room_desc, bathroom_count, bed_count, price)
  85.   VALUES(10, 3, 'MEDIUM', 'Increadable view of Whakapapa Ski fields', 1, 3, 45);
  86.   INSERT INTO room_table (room_id, branch_id, room_type, room_desc, bathroom_count, bed_count, price)
  87.   VALUES(11, 2, 'VISTA', 'Sits right next to the church', 3, 5, 123);
  88.   INSERT INTO room_table (room_id, branch_id, room_type, room_desc, bathroom_count, bed_count, price)
  89.   VALUES(12, 3, 'PENTHOUSE', 'You can practically ski out from your room', 6, 12, 280);
  90.   INSERT INTO room_table (room_id, branch_id, room_type, room_desc, bathroom_count, bed_count, price)
  91.   VALUES(13, 1, 'PENTHOUSE', 'A-Star room with a view of the sky tower', 4, 4, 190);
  92.   INSERT INTO room_table (room_id, branch_id, room_type, room_desc, bathroom_count, bed_count, price)
  93.   VALUES(14, 2, 'PENTHOUSE', 'Bueatiful view of the mountain ranges', 3, 7, 120);
  94.   INSERT INTO room_table (room_id, branch_id, room_type, room_desc, bathroom_count, bed_count, price)
  95.   VALUES(15, 5, 'KING', 'A room suited for a king and his queen and with a cheap price tag', 2, 2, 67);
  96.   INSERT INTO room_table (room_id, branch_id, room_type, room_desc, bathroom_count, bed_count, price)
  97.   VALUES(16, 5, 'VISTA', 'Deck outside that leads to a fantastic view', 2, 13, 110);
  98.   INSERT INTO room_table (room_id, branch_id, room_type, room_desc, bathroom_count, bed_count, price)
  99.   VALUES(17, 3, 'QUEEN', 'A queen and her self could spend an eternity here', 1, 1, 90);
  100.  
  101.   INSERT INTO reservation_table (res_id, cust_id, cust_fname, cust_lname, room_id, room_type, start_date, end_date)
  102.   VALUES(1, 1, (SELECT cust_fname FROM customer_table WHERE cust_id = 1),
  103.                (SELECT cust_lname FROM customer_table WHERE cust_id = 1), 1,
  104.                (SELECT room_type FROM room_table WHERE room_id = 1), '12-07-2018', '30-08-2018');
  105.   INSERT INTO reservation_table (res_id, cust_id, cust_fname, cust_lname, room_id, room_type, start_date, end_date)
  106.   VALUES(2, 2, (SELECT cust_fname FROM customer_table WHERE cust_id = 2),
  107.                (SELECT cust_lname FROM customer_table WHERE cust_id = 2), 2,
  108.                (SELECT room_type FROM room_table WHERE room_id = 2), '4-07-2017', '30-03-2018');
  109.   INSERT INTO reservation_table (res_id, cust_id, cust_fname, cust_lname, room_id, room_type, start_date, end_date)
  110.   VALUES(3, 3, (SELECT cust_fname FROM customer_table WHERE cust_id = 3),
  111.                (SELECT cust_lname FROM customer_table WHERE cust_id = 3), 3,
  112.                (SELECT room_type FROM room_table WHERE room_id = 3), '5-09-1999', '1-10-2018');
  113.   INSERT INTO reservation_table (res_id, cust_id, cust_fname, cust_lname, room_id, room_type, start_date, end_date)
  114.   VALUES(4, 4, (SELECT cust_fname FROM customer_table WHERE cust_id = 4),
  115.                (SELECT cust_lname FROM customer_table WHERE cust_id = 4), 4,
  116.                (SELECT room_type FROM room_table WHERE room_id = 4), '5-02-2018', '6-02-2018');
  117.   INSERT INTO reservation_table (res_id, cust_id, cust_fname, cust_lname, room_id, room_type, start_date, end_date)
  118.   VALUES(5, 5, (SELECT cust_fname FROM customer_table WHERE cust_id = 5),
  119.                (SELECT cust_lname FROM customer_table WHERE cust_id = 5), 1,
  120.                (SELECT room_type FROM room_table WHERE room_id = 1), '12-05-2018', '30-08-2018');
  121.  
  122. /*Inseting into invoice table loop*/
  123.   FOR i IN 1 .. numberOfReservations LOOP
  124.     INSERT INTO invoice_table (res_id, room_id, cust_fname, cust_lname, price, days_stayed, bill)
  125.     VALUES((SELECT res_id FROM reservation_table WHERE res_id = i),
  126.         (SELECT room_id FROM reservation_table WHERE res_id = i),
  127.         (SELECT cust_fname FROM reservation_table WHERE res_id = i),
  128.         (SELECT cust_lname FROM reservation_table WHERE res_id = i),
  129.         (SELECT price FROM room_table roo, reservation_table res
  130.           WHERE res.res_id = i
  131.           AND res.room_id = roo.room_id),
  132.         (SELECT (end_date-start_date)
  133.           FROM reservation_table
  134.           WHERE res_id = i),
  135.         (SELECT (roo.price*(res.end_date-res.start_date))
  136.           FROM room_table roo, reservation_table res
  137.           WHERE roo.room_id = res.room_id
  138.           AND res.res_id = i));
  139.   END LOOP;
  140.  
  141. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement