ORA-04031: unable to allocate … bytes of shared memory
The ORA-04031 unable to allocate … bytes of shared memory might cause some irritation when it reports, that a (relatively small) amount of memory cannot be allocated even though there is plenty of free memory in the System.
This is because the Shared pool heap manager allocates contiguous memory and the largest chunk of contiguous memory might be well below the total amount of free memory.
The most obvious fix for ORA-04031 errors is to increase the size of the Shared Pool. When doing that, it might be useful to consult v$shared_pool_advice.