Download presentation
Presentation is loading. Please wait.
1
More on Oracle Scripts CSC 240 (Blum)
2
Camping Equipment Revisited
CSC 240 (Blum)
3
Code for table creation: note comments and domain constraints
CSC 240 (Blum)
4
Something of a shortcut to inserting the Customer data.
Take the Customer data from the posted solution to the camping exercise and paste it into Excel. Insert a column before the data and enter: INSERT INTO Customer VALUES( Copy the value down. In the column after the data, enter ); CSC 240 (Blum)
5
Before CSC 240 (Blum)
6
After CSC 240 (Blum)
7
Save the Excel file as a CSV file.
CSC 240 (Blum)
8
Open the csv file in Notepad.
CSC 240 (Blum)
9
Go to Edit/Replace Replace a comma with a single quote followed by a comma followed by a space followed by a single quote CSC 240 (Blum)
10
Replace open parenthesis followed by single quote followed by comma followed by space with open parenthesis. CSC 240 (Blum)
11
Result: CSC 240 (Blum)
12
Replace comma followed by space followed by single quote followed by close parenthesis with close parenthesis. CSC 240 (Blum)
13
Result: CSC 240 (Blum)
14
Add INSERT Code to CREATE code and add a SELECT to check.
CSC 240 (Blum)
15
Result: CSC 240 (Blum)
16
Result of running script (I)
CSC 240 (Blum)
17
Result of running script (II)
CSC 240 (Blum)
18
Something to watch out for
The INSERT statement we use assume that the order of the values is the same as the order of fields in the CREATE TABLE statement. If this were not the case you can use Excel to change the order of the columns. CSC 240 (Blum)
19
Proceed Create an Item table (don’t forget a primary key).
Insert the item data. Create a table for the order. Note that “Order” is not an acceptable name for a table in Oracle – so change it. Also note that “Date” is a type and should not be used as the name of a field. Don’t forget the order table has foreign keys. CSC 240 (Blum)
20
Let us add a step in our procedure
CSC 240 (Blum)
21
High the column with the dates and go to Format/Cells, select Date from Category and select the type shown below. CSC 240 (Blum)
22
This is the format for dates preferred by Oracle.
CSC 240 (Blum)
23
Insert data in CustOrder table.
CSC 240 (Blum)
24
Result of SELECT CSC 240 (Blum)
25
CREATE statement pasted from script
CSC 240 (Blum)
26
New Problem Our procedure added single quotes but when we have numbers we do not want the quotes. CSC 240 (Blum)
27
Try adding a column of *’s before numbers and & after (use characters you do not expect in the rest of the data). CSC 240 (Blum)
28
After replacing , with ‘, ‘
CSC 240 (Blum)
29
Then replace ‘*’, ‘ with nothing
CSC 240 (Blum)
30
Result CSC 240 (Blum)
31
Replace ‘, ‘&’ with nothing
CSC 240 (Blum)
32
Result CSC 240 (Blum)
33
Replace & with nothing CSC 240 (Blum)
34
Result CSC 240 (Blum)
35
Integrity: The ItemNum was I7777 and we tried to insert 17777
CSC 240 (Blum)
36
Integrity: there was no Order number 6.
CSC 240 (Blum)
37
SELECT Customer C2727 CSC 240 (Blum)
38
Adam Adams 8475 Oak Lane not 8745 Oak Lane
CSC 240 (Blum)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.