title: ora-04091 table is Mutating-
body: <p>I'm using a function which compares all the columns in Table 1 and Table 2 and returns 'Y' or 'N'. Based on that, I will update my Table 1.</p>
  
  <p>But when I run the merge statement it displays an error:</p>
  
  <blockquote>
    <p>ora-04091 - Table1 is mutating, trigger/function may not see it</p>
  </blockquote>
  
  <p>How can I fix this?</p>
  
  <pre><code>CREATE OR REPLACE function  DataChange  (in_epmname varchar2) return char  is
      v_epmname   table2.empname%type;
      v_DATA_COUNT  varchar2(2);
      v_DATA_CHANGED  char;
  begin
      SELECT COUNT (*) into v_DATA_COUNT
      FROM
      (
          SELECT trim(column1||column2||column3)
          FROM table1
          WHERE empname  =  in_epmname
          UNION
          SELECT trim(column1||column2||column3)
          FROM table2
          WHERE empname = in_epmname
      );
      If (v_DATA_COUNT = '1' ) Then
          v_DATA_CHANGED :='N';
      else
          v_DATA_CHANGED :='Y';
      end if;
      return v_DATA_CHANGED;
  end DataChange  ;
  </code></pre>
  
  <p>The merge statement that I'm using is:</p>
  
  <pre><code>CREATE OR REPLACE PROCEDURE updatetabble1 AS
  BEGIN
      MERGE
          INTO Table1 DBC
          USING  ( SELECT
              empname,
              DataChange(empname) as DATA_CHANGED
              FROM employee
          ) TBL_MAIN
          ON ( DBC.empname = TBL_MAIN.empname    )
          WHEN MATCHED THEN
            UPDATE SET
            DBC.DATA_CHANGED = TBL_MAIN.DATA_CHANGED;
      COMMIT;     
  END updatetabble1;
  </code></pre>