CREATE Oracle Procedure

跟風遠走 提交于 2019-11-29 14:52:40

You cannot explicity OPEN the cursor and also use it in an implicit FOR loop. You much choose either implicit (FOR loop) or explicit(OPEN/FETCH/CLOSE).

If you use a cursor with a FOR/IN/LOOP, you don't need to open it explictly. Just write:

SQL> CREATE OR REPLACE PROCEDURE Update_STUD_Fin ( AIDY_CODE IN VARCHAR2 ) IS
  2    CURSOR PublicationC IS
  3      SELECT SGidm from SGB
  4       WHERE SGCODE_EFF ='201030';
  5  BEGIN
  8    FOR PublicationR IN PublicationC
  9    LOOP
 10      DBMS_OUTPUT.PUT_LINE( PublicationR.SGidm );
 11    END LOOP;
 12  
 15  END;
 16  /

6512 Error message indicates the line number in PL-SQL code that the error resulted. Are you sure you don't have another message before ?

I don't know why you're getting an ORA-06512 message with no other error message above it. Are you sure you have pasted the entire error message?

ORA-06512 is only used when printing out stack traces when an exception is raised in PL/SQL code. Here's a complete example:

ERROR at line 1:
ORA-01001: invalid cursor
ORA-06512: at "USER.SOME_PROCEDURE", line 5
ORA-06512: at line 1

The real error here is the ORA-01001. The ORA-06512s merely state where the error occurred: on line 5 of USER.SOME_PROCEDURE, which was called by line 1 of an anonymous PL/SQL block.

Taking a look at your code, I can spot a couple of problems:

  • When using FOR ... IN some_cursor LOOP ... then you should not explicitly open and close the cursor. That will be done for you automatically by the FOR loop.

  • You should also not attempt to close a cursor that hasn't been opened. If you try to do this, you'll get an ORA-01001 'invalid cursor' error message. I'm guessing you've put this in to ensure that the cursor was closed before you opened it, but unfortunately you can't do that.

In short, you should delete all of the OPEN and CLOSE statements from your procedure and try again.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!