Scuba Steve
Scuba Steve

Reputation: 1648

PL/SQL invalid cursor error

So I really don't have any idea why my cursor isn't working. The select statement works fine, so I'm not sure why the SQL server is throwing the error. The For loop has an implicit open and close, so that shouldn't be the problem either. Any ideas?

DECLARE
   var_lname customer.c_last%TYPE;
   var_fname customer.c_first%TYPE;
   var_addr customer.c_address%TYPE;
   var_phone customer.c_dphone%TYPE;
   CURSOR expl_cursor IS SELECT c_last, c_first, c_address, c_dphone from customer;
   cust_record expl_cursor%ROWTYPE;

BEGIN

   DBMS_OUTPUT.PUT_LINE('ClearWater Traders Mailing List');
   FOR cust_record IN expl_cursor
   LOOP
      FETCH expl_cursor INTO cust_record;
      var_lname := cust_record.c_last;
      var_fname := cust_record.c_first;
      var_addr := cust_record.c_address;
      var_phone := cust_record.c_dphone;
      DBMS_OUTPUT.PUT_LINE(var_lname || ' ' || var_fname || ' ' ||
      var_addr || ' ' || var_phone);
   END LOOP;
END;

Here's the error:

ERROR at line 1: ORA-01001: invalid cur ORA-06512: at line 15

Upvotes: 0

Views: 1509

Answers (1)

Scuba Steve
Scuba Steve

Reputation: 1648

Ah I solved this. Can't do a FETCH inside a for loop. Since the cursor is incremented automatically.

Upvotes: 2

Related Questions