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 UPDATESELECT 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:Function | Description |
INSERT | Adds a new row to the table |
UPDATE | Modifies existing rows in the table |
DELETE | Removes existing rows from the table |
TRUNCATE | Removes all rows from a table |
COMMIT | Makes all pending changes permanent |
SAVEPOINT | Is used to roll back to the savepoint marker |
ROLLBACK | Discard all pending data changes |
FOR UPDATE clause in SELECT | Locks rows indentified by the SELECT query. |
相关文章推荐
- 第08、09讲:Chapter 03--Managing an Oracle Instance.swf
- [bbk2193] 第34集 - Chapter 09-Optimizing Sore Perations(03)
- Chapter -09 Creating Procedures 03
- APUE读书笔记-09进程关系(03)
- 20170705L07-09-03老男孩linux运维实战培训-Sersync实时同步软件实战应用指南-2
- 20170711L07-09-03老男孩Linux运维实战培训-Sersync实时同步软件实战应用指南09
- 【收藏】本周ASP.NET英文技术文章推荐[12/03 - 12/09]
- [linux device driver] Chapter 03:字符设备注册学习
- Chapter -03 Writing Executable Statements 01
- [bbk2301] 第44集 - Chapter 11-SQL Statement Tuning(03)
- [bbk2226] 第40集 - Chapter 10-Using Resource Manager(03)
- 10-03-09 信心
- 顺序程序设计03 - 零基础入门学习C语言09
- 20170113C++阶段班03_Object C++_08-09语法复习/Object复习
- 第06讲:Chapter 03--Managing an Oracle Instance
- Chapter 03 - Joins - Solutions
- 09---Ajax03(返回xml数据)
- 【收藏】本周ASP.NET英文技术文章推荐[06/03 - 06/09]
- [linux device driver] Chapter 03:IS_ERR的理解
- [linux device driver] Chapter 03:以scull_load为例,详解mknod命令