Oracle SQL - 此处不允许使用组函数
Oracle SQL - Group function not allowed here
这段代码如何运行良好:
select count(distinct t.title_id), count(*)
from member m, rental r, title t
where m.member_id = r.member_id
and r.title_id = t.title_id
and m.first_name = 'Carmen'
and m.last_name = 'Velasquez';
这不是:
set serveroutput on;
DECLARE
lst_name employees.last_name%TYPE := '&lst';
fst_name employees.first_name%TYPE := '&fst';
res NUMBER(3);
titles NUMBER(3);
BEGIN
select count(*) into res, count(distinct t.title_id) into titles
from member m, rental r, title t
where m.member_id = r.member_id
and r.title_id = t.title_id
and m.first_name = fst_name
and m.last_name = lst_name;
dbms_output.put_line(fst_name || ' ' || lst_name || ':' || res || ' number of titles: ' || titles);
END;
我得到的第二个片段的错误是:
PL/SQL: ORA-00934: group function is not allowed here
.
错误肯定来自:select count(*) into res, count(distinct t.title_id) into titles
,但我不明白为什么在第一个代码片段中有效,但在第二个代码片段中却无效。
语法错误。 select
第一,into
其次
select count(*), count(distinct t.title_id)
into res, titles
from ...
这段代码如何运行良好:
select count(distinct t.title_id), count(*)
from member m, rental r, title t
where m.member_id = r.member_id
and r.title_id = t.title_id
and m.first_name = 'Carmen'
and m.last_name = 'Velasquez';
这不是:
set serveroutput on;
DECLARE
lst_name employees.last_name%TYPE := '&lst';
fst_name employees.first_name%TYPE := '&fst';
res NUMBER(3);
titles NUMBER(3);
BEGIN
select count(*) into res, count(distinct t.title_id) into titles
from member m, rental r, title t
where m.member_id = r.member_id
and r.title_id = t.title_id
and m.first_name = fst_name
and m.last_name = lst_name;
dbms_output.put_line(fst_name || ' ' || lst_name || ':' || res || ' number of titles: ' || titles);
END;
我得到的第二个片段的错误是:
PL/SQL: ORA-00934: group function is not allowed here
.
错误肯定来自:select count(*) into res, count(distinct t.title_id) into titles
,但我不明白为什么在第一个代码片段中有效,但在第二个代码片段中却无效。
语法错误。 select
第一,into
其次
select count(*), count(distinct t.title_id)
into res, titles
from ...