title: cannot perform DML operation inside a query
body: <p>I cannot convince why I can't add DML operation inside <strong>Oracle Function</strong> especially inside <strong>cursor loop</strong>. I feel Oracle don't support DML operation inside cursor loop.</p>
  
  <p>How can I do If I need to insert into table inside cursor loop? Create new store procedure inside it or something else?</p>
  
  <p>Error Message : <strong>cannot perform DML operation inside a query</strong></p>
  
  <p>Here is my function,</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION TEST_FUNC(U_ID IN VARCHAR2)
  RETURN VARCHAR2
  IS
    V_MESSAGE VARCHAR2(30);
    CURSOR C_PERSON (V_ID VARCHAR2) IS
           SELECT NAME_UPPER
           FROM TBL_PERSON
           WHERE NAME_UPPER = V_ID;                  
  BEGIN
     FOR C_PERSON_CURSOR IN C_PERSON(U_ID) 
     LOOP
         INSERT INTO TMP_PERSON(NAME) VALUES (C_PERSON_CURSOR.NAME_UPPER);
     END LOOP;
  
     RETURN V_MESSAGE;
  
  EXCEPTION
  WHEN OTHERS THEN
      raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
  END;
  </code></pre>