-- nobinds.sql: statements that differ only in their literals, grouped and counted -- Copyright (c) HASHJOIN. MIT License (https://hashjoin.com/kb/license/) -- https://hashjoin.com/kb/oracle/sql-without-bind-variables/ -- -- Usage: @nobinds.sql -- @nobinds.sql 1000 -- -- Needs Tom Kyte's remove_constants function (see the page for the link). -- Creates a global temporary table sql_area_tmp in the current schema. alter session set recyclebin=off; begin execute immediate 'truncate table sql_area_tmp'; execute immediate 'drop table sql_area_tmp'; exception when others then null; -- first run: the table doesn't exist yet end; / CREATE GLOBAL TEMPORARY TABLE sql_area_tmp on commit preserve rows AS SELECT sql_text , sql_text sql_text_wo_constants , module , action FROM v$sqlarea WHERE 1=0 / ALTER TABLE sql_area_tmp MODIFY ( SQL_TEXT_WO_CONSTANTS VARCHAR2(2000) ) / INSERT INTO sql_area_tmp (sql_text,module,action) SELECT sql_text,module,action FROM v$sqlarea / UPDATE sql_area_tmp SET sql_text_wo_constants = remove_constants(sql_text) / COMMIT / set pages 60 set lines 100 set trims on set head on set feed on set verify off col sql_text_wo_constants format a80 word_wrapped heading "SQL needs rewrite to use bind variables" SELECT sql_text_wo_constants , COUNT(*) cnt FROM sql_area_tmp GROUP BY sql_text_wo_constants HAVING COUNT(*) > &&1 ORDER BY 2 DESC / undefine 1