programing

C#에서 단일 Oracle 명령어로 여러 쿼리 실행

lovejava 2023. 11. 5. 10:47

C#에서 단일 Oracle 명령어로 여러 쿼리 실행

저는 비주얼 스튜디오 2013과 오라클 데이터베이스를 사용하고 있습니다.여러 개의 생성 테이블 쿼리를 한 번에 단일 오라클 명령으로 실행하고 싶은데 가능합니까?저는 팔로우를 시도하고 있지만 일을 하지 않습니다.

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에서 오류가 발생했습니다.비쿼리 실행();

두 개 이상의 명령을 실행하려면 해당 명령을 입력합니다.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();

자세한 정보:Oracle.ODP를 사용하여 SQL 스크립트 실행

해보셨습니까?

cmd.CommandText = "create table test(name varchar2(50) not null);"+"create table test2(name varchar2(50) not null);";

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