declare mon int;
begin
for mon in 2..12
loop
begin
update tb1 a set sum(moneys)=(
select nvl(sum(money1),0) from tb1
where years=a.years
and ids=a.ids
and code = a.code
and mons<=mon
and years=2009
)where mons=mon and years=2009;
commit;
end;
end loop;
end;
end;
就这么一个更新语句 其中 要根据ids years code mons 才能锁定一条记录 问题 我现在更新速度超级慢 数据库里一共就70多万条记录 09年的记录 也就不到20万条 如何更新 速度才能快呀 很慢很慢的 受不了了 更新好几个小时了都
还有个问题 顺便问下 不算重点。。 SQLSERVER里 我可以打印语句 来查看 更新到哪里了
oracle里呢? 如何查看 ? dbms_output.put_line(...).这个语句 在没有更新完成之前 无法查看任何东西 有别的方法么 ?
begin
for mon in 2..12
loop
begin
update tb1 a set sum(moneys)=(
select nvl(sum(money1),0) from tb1
where years=a.years
and ids=a.ids
and code = a.code
and mons<=mon
and years=2009
)where mons=mon and years=2009;
commit;
end;
end loop;
end;
end;
就这么一个更新语句 其中 要根据ids years code mons 才能锁定一条记录 问题 我现在更新速度超级慢 数据库里一共就70多万条记录 09年的记录 也就不到20万条 如何更新 速度才能快呀 很慢很慢的 受不了了 更新好几个小时了都
还有个问题 顺便问下 不算重点。。 SQLSERVER里 我可以打印语句 来查看 更新到哪里了
oracle里呢? 如何查看 ? dbms_output.put_line(...).这个语句 在没有更新完成之前 无法查看任何东西 有别的方法么 ?
前先要设置 set serveroutput on
select nvl(sum(money1),0) from tb1
where years=a.years
and ids=a.ids
and code = a.code
and trunc(datetime,'MM') = trunc(a.datetime,'MM')
);
被更新的字段可以用sum()函数?
额 这里写错了 就当是MONEYSUM吧。。一个字段
update tb1 a set sum(moneys)...
被更新的字段可以用sum()函数? 原来是错的。
然后把原表的09年数据删掉 再插入回来。。create table 累计额中间表(
years int,
code varchar(50),
mon int,
money decimal(18,2),
moneysum decimal(18,2),
ids int;
)begin
delete from 累计额中间表;
commit;
/**1月**/
insert into 累计额中间表
select years,code,mon,money,
money,ids from
sum where years=2009 and mon=1;
commit;
/**2月**/
begin
for i in 2..12
loop
begin
insert into 累计额中间表
select a.years,a.code,a.mon,a.money,
sum(b.money),a.ids
from sum a , sum b
where a.years=2009 and a.mon=i and b.mon<=i
and a.ids=b.ids and a.code=b.code and a.years=b.years
group by a.years,a.code,a.mon,a.money,
a.ids;
commit;
end;
end loop;
end;
end;
嗯 然后就是把这里面得数据 再插回去 很快 也就不到30秒 30多万条数据就搞定了。。
希望可以帮到其他人 最后 非常感谢 上面几位的帮助 谢谢。