【发布时间】:2021-12-20 07:32:27
【问题描述】:
这段代码如何运作良好:
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;
第二个 sn-p 我得到的错误是:
PL/SQL: ORA-00934: group function is not allowed here.
错误肯定来自:select count(*) into res, count(distinct t.title_id) into titles,但我不明白为什么在第一个代码 sn-p 中它可以工作,而在第二个代码中却没有。
【问题讨论】: