如何在ORACLE的游标中动态地构造SQL语句啊?
追寻梦中人 2005-10-11 11:36:25 现在有这样一条语句:
select nvl(sum(fqty),0) into vpickqty from table1
where f1 >= PIFIRSTBIN
and f2 <= PILASTBIN;
我想这样:
当PIFIRSTBIN = ''时,SQL语句变为:
select nvl(sum(fqty),0) into vpickqty from table1
where f2 <= PILASTBIN;
当PILASTBIN = ''时,SQL语句变为:
select nvl(sum(fqty),0) into vpickqty from table1
where f1 >= PIFIRSTBIN;
如果都为空是,SQL语句变为:
select nvl(sum(fqty),0) into vpickqty from table1;
这个除了用
if
select nvl(sum(fqty),0) into vpickqty from table1
where f2 <= PILASTBIN;
elsif
select nvl(sum(fqty),0) into vpickqty from table1
where f1 >= PIFIRSTBIN;
else
select nvl(sum(fqty),0) into vpickqty from table1;
外还有什么其他办法吗?
如果这样的判断需要在游标里进行的话,
难道因为条件不同,需要写三个游标吗?