|
SAVEPOINT gives a name to and marks a point in the processing of your transaction. This marker allows you to ROLLBACK TO that point, erasing any changes and releasing any locks issued after that savepoint, but preserving any changes and locks which occurred before you marked the savepoint.
Note that savepoint_name is an undeclared identifier. This means that it must conform to the rules for an Oracle identifier (up to 30 characters in length, starting with a letter, containing letters, numbers and #, $, or _), but that you do not need to (nor can you) declare that identifier. 注意:savepoint_name是一个未声明的标识符.意思是它的命名要符合Oracle标识符的规则.但是你不需要对它进行声明(也不能进行声明).
When you ROLLBACK, you undo some or all changes made by your session to the database in the current transaction. The ROLLBACK statement is important because it allows you to clean up or restart from a "clean state" when a problem occurs.
There are two basic ways to use ROLLBACK:
Without parameters - Undoes all outstanding changes in your transaction. With the TO clause - Indicates a savepoint at which the ROLLBACK should stop. ROLLBACK TO allows you to undo all changes and release all acquired locks which were issued since the savepoint identified by savepoint_name was marked. See the SAVEPOINT statement for more information on how to mark a savepoint in your application.
注意事项:
ROLLBACK SAVEPOINT; -- ORA-02181: invalid option to ROLLBACK WORK -- Must use TO keyword before SAVEPOINT(必须用ROLLBACK TO 语法).
ROLLBACK WORK TO; -- ORA-02182: save point name expected -- Must specify savepoint name(必须指定savepoint name).
ROLLBACK TO SAVEPOINT 'favorite_movies'; -- ORA-03001: Unimplemented feature -- Savepoint cannot be in quotes.(Savepoint不能被引号括住)
例:
BEGIN FOR I IN 9..20 LOOP IF I = 15 THEN SAVEPOINT POINT15; END IF; INSERT INTO TST (ID,NAME) VALUES (I,'XLING'); END LOOP; ROLLBACK TO POINT15; COMMIT; END; |