Home » SQL & PL/SQL » SQL & PL/SQL » error rises as INVALID CURSOR (ORACLE 10G, WINDOWS 7)
icon5.gif  error rises as INVALID CURSOR [message #588852] Fri, 28 June 2013 22:52 Go to next message
gowthamsanj
Messages: 18
Registered: June 2013
Location: tirupur
Junior Member
HI Razz
I AM NEW TO PL SQL, WHILE DEVELOPING PLSQL I FACE CERTAIN ERROR, I HOPE SOME OF EXPERTS WILL HELP ME
THANK YOU

CODING
CREATE OR replace PROCEDURE Ph 
IS 
  CURSOR c_ph IS 
    SELECT * 
    FROM   emp; 
  emp_rec emp%ROWTYPE; 
  mb      VARCHAR(40); 
  eid     NUMBER; 
BEGIN 
    OPEN c_ph; 

    LOOP 
        FETCH c_ph INTO emp_rec; 

        eid := emp_rec.employee_id; 

        mb := '+91 ' 
              ||Substr(emp_rec.phone_number, 1, 3) 
              ||'-' 
              ||Substr(emp_rec.phone_number, 5, 3) 
              ||'-' 
              ||Substr(emp_rec.phone_number, 9, 3); 

        UPDATE emp 
        SET    ph_new = mb 
        WHERE  employee_id = eid; 

        COMMIT; 

        exit WHEN c_ph%NOTFOUND; 

        CLOSE c_ph; 
    END LOOP; 
END; 

/ 

ERROR RAISED

declare
*
ERROR at line 1:
ORA-01001: invalid cursor
ORA-06512: at line 11

[EDITED by LF: formatted code & applied [code] tags]

[Updated on: Sat, 29 June 2013 03:06] by Moderator

Report message to a moderator

Re: error rises as INVALID CURSOR [message #588853 is a reply to message #588852] Fri, 28 June 2013 22:54 Go to previous messageGo to next message
gowthamsanj
Messages: 18
Registered: June 2013
Location: tirupur
Junior Member
I HAVE TO SAY ONE MORE THING THAT EMP TABLE IS A COPY OF HR - EMPLOYEES TABLE
AND THE PROCEDURE WAS CREATED SUCCESSFULLY
Re: error rises as INVALID CURSOR [message #588854 is a reply to message #588853] Fri, 28 June 2013 23:04 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please explain what you see below
[oracle@localhost ~]$ sqlplus hr/hr

SQL*Plus: Release 11.2.0.2.0 Production on Fri Jun 28 21:01:49 2013

Copyright (c) 1982, 2010, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create or replace view emp as select * from employees;

View created.

SQL> set term on echo on
SQL> create or replace procedure ph
is
cursor c_ph is select * from emp;
emp_rec emp%rowtype;
mb varchar(40);
eid number;
begin
open c_ph;
loop
fetch c_ph into emp_rec;
eid:=emp_rec.employee_id;
mb:='+91 '||substr(emp_rec.phone_number,1,3)||'-'||substr(emp_rec.phone_number,5,3)||'-'||substr(emp_rec.phone_number,9,3);
update emp set ph_new=mb where employee_id=eid;
commit;
exit when c_ph%notfound;
close c_ph;
end loop;
end;
/  2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17   18   19  

Warning: Procedure created with compilation errors.

SQL> show error
Errors for PROCEDURE PH:

LINE/COL ERROR
-------- -----------------------------------------------------------------
13/1     PL/SQL: SQL Statement ignored
13/16    PL/SQL: ORA-00904: "PH_NEW": invalid identifier
SQL> 




Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/
Re: error rises as INVALID CURSOR [message #588855 is a reply to message #588854] Fri, 28 June 2013 23:08 Go to previous messageGo to next message
gowthamsanj
Messages: 18
Registered: June 2013
Location: tirupur
Junior Member
sorry to inform this before : ph_new is a new column created in emp table as varchar2(40)
Re: error rises as INVALID CURSOR [message #588856 is a reply to message #588855] Fri, 28 June 2013 23:20 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/

I refuse to continue to guess what you have.
Do NOT use PL/SQL when plain SQL can accomplish same results.
Good Luck with debugging your code.
You're On Your Own (YOYO)!
Re: error rises as INVALID CURSOR [message #588860 is a reply to message #588855] Sat, 29 June 2013 00:30 Go to previous messageGo to next message
Michel Cadot
Messages: 68765
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
gowthamsanj wrote on Sat, 29 June 2013 06:08
sorry to inform this before : ph_new is a new column created in emp table as varchar2(40)


So post the CREATE TABLE statement for your table so we can reproduce what you have.
Use SQL*Plus and copy and paste your session, the WHOLE session.

Before, Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" or "Preview Quick Reply" button to verify.
Also always post your Oracle version, with 4 decimals.

And do NOT post in UPPER case.

Regards
Michel

[Updated on: Sat, 29 June 2013 00:31]

Report message to a moderator

Re: error rises as INVALID CURSOR [message #588873 is a reply to message #588860] Sat, 29 June 2013 03:10 Go to previous messageGo to next message
Littlefoot
Messages: 21825
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
A problem, as I see it (after code has been formatted) is that it looks like this:
declare cursor ...
begin
  open cursor
  loop
    fetch
    do something
    exit when 
    close cursor          --> this is a culprit
  end loop
end

If you didn't get it, here you go: everything goes OK for the first loop round. Then - within the loop - you closed the cursor. The second loop round tries to fetch from a closed cursor. As you can't do that, you got the error.

Therefore, move CLOSE outside the loop.
Re: error rises as INVALID CURSOR [message #588929 is a reply to message #588873] Sun, 30 June 2013 01:01 Go to previous messageGo to next message
gowthamsanj
Messages: 18
Registered: June 2013
Location: tirupur
Junior Member
problem solved , thank you 'Lie to me'
Re: error rises as INVALID CURSOR [message #588930 is a reply to message #588929] Sun, 30 June 2013 01:02 Go to previous message
gowthamsanj
Messages: 18
Registered: June 2013
Location: tirupur
Junior Member
thank you littlefooot
Previous Topic: Cumulative Sum of previous row in the same column
Next Topic: CREATE PROCEDURE
Goto Forum:
  


Current Time: Sat Aug 09 02:14:21 CDT 2025