的速度,我有两个疑问:“提取物(从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