About Data Manipulation Language(DML) Statements
Data manipulation language (DML) statements access and manipulate data in existing tables.
In the SQL Plus environment, youc can enter a DML statement after the SQL> prompt.
The effect of a DML statement is not permanent until you commit the transaction that includes it.
A transaction is a sequence of SQL statements that Oracle Database treats as a unit.
Until a transaction is committed, it can be rolled back.
About the INSERT Statement
The INSERT statement inserts rows into an existing table.
INSERT INTO table_name (list_of_columns)
VALUES (list_of_values);
Every column in list_of_columns must have a valid value in the corresponding position in list_of_values.
About the UPDATE Statement
The UPDATE statement updates(changes the values of) a set of existing table rows.
UPDATE table_name
SET column_name=value [ ,column_name = value] ...
[WHERE condition];
Each value must be valid for its column_name. If you include the WHERE clause, the statement updates column values only in rows that satisfy condition.
Example:
UPDATE EMPLOYEES
SET SALARY = 8500
WHERE LAST_NAME='Keats';
UPDATE EMPLOYEES
SET COMMISSION_PCT = COMMISSION_PCT + 0.05
WHERE DEPARTMENT_ID = 80;
About the DELETE Statement
The DELETE statement deletes rows from a table.
DELETE FROM table_name
[ WHERE condition ];
If you include the WHERE clause, the statement deletes only rows that satisfy condition. If you omit the WHERE clause, the statement deletes all rows from the table, but the empty table still exists. To delete a table, use the DROP TABLE statement.
About Transaction Control Statements
A transaction is a sequence a one or more SQL statements that Oracle Database treats as a unit: either all of the statements are performed, or none of them are.
You need transactions to model business processes that require that several operations be performed as a unit.For example, when a manager leaves the company, a row must be inserted into the JOB_HISTORY table to show when the manager left, and for every employee who reports to that manager, the value of MANAGER_ID must be updated in the EMPLOYEES table.To model this process in an application, you must group the INSERT and UPDATE statements into a single transaction.
The basic transaction control statements are:
- SAVEPOINT, which marks a savepoint in a transaction - a point to which you can later roll back. Savepoints are optional, and a transaction can have multiple savepoints.
- COMMIT, which ends the current transaction, makes its changes permanent, erases its savepoints, and releases its locks.
- ROLLBACK, which rolls back either the entire current transaction or only the changes made after the specified savepoint.
Committing Transactions
Committing a transaction makes its changes permanent, erases its savepoints, and releases its locks.
Before you commit a transaction:
- Your changes are visible to you, but not to other users of the database instance.
- Your changes are not final—you can undo them with a ROLLBACK statement.
After you commit a transaction:
- Your changes are visible to other users, and to their statements that run after you commit your transaction.
- Your changes are final—you cannot undo them with a ROLLBACK statement.
Rolling Back Transactions
Rolling back a transaction undoes its changes. You can roll back the entire current transaction, or you can roll it back only to a specified savepoint.
To roll back the current transaction only to a specified savepoint, you must use the ROLLBACK statement with the TO SAVEPOINT clause.
To roll back the entire current transaction, use either the ROLLBACK statement without the TO SAVEPOINT clause.
Rolling back the entire current transaction:
- Ends the transaction
- Reverses all of its changes
- Erases all of its savepoints
- Releases any transaction locks
Rolling back the current transaction only to the specified savepoint:
- Does not end the transaction
- Reverses only the changes made after the specified savepoint
- Erases only the savepoints set after the specified savepoint (excluding the specified savepoint itself)
- Releases all table and row locks acquired after the specified savepoint
Setting Savepoints in Transactions
The SAVEPOINT statement marks a savepoint in a transaction - a point to which you can later roll back. Savepoints are optional, and a transaction can have multiple savepoints.