Datapatch error patch XXXX: XML descriptor does not exist in either the file system or SQL registry

In one of the environments (19c) after successfully applying Oracle patches at binary level, the following error was thrown when datapatch command was executed:

so the tool was searching for an old patch that doesn’t exist anymore under $ORACLE_HOME/sqlpatch directory.

— Possible Solutions:

Possible solution 1: if the patch number XXXX is related to old java patch, then apply latest OJVM patch…you can execute the following command to check:
$ORACLE_HOME/OPatch/opatch lspatches

Possible solution 2: copy the missing patch folder from another database environment to this environment (the environment you are facing the error) , under this folder: $ORACLE_HOME/sqlpatch

Datapatch error Error at line 2082: script md/admin/sdottsmeta.sql

I am sharing this blog post to cover an issue i have faced while invoking “datapatch” after rolling back a patch:

logfile: /ora/dbt01/cfgtoollogs/sqlpatch/29789911/23573028/29789911_rollback_dbt01_2020Jul16_06_56_44.log (errors)
-> Error at line 2082: script md/admin/sdottsmeta.sql
– SP2-0310: unable to open file “/ora/dbt01/product/19.3/sqlpatch/29789911/23573028/&sql_script.sql”
Patch 31281355 apply: WITH ERRORS
logfile: &full_logfile (errors)

Can’t use string (“Could not open logfile &full_log”…) as a HASH ref while “strict refs” in use at /ora/dbt01/product/19.3/sqlpatch/sqlpatch.pm line 6175, <LOGFILE> line 2177.
Please refer to MOS Note 1609718.1 and/or the invocation log
/ora/dbt01/cfgtoollogs/sqlpatch/sqlpatch_39541_2020_07_16_06_55_39/sqlpatch_invocation.log
for information on how to resolve the above errors.

The workaround fix:

Add “set define on” at the end of script $ORACLE_HOME/md/admin/prvtrdfctx.plb