Você está na página 1de 22

Oracle Development

Table of Contents
Table bb_shoper:..............................................................................................................................3
Screen capture of BB_SHOPER :....................................................................................................4
TABLE BB_BASKET:....................................................................................................................4
Screen capture of BB_BASKET :...................................................................................................7
Question 1........................................................................................................................................7
Solution:.......................................................................................................................................7
OUTPUT:.........................................................................................................................................9
Question 2......................................................................................................................................12
Solution:.....................................................................................................................................12
OUTPUT:.......................................................................................................................................15
Question 3......................................................................................................................................15
Solution:.....................................................................................................................................15
Question 4......................................................................................................................................18
Solution:.....................................................................................................................................18
OUTPUT:...................................................................................................................................21
Reference List................................................................................................................................22

Table bb_shoper:
CREATE TABLE BB_SHOPER(
IDSHOPPER int NOT NULL PRIMARY KEY,
FIRSTNAME VARCHAR2(15),
LASTNAME VARCHAR2(20),
ADDRESS VARCHAR2(40),
CITY VARCHAR2(20),
STATE CHAR(2),
ZIPCODE VARCHAR2(15),
PHONE VARCHAR2(10),
FAX VARCHAR2(10),
EMAIL VARCHAR2(25),
USERNAME VARCHAR2(8),
PASSWORD VARCHAR2(8),
COOKIE INT,
DTENTERED DATE,
PROVINCE VARCHAR2(15),
COUNTRY VARCHAR2(15),
3

PROMO CHAR(1)
);

Screen capture of BB_SHOPER :

TABLE BB_BASKET:
CREATE TABLE BB_BASKET(
IDBASKET INT NOT NULL PRIMARY KEY,
QUANTITY NUMBER(2),
IDSHOPPER NUMBER(4),
ORDERPLACED NUMBER(2),
SUBTOTAL NUMBER(7,2),
TOTAL NUMBER(7,2),

SHIPPING NUMBER(5,2),
TAX NUMBER(5,2),
DTCREATED DATE,
PROMO NUMBER(2),
SHIPFIRSTNAME VARCHAR2(10),
SHIPLASTNAME VARCHAR2(10),
SHIPADDRESS VARCHAR2(40),
SHIPCITY VARCHAR2(20),
SHIPSTATE VARCHAR2(2),
SHIPZIPCODE VARCHAR2(15),
SHIPPHONE VARCHAR2(10),
SHIPFAX VARCHAR2(10),
SHIPEMAIL VARCHAR2(25),
BILLFIRSTNAME VARCHAR2(10),
BILLLASTNAME VARCHAR2(20),
BILLADDRESS VARCHAR2(40),
BILLCITY VARCHAR2(2),
BILLSTATE VARCHAR2(20),
BILLZIPCODE VARCHAR2(15),
BILLPHONE VARCHAR2(15),
BILLFAX VARCHAR2(10),
5

BILLEMAIL VARCHAR2(25),
DTORDERED DATE,
SHIPPROVIENCE VARCHAR2(20),
SHIPCOUNTRY VARCHAR2(20),
BILLPROVINCE VARCHAR2(20),
BILLCOUNTRY VARCHAR2(20),
CARDTYPE CHAR(1),
CARDNUMBER VARCHAR2(20),
EXPMONTH CHAR(2),
EXPYEAR CHAR(4),
CARDNAME VARCHAR2(25),
SHIPBILL CHAR(1),
SHIPFLAG CHAR(1)
);

Screen capture of BB_BASKET :

Question 1
Solution:
DECLARE
a char(1);
n number(2) :=0;
x char(1);
BEGIN
DBMS_OUTPUT.PUT_LINE('ENTER YOUR CHOICE:');
a:=:x;
while n<1 Loop

CASE a

WHEN 'A' THEN DBMS_OUTPUT.PUT_LINE('Please proceed to Level 1');

WHEN 'B' THEN DBMS_OUTPUT.PUT_LINE('Please proceed to Level 2');

WHEN 'C' THEN DBMS_OUTPUT.PUT_LINE('Please proceed to Level 2');

WHEN 'D' THEN DBMS_OUTPUT.PUT_LINE('Please proceed to Level 3');

ELSE DBMS_OUTPUT.PUT_LINE('Invalid Entry');


END CASE;
n := n + 1;
END LOOP;
END;
/

OUTPUT:

10

11

Question 2
Solution:
DECLARE
a number(1);
12

count number(10);
c_bsk bb_basket1.idbasket%type;
c_quan bb_basket1.quantity%type;
c_order bb_basket1.orderplaced%type;
c_shp bb_basket1.idshopper%type;
c_total bb_basket1.total%type;
CURSOR c_cust is
SELECT idbasket, quantity, orderplaced, idshopper,total FROM bb_basket1;
BEGIN
OPEN c_cust;
LOOP
FETCH c_cust into c_bsk, c_quan, c_order, c_shp, C_total;
EXIT WHEN c_cust%notfound;

