Most commonly this error comes because of smaller SHARED POOL - which is also mentioned with the error message as follows
ERROR at line 1:
ORA-04031: unable to allocate 4018 bytes of shared memory ("shared
pool","unknown object","sga heap(1,0)","kglsim heap")
ORA-04031: unable to allocate 4018 bytes of shared memory ("shared
pool","unknown object","sga heap(1,0)","kglsim heap")