代码大致思路如下:
open d1;
LOOP
if userCode is null then
FETCH d1
INTO d;
Exit When d1%Notfound;
end if;
select count(*)
into num3
from ec_quantity_list_history t
where t.user_code = d.user_code
and t.electri_quantity_type = 2
and t.electri_fee_month = eletricFeeMonth;--问题是这里,打开游标D1,会有多个user_code。所以这句会有问题。不知道怎么修改,放在哪做判断?
end loop;
close d1;
if num3 = 1 then
INSERT
ELSIF NUM3>1 then
open e1;
LOOP
if userCode is null then
FETCH e1
INTO e;
Exit When e1%Notfound;
end if;
insert
end loop;
close e1;
在线等
open d1;
LOOP
if userCode is null then
FETCH d1
INTO d;
Exit When d1%Notfound;
end if;
select count(*)
into num3
from ec_quantity_list_history t
where t.user_code = d.user_code
and t.electri_quantity_type = 2
and t.electri_fee_month = eletricFeeMonth;--问题是这里,打开游标D1,会有多个user_code。所以这句会有问题。不知道怎么修改,放在哪做判断?
end loop;
close d1;
if num3 = 1 then
INSERT
ELSIF NUM3>1 then
open e1;
LOOP
if userCode is null then
FETCH e1
INTO e;
Exit When e1%Notfound;
end if;
insert
end loop;
close e1;
在线等
解决方案 »
- oracle alter database open一直卡在那不动,日志也没报错
- 查询
- 在局域网ORACLE服务器上,用SQL命令创建表为什么没反应?难道是表太大,机器慢?
- 请教一个按周分组的问题
- 新手问题:如何向表中插入序列并且为主键
- oracle9安装完成建立数据库实例后,用sql plus连接数据库时,输入infodba,总提示the account is locked 该如何解除锁定
- 获取一个事务的执行时间的问题!
- Oracle 过程问题
- 简单问题:orcale下用那个系统库来建用户库。比如在sqlserver中系统一般都使用master数据库来建立其他用户数据库的!
- 用system/manager登录提示“凭证检索失败”怎么解决???
- 有哪位朋友做过把WIN平台下面的ORACLE库,迁移到LIUNX平台下面的?百分悬赏
- oracle优化等深度学习资料 学习的速度来拿啊 ...........................................
???不太明白你的意思
USERCODE NAME
1 A
1 C
1 C
2 SDA
2 DASD
2 DADA
3 DAD
我要依次COUNT(*),比如第1次是3,然后下面判断是否>1
直接FOR d1_ IN d1 LOOP
......
where t.user_code = d1_.user_code
...... 就可以了呀
然后根据这个出现的次数,如果仅出现一次,那么做一种操作,超过一次做另一种操作???
into num3
from ec_quantity_list_history t
where t.user_code = d.user_code
and t.electri_quantity_type = 2
and t.electri_fee_month = eletricFeeMonth;--问题是这里,打开游标D1,会有多个user_code。所以这句会有问题。不知道怎么修改,放在哪做判断? if num3 = 1 then
INSERT
ELSIF NUM3>1 then
open e1;
LOOP
if userCode is null then
FETCH e1
INTO e;
Exit When e1%Notfound;
end if;
insert
end loop;
close e1; end loop;
close d1;
dbms_output.put_line(num3||' '||d.user_code);
if num3 = 1 then我打印了一下,应该出现下面的情况,每个一个
1 02530104
1 02536366.2
1 02530080
1 02536236
1 02536366
1 02536409
1 02543200
1 02530105
1 02536236.3
1 02536426
1 02552513
1 02530104但事实他上面的数据重复了15次,,11条数据变165条了
USERCODE NAME
1 A
1 C
1 C
2 SDA
2 DASD
2 DADA
3 DAD
打开游标,因为有3个1,所以num3=3,执行
因为有3个2,所以num3=3,执行
因为有1个3,所以num3=1,执行 ??
还是查游标里相同的USERCODE重复了几次(num3)?
如果是前者,你的程序就是取游标值的时候出问题了,
如果是后者,代码就有问题。
我理解你的意思是前者,是吗??
(个人想法)
感觉应该在定义course d1的时候就把重复的 user_code 去掉
我在10楼说的那种方法应该可以,还要判断每次打开的游标usercode值是否和上次相同,如果相同就num:=num3+1。而且大前提还要定义游标的时候 order by usercode。个人觉得你的LOOP有点问题,但也不好说问题在哪。你说出了165条数据,应该是LOOP。我平时的后台代码风格和你的不太一样。