您的位置:首页 > 其它

Chapter 09-Manipulation Data - 03

2013-04-17 13:16 323 查看

Rolling Back Changers to a Marker

Create a marker in the current transaction by using the SAVEPOINT statement.

Roll back to that marker by using the ROLLBACK TO SAVEPOINT statement.

UPDATE ...
SAVEPOINT update_done;
INSERT ...
ROLLBACK TO update_done;


Implict Transaction Processing

An automatic commit occurs in the following circumstances:

-A DDL statement is issued

-A DCT statement is issued

-Normal exit from SQL Developer or SQL*Plus,without explicitly issuing COMMIT or ROLLBACK statements.(Normal exit->commit;Abnormal exit->rollback;)

An automatic rollback occurs when there is an abormal termination of SQL Developer or SQL*Plus or a system failure.

State of the Data Before COMMIT or ROLLBACK

The previous state of the data can be recovered.

The current user can review the resutls of the DML operations by using the SELECT statement.

Other users cannot view the results of the DML statements issued by the current user.

The affected rows are locked;other users cannot change the data in the affected rows.

State of the Data After COMMIT

Data changes are saved in the database.

The previous state of the data is overwritten.

All users can view the results.

Locks on the affected rows are released;those rows are available for other users to manipulate.

All savepoints are erased.

Committing Data

Make the changes:

DELETE FROM employees

WHERE employee_id = 999999;

INSERT INTO departments

VALUES(290,'Corporate Tax',NULL,1700);


Commit the changes

COMMIT;
COMMIT successded;


State of the Data After ROLLBACK

Discard all pending changes by using the ROLLBACK statement.

Data changes are undone.

Previous state of the data is restored.

Locks on the affected rows are released.

DELETE FROM copy_emp;

ROLLBACK;


State of the Data After ROLLBACK :Example

FOR UPDATE

SELECT e.employee_id,e.salary,e.commission_pct

FROM employees e JOIN departments d

USING(department_id)

WHERE job_id = 'ST_CLEAR' AND job_id = 1500

FROM UPDATE

ORDER BY e.employee_id;


Rows from both the EMPLOYEES and DEPARTMENTS tables are locked.

Use FOR UPDATE OF column_name to qualify the column you intend to change,then only the rows from that specific table are locked.

Summary

In this lesson,you should have learned how to use the following statements:

FunctionDescription
INSERTAdds a new row to the table
UPDATEModifies existing rows in the table
DELETERemoves existing rows from the table
TRUNCATERemoves all rows from a table
COMMITMakes all pending changes permanent
SAVEPOINTIs used to roll back to the savepoint marker
ROLLBACKDiscard all pending data changes
FOR UPDATE clause in SELECTLocks rows indentified by the SELECT query.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: