BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE 10.2.0.4.0 Production
TNS for HPUX: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production
ok I have a simplified example below of what is happening
I am attempting to do updates or inserts into tables and I am using a pipelined function to that reads from the same tables to do it.
and it is giving me
ORA-04091: table DSAMSTRC.T is mutating, trigger/function may not see it
ORA-06512: at "DSAMSTRC.GET_T_ARRAY", line 6
my solution was to do a cursor and update insert row by row but I was wondering if there is a way around this error?
here is my example
DROP TABLE t;
------------------------------------------------------------------------------------
CREATE TABLE t
AS
SELECT LEVEL id, 'A' txt
FROM DUAL
CONNECT BY LEVEL <= 10;
-------------------------------------------------------------------------------------
CREATE OR REPLACE TYPE t_table_type AS OBJECT
(id NUMBER, txt VARCHAR2 (200));
------------------------------------------------------------------------------------
CREATE OR REPLACE TYPE t_array AS TABLE OF t_table_type;
-----------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION get_t_array (v_txt IN t.txt%TYPE)
RETURN t_array
PIPELINED
IS
BEGIN
FOR EACH IN (SELECT id, txt
FROM t
WHERE t.txt = v_txt)
LOOP
PIPE ROW (t_table_type (EACH.id, EACH.txt));
END LOOP;
RETURN;
END;
---------------------------------------------------------------------------------------
UPDATE t
SET txt = 'B'
WHERE id IN (SELECT id FROM TABLE (get_t_array ('A')));