我的查詢的精簡版本在下面(因爲有多少變量),當我運行子查詢本身時它運行在2秒內,但是當我圍繞它時,它需要超過半小時。我檢查了所有列名 - 兩次。這是爲什麼發生?我能做些什麼來解決它?需要很長時間的Oracle查詢
SELECT Amount, Comments, FirstName, LastName, TermName, AdjustmentType, Void_Indicator FROM ( Select c.amount amount, c.comments comments, p.firstname firstname, p.lastname lastname, e.termname termname, c.adjustmenttype adjustmenttype, b.voidindicator void_indicator From ChargesDTL c, ChargesHDR b, PeopleHDL p, TermMaster e Where ( b.studentnumber=p.studentnumber and c.termid = e.term_id and b.adjustmentnumber=c.adjustmentnumber and p.personID=b.personID and b.locationcode='12' ) Union Select c.amount amount, c.comments comments, p1.firstname firstname, p1.lastname lastname, e.termname termname, c.adjustmenttype adjustmenttype, b.voidindicator void_indicator From ChargesDTL c, ChargesHDR b, PeopleHDL p1, TermMaster e Where ( b.studentnumber=p.studentnumber and c.termid = e.term_id and b.adjustmentnumber=c.adjustmentnumber and p1.personId = b.personId and b.locationcode='13' ) order by adjustmenttype )
這可能是一個查詢。派生表不是必需的 –