insert into metadata_statistics (order_sequence, metadata_defn, total_entries, rundate, metadata_id)
select 
rownumber() over (order by coalesce(length(dbl_blob),length(dbl_bit_varchar),0) desc), 
'SizePerScript', 
coalesce(length(dbl_blob),length(dbl_bit_varchar),0), 
current timestamp, dbl_doc_id
from dhi, dbl
where dbl_doc_id = dhi_doc_id
and   dbl_cmp_id = dhi_cmp_id
and   dbl_cmp_id = 40001
and substr(dhi_doc_path,1,9) = '/scripts/'
;
commit;
