oracle8.1.6
select job_id,
job_start_time,
job_end_time,
interactive_p,
snapshot_p,
authority_id,
message,
creation_user,
doc_start_time,
doc_end_time,
doc_status,
doc_message,
document,
(j.job_end_time - j.job_start_time) * 24*60*60 as run_time_seconds,
(select count(e1.entry_id)
from auth_batch_job_entries e1
where e1.job_id = j.job_id) as num_actions,
(select count(e2.entry_id)
from auth_batch_job_entries e2
where e2.job_id = j.job_id
and e2.success_p = 'f') as num_problems
from auth_batch_jobs j
where j.job_id = :job_id
update auth_batch_jobs
set doc_start_time = sysdate
where job_id = :job_id
update auth_batch_jobs
set doc_end_time = sysdate,
doc_status = :doc_status,
doc_message = :doc_message,
document = empty_clob()
where job_id = :job_id
returning document into :1
insert into auth_batch_job_entries
(entry_id, job_id, operation, username, user_id, success_p, message, element_messages)
values
(:entry_id, :job_id, :operation, :username, :user_id, :success_p_db, :message, empty_clob())
returning element_messages into :1
delete from auth_batch_jobs
where job_end_time < sysdate - :num_days