Skip to main content

Solution Manual for Oracle 11G SQL 2nd Edition by Joan Casteel

Page 1

Solution Manual for Oracle 11G SQL 2nd Edition by Joan Casteel

Chapter 1 Solutions Review Questions 1. c 2. b 3. a 4. a, b, and d 5. a, c, and d 6. c 7. a 8. a 9. c 10. b 11. Procedure: A PL/SQL block that can receive and return multiple values. Function: A PL/SQL block that typically returns one value and can be used in SQL and PL/SQL statements. Package: Groups procedures and functions together. Database trigger: A PL/SQL block that fires automatically based on a DML action on a specified table. 12. Yes, regardless of the development tool, using stored program units is still an advantage, especially when performing SQL tasks because it increases overall efficiency by reducing network transmissions. 13. A middle-tier in the three-tier model serves as the application server, and application code is stored on the application server instead of the client machine. 14. A user interface consists of windows that users see to interact with the application. If a developer uses Oracle tools, such as Oracle Forms, PL/SQL provides all the program code that responds to user events, such as clicking a button.

Hands-On Assignments Part I Assignment 1-1 Querying the database:


Step 2: SELECT idProduct, productname, price, active, type, idDepartment, stock FROM bb_product;

Step 3: SELECT idShopper, b.idBasket, b.orderplaced, b.dtordered, b.dtcreated FROM bb_shopper s INNER JOIN bb_basket b USING (idShopper);

Step 4: SELECT idProduct, p.productname, pc.categoryname, pd.optionname FROM bb_product p INNER JOIN bb_productoption USING(idProduct) INNER JOIN bb_productoptiondetail pd USING(idOption) INNER JOIN bb_productoptioncategory pc USING(idOptioncategory);

Writing SQL statements: Step 1: SELECT DISTINCT idproduct FROM bb_basketitem ORDER BY idproduct;

Step 2: ANSI join: SELECT bi.idbasket, idproduct, p.productname, p.description FROM bb_basketitem bi JOIN bb_product p USING(idproduct);

Traditional join: SELECT bi.idbasket, bi.idproduct, p.productname, p.description FROM bb_basketitem bi, bb_product p WHERE bi.idproduct = p.idproduct;

Step 3: ANSI join: SELECT s.lastname, idbasket, idproduct, p.productname, p.description FROM bb_shopper s JOIN bb_basket b USING(idshopper) JOIN bb_basketitem bi USING(idbasket) JOIN bb_product p USING(idproduct);

Traditional join: SELECT s.lastname, bi.idbasket, bi.idproduct, p.productname, p.description FROM bb_shopper s, bb_basket b, bb_basketitem bi, bb_product p WHERE s.idshopper = b.idshopper AND b.idbasket = bi.idbasket AND bi.idproduct = p.idproduct;

Step 4:


SELECT idbasket, idshopper, TO_CHAR(dtcreated,'Month DD, YYYY') FROM bb_basket WHERE TO_CHAR(dtcreated,'Mon YYYY') = 'Feb 2012';

Step 5: SELECT idproduct, SUM(quantity) FROM bb_basketitem GROUP BY idproduct;

Step 6: SELECT idproduct, SUM(quantity) FROM bb_basketitem GROUP BY idproduct HAVING SUM(quantity) < 3;

Step 7: SELECT idproduct, productname, price FROM bb_product WHERE type = 'C' AND price > (SELECT AVG(price) FROM bb_product WHERE type = 'C');

Step 8: CREATE TABLE contacts (con_id NUMBER(4), company_name VARCHAR2(30) NOT NULL, email VARCHAR2(30), last_date DATE DEFAULT SYSDATE, con_cnt NUMBER(3), CONSTRAINT con_id_pk PRIMARY KEY (con_id), CONSTRAINT con_cnt_ck CHECK (con_cnt > 0));

Step 9: INSERT INTO contacts (con_id, company_name, email, last_date, con_cnt) VALUES (555,'A Company', 'steve@a.com','01-JUL-2012',5); INSERT INTO contacts (con_id, company_name, email, con_cnt) VALUES (777,'B Company', 'jan@b.com',111); COMMIT;

Step 10: UPDATE contacts SET email = 'ben@a.com' WHERE con_id = 555; SELECT * FROM contacts; ROLLBACK; SELECT * FROM contacts;

Assignment 1-2 Example: TOAD 

PL/SQL debugger allows easy line-by-line code stepping.


Formatter Plus analyzes and formats PL/SQL code.

Knowledge Expert provides a PL/SQL code library.

Assignment 1-3 

Calculating the total count of items, using quantity

Retrieving shipping cost data from the database

Determining the correct shipping cost

Retrieving the tax rate from the database

Calculating the tax amount by using rate and subtotal

Calculating the order total by adding subtotal, shipping, and tax

Assignment 1-4 A control structure is a mechanism that directs the flow of control in a PL/SQL program. Examples include IF-THEN, CASE, and LOOP statements.

Hands-On Assignments Part II Assignment 1-5 Step 1: SELECT d.firstname, d.lastname, p.pledgedate, p.pledgeamt FROM dd_donor d JOIN dd_pledge p USING (idDonor) WHERE paymonths = 0;

Step 2: SELECT d.firstname, d.lastname, p.pledgedate, p.pledgeamt, p.pledgeamt/12 "Monthly Pay" FROM dd_donor d JOIN dd_pledge p USING (idDonor) WHERE paymonths = 12;

Step 3: SELECT DISTINCT idProj, j.projname FROM dd_project j JOIN dd_pledge USING (idProj);

Step 4: SELECT idDonor, d.firstname, d.lastname, COUNT(idPledge) FROM dd_donor d JOIN dd_pledge p USING (idDonor) GROUP BY idDonor, d.firstname, d.lastname ORDER BY idDonor;

Step 5: SELECT * FROM dd_pledge WHERE pledgedate < TO_DATE('03/08/2012','mm/dd/yyyy');

or


SELECT * FROM dd_pledge WHERE pledgedate < '08-MAR-2012';

Case Projects Case 1-1 

A PL/SQL editor that checks syntax

Debugging features

Allows running and testing program execution

Case 1-2 Query 1: SELECT m.movie_id, m.movie_title, movie_cat_id, mt.movie_category FROM mm_movie m INNER JOIN mm_movie_type mt USING(movie_cat_id);

Query 2: SELECT member_id, last, suspension FROM mm_member;

Query 3: SELECT m.last, r.checkout_date, mv.movie_title FROM mm_member m INNER JOIN mm_rental r USING(member_id) INNER JOIN mm_movie mv USING(movie_id);

Chapter 2 Solutions Review Questions 1. b 2. c 3. b 4. c 5. b 6. d 7. a 8. a. 9. b and c 10. b 11. Variables are structures used to hold data values during the processing of a block.


Turn static files into dynamic content formats.

Create a flipbook
Solution Manual for Oracle 11G SQL 2nd Edition by Joan Casteel by AnswerDone - Issuu