pl/sql 的一些问题

[复制链接]
查看11 | 回复9 | 2006-4-17 13:46:34 | 显示全部楼层 |阅读模式
在存储过程里给一变量赋值
例:建一个变量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里执行正常
回复

使用道具 举报

千问 | 2006-4-17 13:46:34 | 显示全部楼层
SELECT..INTO ..
回复

使用道具 举报

千问 | 2006-4-17 13:46:34 | 显示全部楼层
(select count(1) from aaa)+(select count(1) from bbb)
有问题
回复

使用道具 举报

千问 | 2006-4-17 13:46:34 | 显示全部楼层
select count(1) from aaa)+(select count(1) from bbb)
没有问题,在SQL/PLUS里执行都正常
回复

使用道具 举报

千问 | 2006-4-17 13:46:34 | 显示全部楼层
直到9i 以前的PL/SQL编译器都不理解这种语法。
如果你是在8i,那么可以使用本地动态sql
execute immediate 'select (select count(1) from aaa)+(select count(1) from bbb) from dual' into n1;
回复

使用道具 举报

千问 | 2006-4-17 13:46:34 | 显示全部楼层
抱歉,出了几天差,未及时回复,上面老兄不知是否输错了
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' ;
不过两者都不行
回复

使用道具 举报

千问 | 2006-4-17 13:46:34 | 显示全部楼层
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?
回复

使用道具 举报

千问 | 2006-4-17 13:46:34 | 显示全部楼层
还有,下次提问时,如果有错误,记得把错误代码帖出来,否则除了猜测,别人没有办法帮你定位错误。
回复

使用道具 举报

千问 | 2006-4-17 13:46:34 | 显示全部楼层
谢谢版主:
1)你说的第二种方法我也知道,就是不清楚第一种方法为什么不行
2)我的oracle版本是8.17,符合要求,可还是不行
3)我是在toad里调试,编译不过,错误代码是ora-04021timeout occurred while waitting to lock object过程名
回复

使用道具 举报

千问 | 2006-4-17 13:46:34 | 显示全部楼层
实在不好意思,可能是本机有些问题,重新启动后,在toad里执行好了,谢谢各位
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行