在C#中的单个Oracle命令中执行多个查询

我正在使用visual studio 2013和oracle数据库.我希望在单个oraclecommand中同时执行多个创建表查询是否可能?我正在尝试跟随但不工作

OracleCommand cmd = new OracleCommand();
cmd.Connection = con;
cmd.CommandText = "create table test(name varchar2(50) not null)"+"create table test2(name varchar2(50) not null)"; 
//+ "create table test3(name varchar2(50) not null)"+"create table test3(name varchar2(50) not null)";
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();

cmd.ExecuteNonQuery();出错

为了执行多个命令,将它们放在begin … end中;块.
对于DDL语句(如create table),使用execute immediate运行它们.这段代码对我有用:

OracleConnection con = new OracleConnection(connectionString);
con.Open();

OracleCommand cmd = new OracleCommand();
cmd.Connection = con;
cmd.CommandText =
    "begin " +
    "  execute immediate 'create table test1(name varchar2(50) not null)';" +
    "  execute immediate 'create table test2(name varchar2(50) not null)';" +
    "end;";
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
con.Close();

更多信息:Executing SQL Scripts with Oracle.ODP

https://stackoverflow.com/questions/31917301/execute-multiple-queries-in-single-oracle-command-in-c-sharp

转载注明原文:在C#中的单个Oracle命令中执行多个查询