圈子推荐
查看所有吧>>
活跃用户
    atlasdb 兼容oracle 特性之 自治事务控制

    请看实验:

    create table at_tb2(id int, name text);

    CREATE PROCEDURE at_test3(int)
    as $$  
    declare
    PRAGMA autonomous_transaction;
    BEGIN
            insert into at_tb2 values(1,'before s1');
            insert into at_tb2 values(2,'after s1');
            if $1 > 10 then
                    ROLLBACK;
            else
                    COMMIT;
            end if;
    end;
    $$ LANGUAGE plpgsql;  

     

    CREATE or replace PROCEDURE at_test4(int)

    as $$  

    declare

    begin

       insert into at_tb2 values(3,'atlasdb');

       call at_test3(1);

       insert into at_tb2 values(4,'atlasdb');

       rollback;

    end;

    $$ LANGUAGE plpgsql;  

     

    call at_test4(1);

    atlasdb=# select * from at_tb2;

     id |   name    

    ----+-----------

      1 | before s1

      2 | after s1

    (2 rows)


    • 分享到:
    排序方式:回复时间 共有0条评论