if c_total>=150 then
dbms_output.put_line('Shopper ID '||c_shp|| ' is rated as HIGH with total spend of $'||
C_total||' and '||c_quan||' number of orders.');
ELSIF c_total>=100 and c_total<=149 then
dbms_output.put_line('Shopper ID '||c_shp|| ' is rated as MEDIUM with total spend of $'||
C_total||' and '||c_quan||' number of orders.');
13

ELSIF c_total<=99 then


dbms_output.put_line('Shopper ID '||c_shp|| ' is rated as LOW with total spend of $'||C_total||'
and '||c_quan||' number of orders.');

End if;

END LOOP;

CLOSE c_cust;
END;

14

OUTPUT:

Question 3
Solution:
declare
a number(2):=0;
c number(2):=0;
s number(2):=0;
c_idshopper bb_shoper1.idshopper%type;
c_firstname bb_shoper1.firstname%type;
c_lastname bb_shoper1.lastname%type;

cursor c_bbshoper is

15

select idshopper, firstname, lastname from bb_shoper1;

c_order bb_basket1.orderplaced%type;
c_shp bb_basket1.idshopper%type;
CURSOR c_cust is
SELECT orderplaced, idshopper FROM bb_basket1;

begin
open c_bbshoper;
dbms_output.put_line('TOTAL CUSTOMERS DETAILS:');
loop
fetch c_bbshoper into c_idshopper, c_firstname, c_lastname;
exit when c_bbshoper%notfound;
a:=c_idshopper;

s:=s+1;

open c_cust;
loop
fetch c_cust into c_order, c_shp;
16

exit when c_cust%notfound;


if (c_shp=a) then
dbms_output.put_line('Shopper ID: '||c_idshopper||' First Name: '||c_firstname ||' Last Name: '||
c_lastname ||' Total Order '||c_order);
end if;
c:=c+c_order;
end loop;
close c_cust;
end loop;
close c_bbshoper;
dbms_output.put_line('Processed '||s||' number of shoppers with a total of '||c||' number of orders
recorded.');

end;

OUTPUT:
17

Question 4
Solution:
DECLARE
a number(7,2):=0.0;
d number(7,2):=0.0;
c number(1):=0;
buff number(7,2):=0.0;
no number(10):=0;
c_bsk bb_basket1.idbasket%type;
c_quan bb_basket1.quantity%type;
c_order bb_basket1.orderplaced%type;
c_shp bb_basket1.idshopper%type;
18

c_total bb_basket1.total%type;
CURSOR c_cust is
SELECT idbasket, quantity, orderplaced, idshopper,total FROM bb_basket1;
BEGIN
OPEN c_cust;
LOOP
FETCH c_cust into c_bsk, c_quan, c_order, c_shp, C_total;
EXIT WHEN c_cust%notfound;

if c_total<=a then
dbms_output.put_line('');

ELSE
a := C_total;
End if;

if c_quan<=c then
dbms_output.put_line('');
ELSE
c:=c_quan;

19

End if;

buff:=C_total;
d:=buff+d;
no := no+1;

END LOOP;
dbms_output.put_line('The highest total order is: '||a||'');
dbms_output.put_line('The largest number of items on an order is customer: '||c||'');
dbms_output.put_line('The average amount for all customers is: '||d/no||'');
CLOSE c_cust;
END;

20

OUTPUT:

21

Reference List
Busso, D., Dominguez, C., Perez-Acle, T. and Moreno, R. (2010). Life-giving caspases:
revealing new roles during mouse embryo preimplantation development. Int. J. Dev. Biol., 54(5),
pp.857-865.
DEVELOPMENT OF AN INTEGRATED DOCUMENT MANAGEMENT SYSTEM: THE
INTERACTION

OF

DATABASE

PRODUCTS

AND

ARCHIVE

DOCUMENTS.

(2013).Automation and Control in Technical Systems.


Frigerio, I., Roverato, S. and Amicis, M. (2013). A Proposal for a Geospatial Database to Support
Emergency Management. JGIS, 05(04), pp.396-403.
Garca-Zornoza, R., Morales-Angulo, C., Gonzlez-Aguado, R., Acle Cervera, L., Cortizo
Vzquez, E. and Obeso Agera, S. (2012). Traumatismos cervicales. Acta Otorrinolaringolgica
Espaola, 63(1), pp.47-54.
Hababeh, I., Khalil, I. and Khreishah, A. (2015). Designing High Performance Web-Based
Computing Services

to Promote Telemedicine

Database

Management

System. IEEE

Transactions on Services Computing, 8(1), pp.47-64.


Jger, T. and fner, D. (2013). Impact of a Proprietary Database Management System on Quality
Assurance and Patient Safety in Gastrointestinal Surgery. Z Gastroenterol, 51(07).
Kanwar, R., Trivedi, P. and Singh, K. (2013). NoSQL, A Solution for Distributed Database
Management System. International Journal of Computer Applications, 67(2), pp.6-9.
Oh, J., Moon, N. and Hong, S. (2015). Trajectory based database management for intelligent
surveillance system with heterogeneous sensors. Multimed Tools Appl.
SajjatulIslam, M. and Zainal Abedin, M. (2013). Impacts of Data Mining on Relational Database
Management System Centric Business Environments. International Journal of Computer
Applications, 75(3), pp.21-27.

22

Você também pode gostar