Why does this code cause an ORA-04091 error?
load data infile * append into table sql_parent ( parent_id "CreateNewRollId", parent_char POSITION(1) CHAR(4), parent_value POSITION(5) CHAR(6) ) BEGINDATA c2 v2 c333v333 //function: CreateNewRollId // create or replace function CreateNewRollId RETURN NUMBER IS roll_max_id NUMBER(38); roll_id NUMBER(38); BEGIN select MAX(parent_id) into roll_id from sql_parent; roll_max_id := GREATEST(roll_id, NVL(roll_max_id,0))+1; RETURN (roll_max_id); END; /
The SQLLOAD command inserts data into the sql_parent table. The SQLLOAD uses a stored function called CreateNewRollId that does a SELECT operation on the same table.
You also have a trigger on the insert event of the table. (It's not written, but check that you have such a trigger; 4091 is a specific error message that involves triggers.)
The SQLLOAD command fires the insert and then the trigger works in conjunction with the stored function. It causes a mutation because when you started the insert row, you cannnot do a DML operaion on the SAME table until the insert row completes. To resolve the situation, disable the insert trigger. Do the SQLLOAD statement, and then do the code inside the trigger definition.
For More Information
- What do you think about this answer? E-mail the editors at editor@searchDatabase.com with your feedback.
- The Best Oracle Web Links: tips, tutorials, scripts, and more.
- Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
Dig Deeper on Oracle error messages
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.