/*i-test for order 502338*/
INSERT INTO DISTRICTPLANT
  (SELECT DD, PL, EMP, getminsystemuser(), sysdate
     FROM (SELECT DISTRICT_ID DD FROM DISTRICT D WHERE D.CODE = '-'),
          (SELECT E.PLANT_ID PL ,E.EMPLOYEE_ID EMP
             FROM EMPLOYEE E, PLANT
            WHERE E.PLANT_ID = PLANT.PLANT_ID
            AND E.EMPLOYEENUMBER = (SELECT MIN(T.EMPLOYEENUMBER) FROM EMPLOYEE T WHERE T.PLANT_ID = E.PLANT_ID)
            AND PLANT.PLANT_ID NOT IN (SELECT DP.PLANT_ID FROM DISTRICTPLANT DP)));