Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

question updating a table using a pipelined function

pollywogMar 16 2011 — edited Mar 16 2011
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')));
 
This post has been answered by kendenny on Mar 16 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 13 2011
Added on Mar 16 2011
4 comments
522 views