Lots of *potential* causes of ora-4031. I'd strongly suggest you have a look at MOS note 1088239.1.
But also, we have a diagnosis tool which will help as well. See MOS Note 1521925.1
You could do something like
SQL> select * from v$sgastat order by pool, bytes desc;
POOL NAME BYTES CON_ID
------------ ---------------------------------------- ---------- ----------
java pool free memory 16777216 0
large pool free memory 33292288 0
large pool PX msg pool 262144 0
shared pool free memory 115875992 0
shared pool allocate segment latch re 58802176 0
shared pool KGLH0 39358864 0
shared pool SQLA 27873360 0
shared pool KQR X SO 13357016 0
shared pool write state object 13023264 0
shared pool db_block_hash_buckets 11538432 0
shared pool event statistics per sess 11512064 0
shared pool KGLS 10598168 0
shared pool KGLHD 10591064 0
shared pool PLMCD 9017784 0
shared pool row cache 8656032 0
...
to see what are the high consumers in the shared pool, but typically
a) the information is somewhat crytpic
b) changes rapidly
As a stopgap solution whilst you investigate the cause, you can look at increasing the size of the shared pool via init.ora parameter.