Presentation is loading. Please wait.

Presentation is loading. Please wait.

Oracle8 - The Complete Reference. Koch & Loney1 Chapter 14. Changing Data: Insert, Update, Delete Presented by Victor M. Matos.

Similar presentations


Presentation on theme: "Oracle8 - The Complete Reference. Koch & Loney1 Chapter 14. Changing Data: Insert, Update, Delete Presented by Victor M. Matos."— Presentation transcript:

1 Oracle8 - The Complete Reference. Koch & Loney1 Chapter 14. Changing Data: Insert, Update, Delete Presented by Victor M. Matos

2 Oracle8 - The Complete Reference. Koch & Loney 2 Changing Data zIn this Chapter you will learn how to yinsert new rows into a table yupdate the values of columns in a row, and ydelete rows from a table.

3 Oracle8 - The Complete Reference. Koch & Loney 3 Sample Data zCOMFORT Table SQL> select * from COMFORT; CITY SAMPLEDAT NOON MIDNIGHT PRECIPITATION ------------- --------- --------- --------- ------------- SAN FRANCISCO 21-MAR-93 62.5 42.3.5 SAN FRANCISCO 22-JUN-93 51.1 71.9.1 SAN FRANCISCO 23-SEP-93 61.5.1 SAN FRANCISCO 22-DEC-93 52.6 39.8 2.3 KEENE 21-MAR-93 39.9 -1.2 4.4 KEENE 22-JUN-93 85.1 66.7 1.3 KEENE 23-SEP-93 99.8 82.6 KEENE 22-DEC-93 -7.2 -1.2 3.9 City SampleDate Noon MidNight Precipitation

4 Oracle8 - The Complete Reference. Koch & Loney 4 Insert zAdding a new row to the COMFORT table insert into COMFORT values ( 'CLEVELAND', TO_DATE('30-JAN-1999', 'DD-MON-YYYY'), 56.7, 43.8, 0); 1 row created CLEVELAND 30-JAN-99 56.7 43.8 0 Oracle default date-format

5 Oracle8 - The Complete Reference. Koch & Loney 5 Insert zAdding another row to the COMFORT table insert into COMFORT values ( 'CLEVELAND', TO_DATE(’01/31/1999', ’MM/DD/YYYY'), 56.7, 43.8, 0); 1 row created CLEVELAND 31-JAN-99 56.7 43.8 0 Change non-Oracle date values using TO_DATE(…). Indicate current date structure.

6 Oracle8 - The Complete Reference. Koch & Loney 6 Insert zAdding a time insert into COMFORT values ( 'CLEVELAND', TO_DATE('01/29/1999 1:35', 'MM/DD/YYYY HH24:MI'), 56.7, 43.8, 0); 1 row created CLEVELAND 29-JAN-99 1:10 56.7 43.8 0 Change non-Oracle date values using TO_DATE(…). Indicate current date structure.

7 Oracle8 - The Complete Reference. Koch & Loney 7 Insert zGiving an explicit list of columns. insert into COMFORT (SampleDate, Precipitation, City, Noon, Midnight) values ( TO_DATE('01/29/1999 1:35', 'MM/DD/YYYY HH24:MI'), NULL, 'CLEVELAND', 56.7, 43.8,); A different sequence of fields NULL means ‘unknown-value’

8 Oracle8 - The Complete Reference. Koch & Loney 8 Insert zUsing a SELECT command to insert rows. insert into COMFORT (SampleDate, Precipitation, City, Noon, Midnight) select TO_DATE('31-JAN-1999', 'DD-MON-YYYY'), Precipitation, 'CLEVELAND', Noon, Midnight from COMFORT where City = 'KEENE' and SampleDate='22-DEC-93' / KEENE 22-DEC-1993 12:00 -7.2 -1.2 3.9 CLEVELAND 31-JAN-1999 12:00 -7.2 -1.2 3.9

9 Oracle8 - The Complete Reference. Koch & Loney 9 Insert 1/2 zUse a SELECT command to add all the employees from the ‘RESEARCH’ dept. to the new project ‘X17’. Assign them to 1.5 hours/week. EMPLOYEE FNAME MINIT LNAME SSN BDATE ADDRESS SEX SALARY SUPERSSN DNO DEPARTMENT DNAME DNUMBER MGRSSN MGRSTARTDATE WORKS_ON ESSN PNO HOURS

10 Oracle8 - The Complete Reference. Koch & Loney 10 Insert 2/2 zSQL solution insert into WORKS_ON(Essn, Pno, Hours) select Ssn, 'X17', 1.5 from EMPLOYEE where Dno IN ( select Dnumber from DEPARTMENT where Dname LIKE 'RESEARCH%' ) 333445555 7777 1.5 123456789 7777 1.5 666884444 7777 1.5 453453453 7777 1.5 New records

11 Oracle8 - The Complete Reference. Koch & Loney 11 Update updateCOMFORT setPrecipitation =.5, MidNight = 73.1 where City = 'KEENE' AND SampleDate = '22-DEC-1993’ KEENE 22-DEC-93 -7.2 73.1.5

12 Oracle8 - The Complete Reference. Koch & Loney 12 Update zAdd/Subtract to a field. update COMFORT set Noon = Noon + 10, MidNight = MidNight - 20 where City = 'KEENE' AND SampleDate = '22-DEC-1993’ KEENE 22-DEC-93 -7.2 73.1.5 KEENE 22-DEC-93 2.8 53.1.5

13 Oracle8 - The Complete Reference. Koch & Loney 13 Update zUse SELECT comand update COMFORT set (Noon, MidNight) = (select Humidity, Temperature from WEATHER where City = 'MANCHESTER') where City = 'KEENE' Two attributes at once!

14 Oracle8 - The Complete Reference. Koch & Loney 14 Delete zRemove the city of ‘San Francisco’. delete from COMFORT where City = 'SAN FRANCISCO' zRecall the deleted records. RollBack;

15 Oracle8 - The Complete Reference. Koch & Loney 15 Delete zRemove ALL cities. delete from COMFORT; zRecall the deleted records. RollBack; Table definition is still in the dictionary


Download ppt "Oracle8 - The Complete Reference. Koch & Loney1 Chapter 14. Changing Data: Insert, Update, Delete Presented by Victor M. Matos."

Similar presentations


Ads by Google