存储过程编译错误

发布于 2024-12-09 07:26:38 字数 1226 浏览 0 评论 0原文

有人可以帮我解决这个问题,这是我运行此脚本时收到的错误消息

 第 1 行出现错误:
    ORA-00979: 不是 GROUP BY 表达式
    ORA-06321: 在“s3398293.P2”,第 7 行
    ORA-06321: 在“s3398293.P2”,第 18 行
    ORA-06321: 在第 1 行

代码:

    create or replace 
    PROCEDURE p2(x NUMBER ) 
    as
        staff_info  staff.bno%TYPE;
        address_info varchar2(20);

            CURSOR c1 IS
                SELECT staff.bno ,
                branch.street || ' ' || branch.suburb || ' ' || branch.postcode 
                FROM deal , staff, contact , property , branch
                where staff.peid = contact.peid
                and contact.pno = property.pno
                and property.pno = deal.pno 
                and staff.peid = branch.peid
                group by staff.bno
                HAVING x > sum(deal.price);

   BEGIN
         OPEN c1;
         LOOP
            FETCH c1 INTO staff_info,address_info ;
            EXIT WHEN c1%notfound;
            dbms_output.put_line('BRANCH# '||' '||'ADDRESS');
            dbms_output.put_line(staff_info ||' '|| address_info);  
         END LOOP;
         close c1;
   END;
   /

有人可以告诉我更多关于 GROUP BY EXPRESSION 的信息吗? ?

Can Someone help me on this , this is the error message I am getting when I run this script

    ERROR at line 1:
    ORA-00979: not a GROUP BY expression
    ORA-06321: at "s3398293.P2", line 7
    ORA-06321: at "s3398293.P2", line 18
    ORA-06321: at line 1

The code:

    create or replace 
    PROCEDURE p2(x NUMBER ) 
    as
        staff_info  staff.bno%TYPE;
        address_info varchar2(20);

            CURSOR c1 IS
                SELECT staff.bno ,
                branch.street || ' ' || branch.suburb || ' ' || branch.postcode 
                FROM deal , staff, contact , property , branch
                where staff.peid = contact.peid
                and contact.pno = property.pno
                and property.pno = deal.pno 
                and staff.peid = branch.peid
                group by staff.bno
                HAVING x > sum(deal.price);

   BEGIN
         OPEN c1;
         LOOP
            FETCH c1 INTO staff_info,address_info ;
            EXIT WHEN c1%notfound;
            dbms_output.put_line('BRANCH# '||' '||'ADDRESS');
            dbms_output.put_line(staff_info ||' '|| address_info);  
         END LOOP;
         close c1;
   END;
   /

Can Someone tell me more about GROUP BY EXPRESSION! ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诠释孤独 2024-12-16 07:26:38

按如下方式更改游标语句(编辑 2!):

            SELECT staff.bno staff_info,
            branch.street || ' ' || branch.suburb || ' ' || branch.postcode address_info
            FROM deal , staff, contact , property , branch
            where staff.peid = contact.peid
            and contact.pno = property.pno
            and property.pno = deal.pno 
            and staff.peid = branch.peid
            group by staff.bno ,
            branch.street || ' ' || branch.suburb || ' ' || branch.postcode 
            HAVING sum(deal.price) < x;

编辑 - 根据注释:

您的 LOOP 应如下所示:

     FOR R IN C1
     LOOP
        staff_info := R.staff_info;
        address_info := R.address_info;
        dbms_output.put_line('BRANCH# '||' '||'ADDRESS');
        dbms_output.put_line(staff_info ||' '|| address_info);  
     END LOOP;

change the cursor statement as follows (EDIT 2!):

            SELECT staff.bno staff_info,
            branch.street || ' ' || branch.suburb || ' ' || branch.postcode address_info
            FROM deal , staff, contact , property , branch
            where staff.peid = contact.peid
            and contact.pno = property.pno
            and property.pno = deal.pno 
            and staff.peid = branch.peid
            group by staff.bno ,
            branch.street || ' ' || branch.suburb || ' ' || branch.postcode 
            HAVING sum(deal.price) < x;

EDIT - as per comments:

Your LOOP should look as follows:

     FOR R IN C1
     LOOP
        staff_info := R.staff_info;
        address_info := R.address_info;
        dbms_output.put_line('BRANCH# '||' '||'ADDRESS');
        dbms_output.put_line(staff_info ||' '|| address_info);  
     END LOOP;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文