2013-08-30 79 views

回答

3

您可以使用該功能dbms_transaction.local_transaction_id

下面是一個例子:(從here拍攝)

SELECT dbms_transaction.local_transaction_id 
FROM dual; 

CREATE TABLE t (
testcol NUMBER(3)); 

INSERT INTO t 
VALUES (1); 

SELECT dbms_transaction.local_transaction_id 
FROM dual; 

CREATE OR REPLACE FUNCTION atf RETURN VARCHAR2 IS 
PRAGMA AUTONOMOUS_TRANSACTION; 
x VARCHAR2(20); 
BEGIN 
    INSERT INTO t 
    (testcol) 
    VALUES 
    (2); 

    x := dbms_transaction.local_transaction_id; 
    COMMIT; 

    RETURN x; 
END atf; 
/

set serveroutput on 

DECLARE 
x VARCHAR2(20); 
BEGIN 
    x := atf; 
    dbms_output.put_line(x); 

    INSERT INTO t VALUES (3); 

    x := dbms_transaction.local_transaction_id; 
    dbms_output.put_line(x); 
    COMMIT; 
END; 
/
+0

謝謝,我會試試看。 –