1

I am trying to run this C# code

string sql = @"EXECUTE GETEMPLOYEES1()";

OracleCommand cmd = new OracleCommand(sql, cnn);
cmd.CommandType = CommandType.Text;

cmd.ExecuteNonQuery();

but I keep getting

Invalid SQL error

My stored procedure code is very simple

CREATE OR REPLACE PROCEDURE GETEMPLOYEES1 
AS 
BEGIN
    DBMS_OUTPUT.PUT_LINE('Welcome to FYICenter!'); 
END;  

I am able to run it normally by using CommandType = StoredProcedure but I need to execute some dynamic code entered by the user and it is vital to me to do it by CommandType = Text.

2
  • Do you need an additional ; on the end of your sql variable. ie. @"EXECUTE GETEMPLOYEES1();"; Commented Sep 10, 2015 at 14:55
  • i just tried string sql = @"CALL GETEMPLOYEES1()"; and that worked fine . I find that strange because i know EXEC should work . Commented Sep 10, 2015 at 15:01

2 Answers 2

1

EXECUTE is a SQL*Plus command. Use either

CALL GETEMPLOYEES1()

or

BEGIN GETEMPLOYEES1(); END;

Also if you choose command type StoredProcedure the library adds BEGIN ... END; internally for you.

CALL also requires empty parentheses when a procedure is parameterless.

Sign up to request clarification or add additional context in comments.

1 Comment

you are right , i was able to execute it with call , do you know how to do it when we pass a ref cursor to the proc also ?
0

Try replacing DBMS_OUTPUT.PUT_LINE('Welcome to FYICenter!'); with null;, and see if that makes it any different. Im asuming in connection context there is no sense to try to output text, there is no console.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.