[PL/SQL] 關於pl/sql編譯報ORA-00934此處不允許使用分組函式 [複製連結]
阿新 • • 發佈:2019-01-01
舉個例子
1、建立兩張表
create table ABC
(
ID NUMBER,
NUM NUMBER,
CUST_NO VARCHAR2(20)
);
create table test
(
ID NUMBER,
NUM NUMBER,
CUST_NO VARCHAR2(20)
);
2、執行如下語句
select count(1) , sum(num),sum(decode(cust_no,'a',1,0)) from abc;
可以成功執行
3、建立一個test1儲存過程
create or replace procedure test1 is
a number;
b number;
c number;
begin
select
count(1) into a,
sum(num) into b,
sum(decode(cust_no,'a',1,0)) into c
from abc;
exception
when others then
begin
rollback;
end;
end test1;
編譯時報ORA-00934此處不允許使用分組函式 錯誤。
4、若將該儲存過程改成插入表結構,不用隱身遊標
create or replace procedure test1 is
a number;
b number;
c number;
begin
insert into test
select
count(1) ,
sum(num) ,
sum(decode(cust_no,'a',1,0))
from abc;
exception
when others then
begin
rollback;
end;
end test1;
該儲存過程編譯成功,執行也成功。或者是顯示遊標也是可以編譯成功和執行成功的。
現在不是很理解為什麼在使用隱形遊標這種方式編譯會報錯,而單獨拿出該語句執行或者用另外一種方式處理就不會報錯呢?請各位大俠指點下