Basmeh Awad
Basmeh Awad

Reputation: 3

Create Oracle Procedure using C#

I am creating procedure using C#

str = @"create or replace procedure awad
                        (O_MSG          OUT    VARCHAR2)
                        is
                        begin
                        O_MSG:='Executed Awad';
                        end;
                        ";
store_cmd = new OracleCommand(str, store_con);
store_cmd.ExecuteNonQuery();

no error in running this from my code but The procedure is creating as Invalid and when i compile it in Toad it is showing me the following error

PROCEDURE 08903.AWAD On line: 1 PLS-00103: Encountered the symbol "" when expecting one of the following: ( ; is with authid as cluster compress order using compiled wrapped external deterministic parallel_enable pipelined The symbol "" was ignored.

if i copy the same code and run it in Toad editor its getting Compile without any error

Upvotes: 0

Views: 572

Answers (2)

erikkallen
erikkallen

Reputation: 34401

When I last used Oracle (although it was like 10 years ago), these errors would often happen because of CRLF in the SQL. Try

str = @"create or replace procedure awad
                    (O_MSG          OUT    VARCHAR2)
                    is
                    begin
                    O_MSG:='Executed Awad';
                    end;
                    ".Replace("\r\n", "\n");

(although I must say that it if this is the issue, it is extremely unimpressive by them not to have fixed this issue in 10+ years).

Upvotes: 1

Stefan Yordanov
Stefan Yordanov

Reputation: 666

You should escape ' (single quote) with '' ( two single quotes). Try this code:

str = @"create or replace procedure awad
                        (O_MSG          OUT    VARCHAR2)
                        is
                        begin
                        O_MSG:=''Executed Awad'';
                        end;
                        ";
                store_cmd = new OracleCommand(str, store_con);
                store_cmd.ExecuteNonQuery();

Upvotes: 0

Related Questions