oracle程式設計300例-效能優化(一)
阿新 • • 發佈:2018-11-21
1、在SELECT語句中避免使用“*”
2、儘可能減小記錄行數
3、使用rowid高效刪除重複記錄
例項:
delete from stu s
where s.rowid>(select min(t.rowid)
from stu t
where t.stu=t.stu
/
4、使用truncate代替delete刪除記錄
5、高效統計記錄行數
select tables_name,num_rows
from user_tables
where table_name='stu'
/
6、儘量多使用commit
7、避免使用having字句
select user_name,count(user_name)
from log_event
group by user_name
having user_name='sys'
/
select user_name,count(user_name)
from log_event
where user_name='sys'
group by user_name
/
8、用exists 替代in謂詞
select sno 學號,sname 姓名,sage 年齡,
sgentle 性別,sbirth 出生年月,sdept 所在班級
from stu
where exists (select * from grade)
where sno=stu.sno and gname='計算機基礎')
/
select sno 學號,sname 姓名,sage 年齡,
sgentle 性別,sbirth 出生年月,sdept 所在班級
from stu
where sno in(select sno from grade
where gname='計算機基礎')