的速度,我有兩個疑問:「提取物(從SYSDATE年)」
with tmp as (
select asy.aim_student_id, ast.aim_test, asq.response
from aim_student_test ast
join aim_student_qst asq on (asq.aps_yr = ast.aps_yr and asq.aim_test = ast.aim_test and asq.aim_id = ast.aim_id)
join aim_student_yr asy on (asy.aps_yr = ast.aps_yr and asy.aim_student_yr_id = ast.aim_student_yr_id)
where asq.aps_yr = '2012'
and asq.qst_num = 1)
select aim_student_id, aim_test, response
from tmp
where response is null
-- execution-time: 0.032 seconds
define this_year = extract(year from sysdate)
with tmp as (
select asy.aim_student_id, ast.aim_test, asq.response
from aim_student_test ast
join aim_student_qst asq on (asq.aps_yr = ast.aps_yr and asq.aim_test = ast.aim_test and asq.aim_id = ast.aim_id)
join aim_student_yr asy on (asy.aps_yr = ast.aps_yr and asy.aim_student_yr_id = ast.aim_student_yr_id)
where asq.aps_yr = &this_year
and asq.qst_num = 1)
select aim_student_id, aim_test, response
from tmp
where response is null
-- execution-time: 82.202 seconds
唯一的區別是,在一個我用「2012」,另一個我實現了提取物(一年SYSDATE)。
我只能想象Oracle正在計算它檢查的每條記錄的提取(年份來自sysdate),而且我無法弄清楚如何使它計算一次並將其用作變量。搜索沒有給我回答我尋找的答案...所以我來找SO.com的魔術師。如何正確使用
extract(year from sysdate)
作爲變量?
嘿夥伴 - 對不起,我沒有更早發佈 - 我兼職工作。今天是我本週回來的第一天,這是我第一次嘗試。它的工作方式非常魅力,完全符合我的要求 - 因此我將其標記爲我接受的答案,因爲另一個很有幫助,但並未完全涵蓋我所尋找的內容。 – nebffa 2012-07-23 23:17:49
@AlexPoole。 。 。非常好的解釋! – 2012-07-24 14:50:56