【问题标题】:Oracle SQL - Group function not allowed hereOracle SQL - 此处不允许使用组功能
【发布时间】: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 中它可以工作,而在第二个代码中却没有。

【问题讨论】:

    标签: sql oracle plsql


    【解决方案1】:

    语法错误。 select 第一,into 下一个

    select count(*), count(distinct t.title_id)
    into res, titles
    from ...
    

    【讨论】:

    • 非常感谢!
    猜你喜欢
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    • 2020-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多