I really hate to post another question on this topic - this seems to be a recurring theme for me. Between all the various forums over the years (that are no longer accessible or the referenced links don't work) I've posted this question a variety of ways depending on what customer / client I'm working with, but I have never gotten a good query to facilitate generating a report to help identify obsolete objects.
I need a query that will:
- Identify objects that have NEVER executed.
- Identify objects that have not executed in x days.
This can be 1 or 2 queries if needed, but the kicker is that the folder location of said object has to be part of the result set.
I have a query that I got from an Automic consultant awhile back (below), but it wasn't thoroughly tested (by me) and while syntactically it is correct - no errors and it shows results - the results for the 2nd requirement above (not executed in x days) aren't accurate.
I am not a SQL guru and this is a bit beyond me. If anyone could review / tweak or provide their own query for this - I'd greatly appreciate it.
For the rows that show (null) for Last Executed Date (objects never executed) this appears to be good results.
However, for the rows that show a Last Executed Date - the object identified DID run on that date (x days ago), but there are later runs after that, so it obviously shouldn't be on the list. Do i need to add a MAX or something somewhere?
I'm on an Oracle 12c db and v11.2.7. We're trying to do some cleanup prior to the upgrade to v12 next month.
And if there is another post that has this information - feel free to send the link. I DID search, but did not find what I needed.
TIA.
Laura
**
with AllFolderPaths AS (
select
level
,ofs_oh_idnr_f as parent
,ofs_oh_idnr_o as child
,oh_name
,SYS_CONNECT_BY_PATH(substr(oh_name,instr(oh_name,'\')+1) , '/' ) as path
from ofs, oh
where oh.oh_idnr = ofs_oh_idnr_f
start with ofs_oh_idnr_f =
(
select oh_idnr from oh
where oh_otype = 'CLNT'
-- enter client number
and oh_client = 555
)
connect by prior ofs_oh_idnr_o = ofs_oh_idnr_f
)
select
Path
, o.OH_Client Client
, o.OH_Name Object_Name
, o.oh_moddate Last_Modified_Date
, history.Last_Executed_Date
from
AllFolderPaths
, OH o
, (select ah_oh_idnr, max(ah_timestamp4) last_executed_date from ah
-- subtract the number of days from current date
where ah_timestamp4 < SYSDATE - 400
group by ah_oh_idnr) history
, OFS
where o.OH_Idnr=OFS_OH_Idnr_O
and OFS_OH_Idnr_F=parent
and o.OH_Idnr=history.AH_OH_Idnr(+)
-- enter client number
and o.oh_client = 555
and o.oh_otype in ('JOBS', 'JOBF', 'JOBP', 'EVNT', 'SCRI')
and o.oh_deleteflag = 0
GROUP BY path, o.oh_client, o.oh_otype, o.oh_name, o.oh_moddate, last_executed_date
order by path, o.oh_name;
------------------------------
Enterprise Scheduling Lead
Takeda
------------------------------