HW2

.docx

School

New Jersey Institute Of Technology *

*We aren’t endorsed by this school

Course

434

Subject

Computer Science

Date

May 4, 2024

Type

docx

Pages

9

Uploaded by JusticeUniverse25366 on coursehero.com

1- Write a PL/SQL program using an implicit cursor that displays each state name, year, and value for each year in the following format: CS434-002 HOMEWORK 2 General Instructions. Read this carefully. This is more important than the individual questions. There are NO GROUP HOMEWORKS IN THIS CLASS. YOU NEED TO WORK ALONE. 1) Do not copy code from any other person. You can ask questions and get answers, but NEVER copy code. Also do not copy and paste English text unless I specifically permit it. NEVER. 2) Save this file. Put your answer to every question into the space AFTER the box. Then submit the whole file. 3) SHOW EVERYTHING. Anything you don't show will be automatically assumed as not done. Don't logically argue that "of course you must have done it." If we don't see it, then it is not done. 4) The whole homework is worth 50 points. Points will appear in [ ] brackets. If you miss the due date by up to one week, there will be a late penalty of 8 points subtracted. If you miss the due date by MORE than a week you will get ZERO points. This homework has four purposes: - Continue writing "simple" PL/SQL programs. - Start writing programs with cursors. - Start writing programs with triggers - Start writing programs with Object Relational tables
The state name should be written only once. You can only use the DRINKINGWATER table. If you use any other table, 0 points. Show the program at the first red arrow. ►DECLARE v_last_state VARCHAR2(100) := NULL; BEGIN DBMS_OUTPUT.PUT_LINE('STATE YEAR VALUE'); FOR r IN (SELECT State, Year, Value FROM drinkingwater ORDER BY State, Year) LOOP IF v_last_state IS NULL OR v_last_state != r.State THEN END IF; DBMS_OUTPUT.PUT_LINE(r.State); v_last_state := r.State; END IF; DBMS_OUTPUT.PUT_LINE(' ' || TO_CHAR(r.Year) || ' ' || r.Value); END LOOP; END; / 2- This question has three steps: STEP1: Copy and paste the following table into an Excel table, name it COVID_DAILY.CSV Import it into an ORACLE table.
COUNTRY NEW_CASES ACTIVE_CASES USA 62773 8584883 India 21668 200401 Brazil 78297 1052579 Russia 9270 310556 UK 6753 729854 France 27166 3630068 Spain 6255 248557 Italy 25673 497350 Turkey 14046 147606 Germany 13655 135950 Colombia 4579 38510 Argentina 8204 155943 Mexico 6674 266074 Poland 21045 286511 Iran 8308 191275 South Africa 1474 27035 Ukraine 9084 187591 Indonesia 5144 141070 Peru 7114 44648 Czechia 14353 164268 Canada 3018 30672 Chile 5563 30856 Romania 5236 49823 STEP2: Write a PL/SQL statement to add a new column (SUMMATION) into the table COVID_DAILY. [3 point] Show the PL/SQL statement at the first red arrow. STEP2: Write a PL/SQL program using an implicit cursor that adds NEW_CASES and ACTIVE_CASES values of COVID_DAILY in a row and then saves them in a SUMMATION column. [7 points] Show the program at the second red arrow. ALTER TABLE COVID_DAILY ADD SUMMATION NUMBER ►BEGIN FOR c_row IN (SELECT COUNTRY, NEW_CASES, ACTIVE_CASES FROM COVID_DAILY) LOOP UPDATE COVID_DAIL WHERE COUNTRY = c_row.COUNTRY;
END LOOP; END; 3- Create a trigger DrinkWater that will guarantee any time the table DRINKINGWATER2019’s STATEPOPULATION or DRINKINGPOPULATION status is updated, the trigger inserts a new row to the TRACKINGWATER table and writes the following message to the output window. Test it with: The output should look like this: Update New York population 4 STATE: New York Old Population Value: 19453561 New Population Value: 19453565 Update Florida Drinking Population 3 STATE: Florida Old Drinking Population Value: 20405336 New Drinking Population Value: 20405339 Update Florida population 3 STATE: Florida Old Population Value: 20405336 New Population Value: 20405339 Update Vermont population 1 STATE: Vermont Old Population Value: 623989 New Population Value: 623990 TRACKINGWATER should look like: STATE OldPopulation NewPopulation OldDrinkingPop NewDrinkingPop New York 19453561 19453565 null null Florida null null 20405336 20405339 Florida 21477737 21477742 null null Vermont 623989 623990 null null Show the TRACKINGWATER table creation SQL statement at the first red arrow [1] Show the trigger program at the second red arrow [4]. CREATE TABLE TRACKINGWATER ( STATE VARCHAR2(50), OldPopulation NUMBER, NewDrinkingPop NUMBER );
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help