說明:優化這個存盤程序,T_text 資料為100多條;T_text_standard 200萬條資料,現在這個存盤程序嚴重影響效率,請大神幫我優化一下,或這用普通sql寫出來
T_text 表結構 ,ID,xm,ygid ,zh , lx ,time,status ;
T_text_standard 表結構 xm,ygid ,zh ;
create or replace procedure PROC_text (inputterm in varchar2,return_value out varchar2) is
cursor bm_cursor
is select * from T_text where time=inputterm;
datarow bm_cursor%rowtype;--資料每行
data_count number; --資料數量
-- inputterm 日期
--status 狀態 0洗掉 1.正常
--ygid 員工號
-- lx 型別 01:開戶 02:變更 03:銷戶
-- zh 賬戶
--T_text_standard 標準表
--T_text 基礎表
begin
return_value:='yes';
--洗掉不是當前日期的資料
for datarow in bm_cursor loop
update T_text t set t.status='0' where ygid=datarow.ygid and zh=datarow.zh and time<>inputterm;
commit;
--查詢標準庫
--回圈查詢標準庫資訊
execute immediate'select count(1) from T_text_standard where ygid= '''||datarow.ygid||'''and zh='''||datarow.zh ||'''' into data_count;
--如果查詢數量>0 但不銷戶,修改型別為變更
if data_count >0 then
execute immediate 'update T_text set lx=''02'' where ygid='''||datarow.ygid||'''and zh='''||datarow.zh||'''and lx<>''03''';
commit;
else
--如果查詢數量其他 但不銷戶,修改型別為開戶,
execute immediate 'update T_text set lx=''01'' where ygid='''||datarow.ygid||'''and zh='''||datarow.zh||'''and lx<>''03''';
commit;
--如果標準庫中不存銷戶資訊,則復制這條資訊為開戶資訊
if datarow.lx='03' then
execute immediate' insert into T_text
select ''012'', xm, ygid,lx,zh,status ,time
from T_text where khyhdm='''||datarow.id||'''';
commit;
end if;
end if;
end loop;
end PROC_text;
uj5u.com熱心網友回復:
T_text_standard200萬左右的資料單獨執行
select count(1) from T_text_standard where ygid= '''||datarow.ygid||'''and zh='''||datarow.zh ||''''
看看是不是這條陳述句拖慢了效率
uj5u.com熱心網友回復:
T_text_standard 200萬條資料所以應該是select count(1) from T_text_standard where ygid= '''||datarow.ygid||'''and zh='''||datarow.zh ||''''出了問題吧
是主鍵或者索引的問題嗎?
如果存在主鍵或非空列上的索引,那么COUNT(1)、COUNT(*)、COUNT(ROWID)、COUNT(常量)、COUNT(主鍵)、COUNT(非空列)會首先選擇主鍵上的索引快速全掃描(INDEX FAST FULL SCAN)。若主鍵不存在則會選擇非空列上的索引。若非空列上沒有索引則肯定走全表掃描(TABLE ACCESS FULL)。其中,COUNT(ROWID)在走索引的時候比其它幾種方式要慢。通過10053事件可以看到這幾種方式除了COUNT(ROWID)之外,其它最終都會轉換成COUNT(*)的方式來執行。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/99317.html
標籤:開發
上一篇:vs 2012 連接資料庫時出現的錯誤:嘗試加載 Oracle 客戶端庫時引發 BadImageFormatException。如果在安裝 32 位 Oracl
