我开始了解SQL中的savepoint以回滚到特定的事务点。但是我们不知道可以创建多少个保存点?保存点是否会给数据库带来额外负担!
答案 0 :(得分:1)
一个简单的测试证明,保存点数量的限制足以涵盖任何实际用途。它很可能只是限制资源,UNDO表空间。
HUSQVIK@HQ_PDB_TCP> CREATE TABLE test1 (val NUMBER);
Table created.
HUSQVIK@HQ_PDB_TCP> BEGIN
2 FOR i IN 1..100000 LOOP
3 INSERT INTO test1 VALUES (dbms_random.value);
4 EXECUTE IMMEDIATE 'SAVEPOINT s' || i;
5 END LOOP;
6 END;
7 /
PL/SQL procedure successfully completed.
HUSQVIK@HQ_PDB_TCP> SELECT count(*) FROM test1;
COUNT(*)
----------
100000
1 row selected.
HUSQVIK@HQ_PDB_TCP> ROLLBACK TO SAVEPOINT s99999;
Rollback complete.
HUSQVIK@HQ_PDB_TCP> SELECT count(*) FROM test1;
COUNT(*)
----------
99999
1 row selected.
HUSQVIK@HQ_PDB_TCP> ROLLBACK TO SAVEPOINT s1;
Rollback complete.
HUSQVIK@HQ_PDB_TCP> SELECT count(*) FROM test1;
COUNT(*)
----------
1
1 row selected.
HUSQVIK@HQ_PDB_TCP>
答案 1 :(得分:0)
我知道在Oracle 7上,默认值为5,可以通过设置Oracle SAVEPOINTS初始化参数将其提升到255。但在那之后我从未遇到过问题。