简单Update语句,但是效率忽快忽慢~~

wgqqgw 2012-11-14 04:10:35
这是一句简单的update一句,有时候跑只要10秒,有时候跑要10分钟甚至20分钟,是怎么回事?是服务器、数据库性能的问题?有其他东西抢资源?

update tmp_report t1
set report_type='项目'
where exists (select 1 from v_detail t2
where t1.report_num=t2.report_num
and t1.report_detail_num=t2.report_detail_num
and t2.num_answer in (1,2,3)
and t2.question_type=1299);

tmp_report 中有索引在report_num和report_detail_num;10万行记录;
v_detail 中的主键是report_num和report_detail_num以及几个别的字段;千万行记录。

这么写规范吗?怎么写才能更规范更快?
Oracle新手求教。
...全文
371 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
软件钢琴师 2012-11-14
  • 打赏
  • 举报
回复
http://czmmiao.iteye.com/blog/1489625
软件钢琴师 2012-11-14
  • 打赏
  • 举报
回复
http://space.itpub.net/9399028/viewspace-682057 这有一篇文章 你看看 你可以百度一下
linwaterbin 2012-11-14
  • 打赏
  • 举报
回复
引用 4 楼 wgqqgw 的回复:
引用 2 楼 taiguang 的回复:可以用如下方式绑定变量 and t2.num_answer in (&par1) and t2.question_type=&par2 请问绑定变量具体是怎么写法?能否帮忙贴个完整的用法?谢谢你啦!
SQL> select * from tt where id=1;

ID NAME
---------- ----------------------------------------
1 test

SQL> select * from tt where id=2;

ID NAME
---------- ----------------------------------------
2 test

SQL> variable i number;
SQL> exec :i :=1;

PL/SQL 过程已成功完成。

SQL> select *from tt where id=:i;

ID NAME
---------- ----------------------------------------
1 test

SQL> exec :i :=2;

PL/SQL 过程已成功完成。

SQL> select *from tt where id=:i;

ID NAME
---------- ----------------------------------------
2 test

SQL> print i;

I
----------
2

SQL> select sql_text,parse_calls from v$sql where sql_text like 'select * from t
t where id=%';

SQL_TEXT PARSE_CALLS
------------------------------------------------------------ -----------
select * from tt where id=2 1
select * from tt where id=1 1
select * from tt where id=:i 2
SQL>
wgqqgw 2012-11-14
  • 打赏
  • 举报
回复
引用 2 楼 taiguang 的回复:
可以用如下方式绑定变量 and t2.num_answer in (&par1) and t2.question_type=&par2
请问绑定变量具体是怎么写法?能否帮忙贴个完整的用法?谢谢你啦!
wgqqgw 2012-11-14
  • 打赏
  • 举报
回复
请问绑定变量具体是怎么写法?能否帮忙贴个完整的用法?谢谢你啦!
软件钢琴师 2012-11-14
  • 打赏
  • 举报
回复
可以用如下方式绑定变量 and t2.num_answer in (&par1) and t2.question_type=&par2
软件钢琴师 2012-11-14
  • 打赏
  • 举报
回复
如果是相同的语句执行时间不一样 那就是有其他的会话抢占资源 如果 and t2.num_answer in (1,2,3)and t2.question_type=1299 输入的值不一样应该和数据量的大小及资源争用有关系

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