Presentation is loading. Please wait.

Presentation is loading. Please wait.

Solving Lab 3 Los Angeles Pierce College Computer Science 560.

Similar presentations


Presentation on theme: "Solving Lab 3 Los Angeles Pierce College Computer Science 560."— Presentation transcript:

1 Solving Lab 3 Los Angeles Pierce College Computer Science 560

2 Problem: Lab Assignment 3 is too hard Actually, it's not...when it's broken down into steps And it has lots of details...until you organize it so the details don't matter "Inside every large problem is a small problem struggling to get out"

3 Problem A: Excluding the multi- state rows How to detect? Search for dash after comma Or search for state code longer than two characters

4 Problem B: Many MSAs have multiple cities How to detect? –Search for dashes before comma

5 Problem C: How to determine number of cities Count the dashes before the comma –...and add one

6 Problem D: How to extract cities Use SUBSTR

7 Problem E: Original OID key is not unique Solution 1: composite key of OID and city Solution 2: use a sequence

8 Problem F: Doing this all at once Solution: Don't do it all at once

9 A Possible Solution create temporary table –- Split city names and state codes –- Exclude multi-state rows –- Use a sequence This solves problem A Also only checks for comma once

10 Temporary Table Contents - Key (sequence) - city column - state code column - dash locations

11 SQL For Sequence CREATE SEQUENCE cs560_lab3_sq;

12 SQL for Temporary Table CREATE GLOBAL TEMPORARY TABLE lab3_temp ( row_sequence NUMBER(2) CONSTRAINT lab3_temp_pk PRIMARY KEY, OID NUMBER(15), cities VARCHAR2(255), state_code CHAR(2), dash1 number(3), dash2 number(3), dash3 number(3), dash4 number(3)) ON COMMIT PRESERVE ROWS;

13 Populate the Temporary Table INSERT INTO lab3_temp SELECT cs560_lab3_sq.NEXTVAL, OID, SUBSTR(basename, 1, INSTR(basename, ', ',1,1)-1), SUBSTR(basename, INSTR(basename, ', ', 1,1)+2, LENGTH(basename)- INSTR(basename, ', ', 1,1)+1), INSTR(basename, '-', 1, 1), INSTR(basename, '-', 1, 2), INSTR(basename, '-', 1, 3), INSTR(basename, '-', 1, 4) AS Dash4 FROM CENSUS_MSA WHERE (LENGTH(basename) - INSTR(basename, ', ', 1,1)-1) = 2;

14 Now divide the data into categories A. City Name [only one] B. City Name 1-City Name 2 C. City Name 1-City Name 2-City Name 3...et cetera

15 Process first case How can we recognize it? –if the Dash1 column is zero, only one city name INSERT INTO CENSUS_MSA_DROPDOWN SELECT OID, Cities, State_Code FROM lab3_temp WHERE Dash1 = 0;

16 Oops! We have to modify the dropdown table CREATE TABLE CENSUS_MSA_DROPDOWN ( OID NUMBER(15), CityName VARCHAR2(30), StateCode CHAR(2), CONSTRAINT census_msa_dropdown_pk PRIMARY KEY(OID, CityName));

17 To Be Continued…


Download ppt "Solving Lab 3 Los Angeles Pierce College Computer Science 560."

Similar presentations


Ads by Google