2013-07-17 49 views
1

好,第一I识别用于特定日期的日期整数,起从我需要的随机值更新到dpm_dateto柱:更新随机日期,以一个单一的柱(日期repeates)

查询:

select to_char(to_date('15/05/2013','dd/mm/yyyy'), 'J') from dual; 

结果:

2456428 

现在,我尝试使用下面的查询来更新dpm_dateto柱:

update t_dailypm 
set dpm_dateto = 
    (select to_date(trunc(dbms_random.value(2456428,2456428+76)), 'J') from dual) 
where dpm_loc = 'P2' and dpm_department like '%IN%'; 

结果:

900 rows updated. 

但是,问题是,在dpm_dateto列中的每个不同值与同一日期更新。我无法理解这一点。请帮助。

回答

4

请勿使用子查询。
只需set = your_expression,就像下面的例子。
甲骨文优化子查询,并评估它只有一次,但表情会为每一行进行评估:

create table xyz(
    abc date 
); 

insert into xyz 
select sysdate from dual 
connect by level < 6; 

select * from xyz; 

ABC  
-------- 
13/07/17 
13/07/17 
13/07/17 
13/07/17 
13/07/17 

现在:

update xyz set abc = to_date(trunc(dbms_random.value(2456428,2456428+76)), 'J'); 

select * from xyz; 

ABC  
-------- 
13/06/14 
13/07/23 
13/07/26 
13/06/24 
13/07/10 
+0

感谢您的更新kordirko..I只是删除了子查询瞧!!!再次感谢! – user1728293

+0

P.S. - 将select(to_date(trunc ...)替换为简单的to_date(trunc ..构造,并且在未进行优化的情况下更新。 – user1728293

相关问题