Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Oracle9i: SQL

Similar presentations


Presentation on theme: "Introduction to Oracle9i: SQL"— Presentation transcript:

1 Introduction to Oracle9i: SQL
Data Manipulation Chapter insert/manipulate data Introduction to Oracle9i: SQL

2 Introduction to Oracle9i: SQL
Chapter Objectives Add a record to an existing table Add a record containing a NULL value to an existing table Use a subquery to copy records from an existing table Modify the existing rows within a table Chapter insert/manipulate data Introduction to Oracle9i: SQL

3 Introduction to Oracle9i: SQL
Chapter Objectives Use substitution variables with an UPDATE command Issue the transaction control statements COMMIT and ROLLBACK Differentiate between DDL, DML, and transaction control commands Chapter insert/manipulate data Introduction to Oracle9i: SQL

4 Introduction to Oracle9i: SQL
Chapter Objectives Delete records Differentiate between a shared lock and an exclusive lock Use the SELECT…FOR UPDATE command to create a shared lock Chapter insert/manipulate data Introduction to Oracle9i: SQL

5 Introduction to Oracle9i: SQL
INSERT Command Used to add rows to existing tables Identify table in the INSERT INTO clause Specify data in the VALUES clause Can only add one row at a time to a table Chapter insert/manipulate data Introduction to Oracle9i: SQL

6 Introduction to Oracle9i: SQL
INSERT Command Syntax Enclose non-numeric data in single quotes If column list not provided, a value must be assigned to each column in the table Chapter insert/manipulate data Introduction to Oracle9i: SQL

7 INSERT Command Example
Chapter insert/manipulate data Introduction to Oracle9i: SQL

8 Introduction to Oracle9i: SQL
Inserting NULL Value Omit column name from INSERT INTO clause column list Substitute two single quotation marks Use NULL keyword Chapter insert/manipulate data Introduction to Oracle9i: SQL

9 Inserting Data from an Existing Table
Substitute subquery for VALUES clause Chapter insert/manipulate data Introduction to Oracle9i: SQL

10 Modifying Existing Rows
Modify rows using UPDATE command Use UPDATE command to: Add values to an existing row Change existing values Chapter insert/manipulate data Introduction to Oracle9i: SQL

11 Introduction to Oracle9i: SQL
UPDATE Command UPDATE clause identifies table SET clause identifies column being changed and new value Optional WHERE clause specifies row(s) to be changed – if omitted, will update all rows Chapter insert/manipulate data Introduction to Oracle9i: SQL

12 Introduction to Oracle9i: SQL
UPDATE Command Syntax Chapter insert/manipulate data Introduction to Oracle9i: SQL

13 UPDATE Command Example
Chapter insert/manipulate data Introduction to Oracle9i: SQL

14 Introduction to Oracle9i: SQL
Note: select query format is determined at the time of the select statement: e.g. Select title, to_char(pubdate, ‘MONTH DD, YYYY’) “Publication Date”, to_char (retail, ‘$999.99’) “Retail Price” from books Chapter insert/manipulate data Introduction to Oracle9i: SQL

15 Substitution Variables
Prompts user for value Identified by ampersand (&) preceding variable name Can be used to create interactive scripts Chapter insert/manipulate data Introduction to Oracle9i: SQL

16 Substitution Variable Example
Chapter insert/manipulate data Introduction to Oracle9i: SQL

17 Introduction to Oracle9i: SQL
Transaction Control Results of Data Manipulation Language (DML) are not permanently updated to table until explicit or implicit COMMIT occurs Transaction control statements can: Commit data through COMMIT command Undo data changes through ROLLBACK command Chapter insert/manipulate data Introduction to Oracle9i: SQL

18 Introduction to Oracle9i: SQL
COMMIT Explicit COMMIT occurs by executing COMMIT; Implicit COMMIT occurs when DDL command is executed or user properly exits system Permanently updates table(s) and allows other users to view changes Chapter insert/manipulate data Introduction to Oracle9i: SQL

19 Introduction to Oracle9i: SQL
ROLLBACK Used to “undo” changes that have not been committed Occurs when: ROLLBACK; is executed System restarts after crash Chapter insert/manipulate data Introduction to Oracle9i: SQL

20 Introduction to Oracle9i: SQL
Deleting Rows// DELETE command removes a row from a table Chapter insert/manipulate data Introduction to Oracle9i: SQL

21 DELETE Command – Omitting WHERE Clause
Omitting WHERE clause removes all rows Chapter insert/manipulate data Introduction to Oracle9i: SQL

22 Introduction to Oracle9i: SQL
Table Locks Prevents users from changing same data or objects Two types: Shared – prevents DML operations on portion of table Exclusive – locks table preventing other exclusive or shared locks Chapter insert/manipulate data Introduction to Oracle9i: SQL

23 Introduction to Oracle9i: SQL
Shared Lock Locks portion of table affected by DML operation Implicitly occurs during UPDATE or DELETE operations Explicitly occurs through LOCK TABLE command with SHARE MODE option Released when COMMIT (implicit or explicit) or ROLLBACK occurs Chapter insert/manipulate data Introduction to Oracle9i: SQL

24 Introduction to Oracle9i: SQL
Exclusive Lock Implicitly locks table for DDL operations - CREATE or ALTER TABLE Explicitly locked through LOCK TABLE command with EXCLUSIVE MODE option Released after execution of DDL operation or after user exits system Chapter insert/manipulate data Introduction to Oracle9i: SQL

25 SELECT…FOR UPDATE Command
Creates shared lock on retrieved portion of table Prevents one user from changing a row while another user is selecting rows to be changed Released through implicit or explicit commit Chapter insert/manipulate data Introduction to Oracle9i: SQL

26 SELECT…FOR UPDATE Command – Example
Chapter insert/manipulate data Introduction to Oracle9i: SQL


Download ppt "Introduction to Oracle9i: SQL"

Similar presentations


Ads by Google