我正在尝试使用 C# 代码将多行插入 DB2 数据库,如下所示:
string query =
"INSERT INTO TESTDB2.RG_Table (V,E,L,N,Q,B,S,P) values" +
"('abc', 'def', '2009-03-27 12:01:19', 'ghi', 'jkl', NULL, NULL, NULL)," +
"('abc', 'def', '2009-03-27 12:01:19', 'ghi', 'jkl', NULL, NULL, NULL)";
DB2Command cmd = new DB2Command(query, this.connection, this.transaction);
cmd.ExecuteNonQuery();
如果我在第一组值之后停止构建查询字符串,它会在没有错误的情况下执行。尝试使用此方法加载多个值会导致以下错误:
Upload error : ERROR [42601] [IBM][DB2] SQL0104N
An unexpected token "," was found following "".
Expected tokens may include: "<END-OF-STATEMENT>". SQLSTATE=42601
SQL 语法与我在其他地方读到的相匹配, IBM 的文档给出了这个例子:
cmd = conn.CreateCommand();
cmd.Transaction = trans;
cmd.CommandText =
"INSERT INTO company_a VALUES(5275, 'Sanders', 20, 'Mgr', 15, 18357.50), " +
"(5265, 'Pernal', 20, 'Sales', NULL, 18171.25), " +
"(5791, 'O''Brien', 38, 'Sales', 9, 18006.00)";
cmd.ExecuteNonQuery();
谁能解释什么可以解释这一点?