Link to home
Start Free TrialLog in
Avatar of wpeterb
wpeterb

asked on

Oracle stored procedure with Sys_refcursor output, Lightswitch, Devart Entity Framework, Toad

I am calling an insert procedure through Microsoft Lightswitch app, and I get this error:

ORA-06550: line 29, column 8:
PLS-00103: Encountered the symbol "SP_MUSIC_INS" when expecting the following:

The procedure is an oracle procedure returning a sys_refcursor.  It has been mapped through DEVART entity framework 4 to work with Lightswitch app as a RIA service.

To test the oracle procedure works, I am trying to run it from oracle.  When I walk through Debug everything is good and the refcursor parameter indicates 1iteration. (Can't see vaule due to it being a refcursor.)

What did I do wrong?   How do I get it to run correctly in Toad?  How do you test a sys_refcursor in SQLPLUS?  Did I miss something in a refcursor setup step in TOAD and in Entity Framework causing this error?

Here is the script I am executing in Toad for the refcursor but I get an the error an not the ability to define the ref_CURSOR AS A CURSOR.
DECLARE
p_Music_GENRE_DESC                  Music.GENRE_DESC%TYPE;
p_SERIES_IND                        Music.SERIES_IND%TYPE;
p_Music_GENRE_CODE_RC                sys_refcursor;

BEGIN
  p_Music_GENRE_DESC := 'Test\Proc Test';
  p_SERIES_IND := 'N';
--  p_Music_GENRE_CODE_RC := null;

  exec SP_MUSIC_INS (p_Music_GENRE_DESC,p_SERIES_IND,:p_Music_GENRE_CODE_RC);
  COMMIT;
END;


Here is how I am calling and assigning the sys_refcursor output.
   )
     RETURNING Music_CODE into p_Music_GENRE_SEQ;
     
     COMMIT;

open p_Music_GENRE_CODE_RC for select p_Music_GENRE_SEQ as p_Music_GENRE_SEQ from dual;

Thank you,

Carol
Avatar of johnsone
johnsone
Flag of United States of America image

Not sure I can help with your other issues, but your question of how do I see the information in a ref cursor in SQL*Plus, I think I can help you with.

This way should work with the way you have your code written.  There are other easier ways if you are using a function that returns a sys_refcursor, rather than having it be an out parameter.

var v_rc sys_refcursor
exec sp_music_ins('Test\Proc Test','N',v_rc);
print v_rc;

Open in new window

Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

>>PLS-00103: Encountered the symbol "SP_MUSIC_INS" when expecting the following:

The reason for this error is the EXEC inside a pl/sql block.  The EXEC is a sqlplus command not a pl/sql command.

As soon as the issue the begin...end; you are inside pl/sql.  Just remove the EXEC.
I agree that the word "exec" in a PL\SQL procedure is not needed or allowed there.  I also wonder about the "commit;" on the next line.  That will not cause an error, but is it needed?  It will add at least a small performance impact, and it could cause unexpected problems if the application has made any changes prior to this call and if the user does not expect those changes to be committed automatically, or if the user (or the application) assumes that earlier changes could still be rolled back.

On the concept of using "ref-cursors": this is one of the fundamental design differences between Oracle and SQL Server.  In SQL Server (and in Microsoft tools) it is expected that a database stored procedure will handle the database cursor and will return a record set to the application.  Historically in Oracle, it was assumed that the application would submit SQL queries directly and that the application would manage the resulting record set  (without depending on a database stored procedure for this functionality).  Oracle has added support for "ref cursors" in PL\SQL (probably because programmers familiar with Microsoft tools asked for that functionality) but that doesn't mean that "ref cursors" are easy to work with in the various Oracle tools.
ASKER CERTIFIED SOLUTION
Avatar of David VanZandt
David VanZandt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wpeterb

ASKER

Thank you.  I removed the Execute immediate from within procedure.
Avatar of wpeterb

ASKER

Quick response and the answer solved the problem.