I am trying to execute a PL/Sql block by using the OracleClientProvider in .Net . The language I am using is c#, the DB is oracle10g
What I am actually doing is the following :
//ConnectionSting is the connection String
OracleConnection connection = new OracleConnection(connectionString);
OracleCommand cmd = new OracleCommand();
cmd.Connection = connection;
// Open the connection
connection.Open();
//queryFile contains the PL/SQL Script I am trying to execute;
String queryFile = ConfigurationManager.AppSettings["MasterDbScript"];
String dataInFile = new StreamReader(queryFile).ReadToEnd();
cmd.CommandText = dataInFile;
connection.Open();
cmd.ExecuteNonQuery();
//close the connection
connection.close();
The PL/SQL block executes properly when I run it through ORACLE client but over here it throws an error ORA-00922: missing or invalid option
I want to ask :
1. Are the scripts executed in a different way from the normal query?
2. What am I doing wrong ?
Suggestions/Answers
Thanks.
Best Answer
As you are not showing your script to us, lets work the other way around. create a table in your database
and put the following into your script file
After executing your code, you can check if it worked by selecting from the database.
The next step will be to use some begin end; block not returning any result sets.
Generally Ado can't process whole scripts. Using sql-server it can process batches, that are parts of a script separated by go statements. As far as I know for Oracle it can only process a single sql-statements or a begin end block.
Edit: Here is a litte PowerShell you can use to try what is possible:
For example you see, that the following fails ( I added a semicolon):
And this fails too:
In a first approximation you can think of the '/' as similar to the sql-server batch delimiter go.