规格约束

规格约束 - 图1 注意: 自治事务执行时,将会在后台启动自治事务session,我们可以通过max_concurrent_autonomous_transactions设置自治事务执行的最大并行数量,该参数取值范围为0~1024,默认值为10。当max_concurrent_autonomous_transactions参数设置为0时,自治事务将无法执行。

  • 触发器函数不支持自治事务。

    1. CREATE TABLE test_trigger_des_tbl(id1 INT, id2 INT, id3 INT);
    2. CREATE OR REPLACE FUNCTION tri_insert_func() RETURNS TRIGGER AS
    3. $$
    4. DECLARE
    5. PRAGMA AUTONOMOUS_TRANSACTION;
    6. BEGIN
    7. INSERT INTO test_trigger_des_tbl VALUES(NEW.id1, NEW.id2, NEW.id3);
    8. RETURN NEW;
    9. END
    10. $$ LANGUAGE PLPGSQL;
  • 自治事务不支持非顶层匿名块调用(仅支持顶层自治事务,包括存储过程、函数、匿名块)。

    1. create table t1(a int ,b text);
    2. DECLARE
    3. --PRAGMA AUTONOMOUS_TRANSACTION;
    4. BEGIN
    5. DECLARE
    6. PRAGMA AUTONOMOUS_TRANSACTION;
    7. BEGIN
    8. dbe_output.print_line('just use call.');
    9. insert into t1 values(1,'can you rollback!');
    10. END;
    11. insert into t1 values(2,'I will rollback!');
    12. rollback;
    13. END;
    14. /
    15. select * from t1;
  • 自治事务不支持ref_cursor参数传递。

    1. create table sections(section_ID int);
    2. insert into sections values(1);
    3. insert into sections values(1);
    4. insert into sections values(1);
    5. insert into sections values(1);
    6. CREATE OR REPLACE function proc_sys_ref()
    7. return SYS_REFCURSOR
    8. IS
    9. declare
    10. PRAGMA AUTONOMOUS_TRANSACTION;
    11. C1 SYS_REFCURSOR;
    12. BEGIN
    13. OPEN C1 FOR SELECT section_ID FROM sections ORDER BY section_ID;
    14. return C1;
    15. END;
    16. /
    17. CREATE OR REPLACE PROCEDURE proc_sys_call() AS
    18. DECLARE
    19. C1 SYS_REFCURSOR;
    20. TEMP NUMBER(4);
    21. BEGIN
    22. c1 = proc_sys_ref();
    23. if c1%isopen then
    24. raise notice '%','ok';
    25. end if;
    26. LOOP
    27. FETCH C1 INTO TEMP;
    28. raise notice '%',C1%ROWCOUNT;
    29. EXIT WHEN C1%NOTFOUND;
    30. END LOOP;
    31. END;
    32. /
    33. select proc_sys_call();
    34. CREATE OR REPLACE function proc_sys_ref(OUT C2 SYS_REFCURSOR, OUT a int)
    35. return SYS_REFCURSOR
    36. IS
    37. declare
    38. PRAGMA AUTONOMOUS_TRANSACTION;
    39. C1 SYS_REFCURSOR;
    40. BEGIN
    41. OPEN C1 FOR SELECT section_ID FROM sections ORDER BY section_ID;
    42. return C1;
    43. END;
    44. /
    45. CREATE OR REPLACE PROCEDURE proc_sys_call() AS
    46. DECLARE
    47. C1 SYS_REFCURSOR;
    48. TEMP NUMBER(4);
    49. a int;
    50. BEGIN
    51. OPEN C1 FOR SELECT section_ID FROM sections ORDER BY section_ID;
    52. c1 = proc_sys_ref(C1,a);
    53. if c1%isopen then
    54. raise notice '%','ok';
    55. end if;
    56. LOOP
    57. FETCH C1 INTO TEMP;
    58. raise notice '%',C1%ROWCOUNT;
    59. EXIT WHEN C1%NOTFOUND;
    60. END LOOP;
    61. END;
    62. /
    63. select proc_sys_call();
  • 自治事务函数不支持返回非out形式的record类型。

  • 不支持修改自治事务的隔离级别。
  • 不支持自治事务返回集合类型(setof)。