在存储过程里给一变量赋值
例:建一个变量n1
select (select count(1) from aaa)+(select count(1) from bbb)into n1
from dual;
编译通不过,是何原因
select (select count(1) from aaa)+(select count(1) from bbb)
from dual;
在SQLPLUS里执行正常
抱歉,出了几天差,未及时回复,上面老兄不知是否输错了
execute immediate 'select (select count(1) from aaa)+(select count(1) from bbb) from dual' into n1;
还是
execute immediate 'select (select count(1) from aaa)+(select count(1) from bbb) from into n1 dual' ;
不过两者都不行
zy_ly,注意你的数据库版本,在8i里,使用
execute immediate 'select (select count(1) from aaa)+(select count(1) from bbb) from dual' into n1;
这样的语法和结果是没有问题的
如果你的是8.0版的,是不支持execute immediate的
你需要使用DBMS_SQL包
要不你换个角度
select count(1) into n1 from aaa ;
select count(*) into n2 from bbb;
n3 = n1 + n2
ok?