WITH c AS
(SELECT FORCE_MATCHING_SIGNATURE,
COUNT(*) cnt
FROM v$sqlarea
WHERE FORCE_MATCHING_SIGNATURE!=0
GROUP BY FORCE_MATCHING_SIGNATURE
HAVING COUNT(*) > 20
)
,
sq AS
(SELECT sql_text ,
FORCE_MATCHING_SIGNATURE,
row_number() over (partition BY FORCE_MATCHING_SIGNATURE ORDER BY sql_id DESC) p
FROM v$sqlarea s
WHERE FORCE_MATCHING_SIGNATURE IN
(SELECT FORCE_MATCHING_SIGNATURE
FROM c
)
),
C2 as ( SELECT sq.sql_text sqltxt
FROM c,
sq
WHERE sq.FORCE_MATCHING_SIGNATURE=c.FORCE_MATCHING_SIGNATURE
AND sq.p =1
ORDER BY c.cnt DESC)
select sqltxt from c2 where rownum<=10 ;
select replace(replace(sqltxt,'''','\"'),'$','-') from c2 where rownum<=3 ;
select 'insert into nobindvar values('||''''||'myaddr'||''''||','||''''|| (select utl_inaddr.get_host_name from dual)||''''||','||''''||replace(sqltxt,'''','\"')||''''||','||''''||to_char(sysdate,'yyyy-mm-dd')||''''||');' from c2 where rownum<=10 ;