Lisa
Lisa

Reputation: 3181

Variable can't be used outside SQL statement

Hey I'm building this stored procedure:

        CREATE OR REPLACE procedure fillCompanyWH
        IS
        cursor c is select other_line_key from line_contact;
        cursor e is select max(comp_id) + 1 from Company_WH;
        r c%ROWTYPE;
        count PLS_INTEGER:=0;
        rr NUMBER(9);
        BEGIN
                open c; 
                open e;
                    fetch e into rr;
                    if(rr is null) THEN
                        rr:=1;
                    end if;
                count:= rr;
                loop    
                    count :=count + 1;              
                fetch c into r;
                exit when c%NOTFOUND;
                        insert into Company_WH (comp_id, comp_key) values (count,r.other_line_key);
                end loop;

                    close c;
                    close e;
        END;
        /

It keeps giving me an error about this line (count :=count + 1; ) the error says that (Statement ignored function or pseudo-column 'COUNT' may be used inside a SQL statement only).

Why??

Upvotes: 0

Views: 828

Answers (2)

Trott
Trott

Reputation: 70075

COUNT is a reserved word so you cannot use it for your variable identifier. Change it to something else.

Upvotes: 4

Aditya
Aditya

Reputation: 116

COUNT is inbuilt function. Try renaming your variable.

Upvotes: 2

Related Questions