Experiment: Use Table-Based and Cursor-Based ... - yimg.com

6 downloads 31 Views 85KB Size Report
Experiment: Use Table-Based and Cursor-Based Records. A). Write a script to populates the zip_rec record using the. SELECT INTO statement with a row from  ...
Experiment: Use Table-Based and Cursor-Based Records A) Write a script to populates the zip_rec record using the SELECT INTO statement with a row from the ZIPCODE table & displayed on the screen. Notice that a restriction applied to the ROWNUM enforces the SELECT INTO statement and always returns a random single row. B) Modify the script so that zip_rec is defined as a cursorbased record. C) Modify the script to Change the structure of the zip_rec record so that it contains the total number of students in a given city, state, and zip code. Do not include audit columns such as CREATED_BY and CREATED_DATE in the record structure. Experiment: Use User-Defined Records A) write script contains the ZIP_CUR cursor, which returns the total number of students corresponding to a particular zip code. Next, it contains the declaration of the user-defined record type, zip_info_type, which has two fields, and the actual user defined record, zip_info_rec. Populates the zip_info_rec record using the cursor FOR loop. Because zip_info_rec is a user-defined record, each record field is assigned a value individually. zip_info_rec data is Displayed on the screen for only the first five records returned by the ZIP_CUR cursor. B) Modify the script to Change the structure of the zip_info_rec record so that it also contains the total number of instructors for a given zip code. Populate this new record, and display its data on the screen for the first five records returned by the ZIP_CUR cursor. Experiment: Use Object Types with Collections A) Create object type ENROLLMENT_OBJ_TYPE, which has the following attributes: ATTRIBUTE NAME DATA TYPE PRECISION

B) C) D) E) F)

student_id

NUMBER

8

first_name

VARCHAR2

25

last_name

VARCHAR2

25

course_no

NUMBER

8

section_no

NUMBER

3

enroll_date

DATE

final_grade NUMBER 3 Write a script uses the newly created object type. Write a script for all object attributes are populated with corresponding values selected from the appropriate tables & displayed on the screen. Modify a script to populate an associative array of objects. After population completed, display all the objects on the screen. Modify a script to populate the table of objects using the BULK SELECT INTO statement. Write a script to data stored in the table of objects can be retrieved using the SELECT INTO statement as well.

Experiment: Use Object Type Methods A) Create a user-defined constructor method that populates object type attributes by selecting data from the corresponding tables based on the incoming values for student ID, course, and section numbers & test the newly added constructor method. B) Add a member procedure method, GET_ENROLLMENT_NAME, that returns student full name. C) Add a static method to the enrollment_obj_type object type that displays values of individual attributes on the screen. D) Add the method to the object type enrollment_obj_type so that its instances may be compared and/or sorted. The object instances should be compared based on the values of the course_no, section_no, and student_id attributes. Experiment: Write a SQL Script to create a following ADT.  INVENTORY_OBJ (Not Final/Instantiable) Name Nullable ITEM_ID YES NUM_IN_STOCK YES REORDER_STATU YES S PRICE YES CONSTRUCTOR FUNCTION inventory_obj ( item_id IN NUMBER, num_in_stock IN NUMBER, price IN NUMBER(10,2) ) RETURN SELF AS RESULT MEMBER PROCEDURE print_inventory MEMBER PROCEDURE print_status MEMBER PROCEDURE print_price MAP MEMBER FUNCTION return_item RETURN number

Type NUMBER(10) NUMBER(10) VARCHAR2(20 CHAR) NUMBER(10,2)

 BOOK_OBJ EXTENT INVENTORY_OBJ (Not Final/Instantiable) Name

Nullable

Type

ISBN

YES

CHAR(10 CHAR)

CATEGORY

YES

VARCHAR2(20 CHAR)

TITLE

YES

VARCHAR2(100 CHAR)

NUM_PAGES

YES

NUMBER(10)

PUBLISHER

YES

VARCHAR2(20 CHAR)

CONSTRUCTOR FUNCTION book_obj ( item_id NUMBER, num_in_stock NUMBER, price NUMBER(10,2), isbn CHAR, title VARCHAR2, num_pages NUMBER, publisher VARCHAR2 ) RETURN SELF AS RESULT MEMBER PROCEDURE print_book_information OVERRIDING MEMBER PROCEDURE print_price OVERRIDING MAP MEMBER FUNCTION return_item RETURN number Write a SQL script to test created data type.

Experiment: Consider the following description of items in the Eggface computer mail-order catalog. “Eggface sells hardware and software. We sell the new Palm Pilot V for $400; its part number is 345. We also sell the IBM ThinkPad 570 for only $1999; choose part number 3784. We sell both business and entertainment software. Microsoft Office 2000 has just arrived and you can purchase the Standard Edition for only $140, part number 974. The new desktop publishing software from Adobe called In Design is here for only $200, part 664. We carry the newest games from Blizzard software. You can start playing Diablo II for only $30, part number 12, and you can purchase Starcraft for only $10, part number 812. 1. Create a well-formed XML document that describes the contents of the Eggface catalog. 2. Create a DTD for your XML document and make sure that the document you created in the last question (1) is valid with respect to this DTD. 3. Write an XML-QL query that lists all software items in the catalog. 4. Write an XML-QL query that lists the prices of all hardware items in the catalog.