1
在Oracle 12c中,如果我在使用物化暗示在WITH..AS部分查詢調用一個函數,該函數調用的行爲像一個自治事務:甲骨文和兌現提示作爲自治事務的職能
DROP TABLE my_table;
CREATE TABLE my_table (
my_column NUMBER
);
-- Returns number of records in table
CREATE OR REPLACE FUNCTION my_function
RETURN INTEGER
IS
i INTEGER;
BEGIN
SELECT COUNT(1) INTO i FROM my_table;
RETURN i;
END;
/
-- Inserts one record to table
INSERT INTO my_table (my_column) VALUES (9);
-- Returns number of records in table. This works correctly, returns 1
SELECT COUNT(1) AS "use simple select" FROM my_table;
-- Returns number of records in table. This works correctly, returns 1
WITH x AS (
SELECT /*+ MATERIALIZE */ COUNT(1) AS "use WITH, MATERIALIZE" FROM my_table
)
SELECT * FROM x;
-- Returns number of records in table. This works correctly, returns 1
SELECT my_function AS "use FUNCTION" FROM dual;
-- Returns number of records in table. This works INCORRECTLY, returns 0.
-- Function is called in autonomous transaction?
WITH x AS (
SELECT /*+ MATERIALIZE */ my_function "use WITH,MATERIALIZE,FUNCTION" FROM dual
)
SELECT * FROM x;
ROLLBACK;
有誰知道這是什麼原因?它是一個Oracle錯誤還是它打算像這樣工作? (爲什麼?) 只有當WITH與MATERIALIZED提示和FUNCTION調用結合使用時,它爲什麼會這樣工作?
無法在Oracle 12c上重現,最後選擇返回1在我的情況。 – Husqvik
我猜Peti在12.1.0.1上,Husqvik在12.1.0.2上? –
我在12.1.0.1.0 – Peti