动态构造的语句如下:
sL_SQL :=
'declare '||
'i integer; '||
'begin '||
'i := 1; '||
'for cPub in( '||
'select count(distinct Feecode) as FeeCodecnt '||
'from v_feedetail a'||OthTbl||
'where '||Condition||sWhere||
'group by GradeCode) loop '||
'if i=1 then :Lv_Med1TypeCount:=cPub.FeeCodecnt; '||
'elsif i=2 then :Lv_Med2TypeCount:=cPub.FeeCodecnt; '||
'elsif i=3 then :Lv_Med3TypeCount:=cPub.FeeCodecnt; '||
'end if;'||
'i := i+1; '||
'end loop;'||
'end;';
execute immediate sL_SQL into Lv_Med1TypeCount,
Lv_Med2TypeCount,
Lv_Med3TypeCount;在这个语句里一共只用到三个参数,而且都一一对应起来了,对于运行时出现“并非所有变量都已关联”这个错误不明白是怎么回事!
在网上搜索到对于这个错误的描述有两种,
说法一:驱动程序的错误,但具体如何解决却说得很含糊,说只要改变provide的值就行,具体怎么改,在哪改,都没说。
说法二:变量没有绑定。使用DBMS_SQL.BIND_VARIABLE(v_Cursor,':no',v_StartDate); 这条语句来绑定变量,但是里面的v_Cursor, v_StartDate两个参数用什么替代却没有说。另外这个解决方法是用在变量中的值赋给数据库中的某个字段的,而我这里是从结果集中取数据保存到变量中,不知道适不适用
请教诸位高手们,我想先判断上条语句出错在哪里应怎么做?
sL_SQL :=
'declare '||
'i integer; '||
'begin '||
'i := 1; '||
'for cPub in( '||
'select count(distinct Feecode) as FeeCodecnt '||
'from v_feedetail a'||OthTbl||
'where '||Condition||sWhere||
'group by GradeCode) loop '||
'if i=1 then :Lv_Med1TypeCount:=cPub.FeeCodecnt; '||
'elsif i=2 then :Lv_Med2TypeCount:=cPub.FeeCodecnt; '||
'elsif i=3 then :Lv_Med3TypeCount:=cPub.FeeCodecnt; '||
'end if;'||
'i := i+1; '||
'end loop;'||
'end;';
execute immediate sL_SQL into Lv_Med1TypeCount,
Lv_Med2TypeCount,
Lv_Med3TypeCount;在这个语句里一共只用到三个参数,而且都一一对应起来了,对于运行时出现“并非所有变量都已关联”这个错误不明白是怎么回事!
在网上搜索到对于这个错误的描述有两种,
说法一:驱动程序的错误,但具体如何解决却说得很含糊,说只要改变provide的值就行,具体怎么改,在哪改,都没说。
说法二:变量没有绑定。使用DBMS_SQL.BIND_VARIABLE(v_Cursor,':no',v_StartDate); 这条语句来绑定变量,但是里面的v_Cursor, v_StartDate两个参数用什么替代却没有说。另外这个解决方法是用在变量中的值赋给数据库中的某个字段的,而我这里是从结果集中取数据保存到变量中,不知道适不适用
请教诸位高手们,我想先判断上条语句出错在哪里应怎么做?
SQL> select :U from dual;
未说明结合变量"U"
SQL> select ':U' from dual;':U'
----
:U------------------------
你的变量存在于字符串中,故无法关联,如下句
'if i=1 then :Lv_Med1TypeCount:=cPub.FeeCodecnt; '
应改为
'if i=1 then '||:Lv_Med1TypeCount||':=cPub.FeeCodecnt; '
是希望通过这三个变量将数据传出来