开发者

Stored Procedure COMPILE Error

开发者 https://www.devze.com 2023-04-12 11:04 出处:网络
Can Someone help me on this , this is the error message I am gett开发者_StackOverflow社区ing when I run this script

Can Someone help me on this , this is the error message I am gett开发者_StackOverflow社区ing 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! ?


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号