This is based on previous post https://communities.ca.com/docs/DOC-231154885
updated for Oracle 12c.
Note: you may need to adjust this script slightly to account for container database/ common user. However this works on a standalone system