异常不是!如果是 select count(*) into :ncount from tablename where 条件; 结果是返回0; select count(*) into :ncount from tablename where 条件 group by field; 结果是空。所以版主说的没错!
wupangzi(无本之木) ,怎么不是异常??!!我可是特意做了试验的,你试过吗?
用 Group By 语句有可能有多行出现. ---------------------------------------------------- 测试... 建表: SQL>create table abc(id number(2),name varchar(10)); SQL>insert into abc(id,name)values('1','a'); SQL>insert into abc(id,name)values('2','b'); SQL>insert into abc(id,name)values('3','c');SQL>var nCount number; -- 定义变量 SQL> begin 2 select count(*) into :nCount from abc; 3 end; 4 /PL/SQL 过程已成功完成。SQL> print :nCount; NCOUNT ---------- 3SQL> begin 2 select count(*) into :nCount from abc group by id; 3 end; 4 / begin * ERROR 位于第 1 行: ORA-01422: 实际返回的行数超出请求的行数 ORA-06512: 在line 2
一清二楚.在用 分组函数(Max,Mix,Count...)时,用 Group By 语句,不只一行.
第一句会把ncount赋值 为0,
但第二句不对ncount进行赋值?(即保持原值)这是为什么呢?
select count(*) into :ncount from tablename where 条件;
结果是返回0;
select count(*) into :ncount from tablename where 条件 group by field;
结果是空。所以版主说的没错!
----------------------------------------------------
测试...
建表:
SQL>create table abc(id number(2),name varchar(10));
SQL>insert into abc(id,name)values('1','a');
SQL>insert into abc(id,name)values('2','b');
SQL>insert into abc(id,name)values('3','c');SQL>var nCount number; -- 定义变量
SQL> begin
2 select count(*) into :nCount from abc;
3 end;
4 /PL/SQL 过程已成功完成。SQL> print :nCount; NCOUNT
----------
3SQL> begin
2 select count(*) into :nCount from abc group by id;
3 end;
4 /
begin
*
ERROR 位于第 1 行:
ORA-01422: 实际返回的行数超出请求的行数
ORA-06512: 在line 2