logo 西林@生存 - 骑猪闯天下!
回滚到指定点:SAVEPOINT & ROLLBACK TO
2006-10-18 15:47:00 By:xling

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; 

转我的贴,写你的名,是一种可耻的行为!请不要让我BS你!
阅读全文 | 回复(0) | 引用通告 | 编辑

发表评论:

    密码:
    主页:
    标题:
    页面数据正在载入...
<<  < 2006 - 10 >  >>
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Placard
1,長江後浪推前浪,前浪死在沙灘上!
2,有了钱的男人,才是真正的男人...
3,不要以为把你的小JJ埋进土里,你就rape了整个地球;不要以为把你的小JJ朝向天空,你就rape了整个宇宙!
Logon System
Search
Info about this blog
Others
myDream
bxna 京ICP备05002321号