remove_constans() ——检查共享池总的sql运行情况。
2012-06-25 17:14
323 查看
关于如何确定系统中是否存在绑定的情况,ASKTOM网站提供了一个不错的函数remove_constans()来检查共享池总的sql运行情况。
用函数更新sql_text_wo_constants 字段
下面是一个例子:
SQL> create table test as select * from v$sqlarea; --创建测试表test,并把v$sqlarea中的数据复制一份。 表已创建。 SQL> alter table test add sql_text_wo_constants varchar2(1000); --给test表增加一个字段。 表已更改。创建remove_constants函数,脚本如下:
create or replace function remove_constants(p_query in varchar2) return varchar2 as l_query long; l_char varchar2(1); l_in_quotes boolean default FALSE; begin for i in 1 .. length(p_query) loop l_char := substr(p_query, i, 1); if (l_char = '''' and l_in_quotes) then l_in_quotes := FALSE; elsif (l_char = '''' and NOT l_in_quotes) then l_in_quotes := TRUE; l_query := l_query || '''#'; end if; if (NOT l_in_quotes) then l_query := l_query || l_char; end if; end loop; l_query := translate(l_query, '0123456789', '@@@@@@@@@@'); for i in 0 .. 8 loop l_query := replace(l_query, lpad('@', 10 - i, '@'), '@'); l_query := replace(l_query, lpad(' ', 10 - i, ' '), ' '); end loop; return upper(l_query); end; /
用函数更新sql_text_wo_constants 字段
SQL> update test set sql_text_wo_constants = remove_constants(sql_text); 已更新1552行。 SQL> commit; 提交完成。查出除了谓词条件不同的sql语句和他们的执行次数,在这里是查询sql没有被重用超过100次的sql语句:
select sql_text_wo_constants, count(*) from test group by sql_text_wo_constants having count(*) > 100 order by 2;
下面是一个例子:
SQL> begin 2 for i in 1..1000 loop 3 execute immediate 'select * from t where rn = '||i; 4 end loop; 5 end; 6 / PL/SQL 过程已成功完成。 SQL> drop table test purge; 表已删除。 SQL> create table test as select * from v$sqlarea; 表已创建。 SQL> alter table test add sql_text_wo_constants varchar2(1000); 表已更改。 SQL> update test set sql_text_wo_constants = remove_constants(sql_text); 已更新1171行。 SQL> commit; 提交完成。 SQL> select sql_text_wo_constants, count(*) 2 from test 3 group by sql_text_wo_constants 4 having count(*) > 100 5 order by 2; SQL_TEXT_WO_CONSTANTS COUNT(*) ---------------------------------------------------------------------------------------------------- ---------- SELECT * FROM T WHERE RN = @ 1000
相关文章推荐
- 确定系统中是否存在绑定变量的情况,ASKTOM提供函数remove_constans()来检查共享池中的SQL运行情况
- 获取sql语句的执行情况近来我的oracle数据库(9201)运行慢
- Oracle EBS-SQL (PO-16):检查采购订单完成情况统计.sql
- Oracle EBS-SQL (MRP-6):检查MRP计划运行报错原因之超大数据查询1.sql
- Oracle EBS-SQL (MRP-7):检查MRP计划运行报错原因之超大数据查询2.sql
- 用Semisynchronous Replication半同步,mk-table-checksum数据同步一致性检查,监控主从同步运行状态的脚本等方式加强SQL性能和数据审核
- [华为面试题_ND2]运行错误请检查是否存在数组越界非法访问_野指针乱访问_空指针乱访问等情况_java_scanner_error
- SQL检查死锁情况
- 用oralce连接.net客户端出现问题:“数据连接不成功,请检查该数据库是否已启动尝试加载oracle客户端时引发BadImageFormatException.如果在安装32位Oracle客户端组件的情况下以64位模式运行,”的解决办法
- 专门查看阻塞和死锁情况以及引起的SQL语句,你可以创建后,直接运行之。
- 小机上监控AIX和数据库管理系统的运行情况直到性能优化(SQL语句优化和排除硬件问题)
- sas中的sql(2) 行选择 、限制重复、条件运算符、运行前语法检查、feedback、count
- 监视SQL语句在数据库中的运行情况
- SpringMVC4+MyBatis+SQL Server2014+druid 监控SQL运行情况
- 统计一条sql_id的信息,详细的运行情况
- 检查mysql的运行情况
- Oracle之数据库SQL总体运行情况
- 利用REMOVE_CONSTANTS函数,查询共享池中哪些SQL没有绑定变量
- 利用SQL 2005 系统表监控管理SQL服务器运行情况
- 检查数据库当前运行的SQL