我的.net C# console app
var SGCodProdInsert = new OracleCommand
{
Connection = con,
CommandText = ProductFirstInsert,
CommandTimeout = 15,
Transaction = dbContextTransaction
};
var t = SGCodProdInsert.ExecuteNonQuery();
我传递的Oracle
命令(ProductFirstInsert
)是这样的:
BEGIN
INSERT INTO Products_TEST (ProductName,ProductCode) VALUES ('TEST','TEST');
INSERT INTO Products_TEST (ProductName,ProductCode) VALUES ('TEST1','TEST1');
INSERT INTO Products_TEST (ProductName,ProductCode) VALUES ('TEST2','TEST2');
INSERT INTO Products_TEST (ProductName,ProductCode) VALUES ('TESTn','TESTn');
END;
结果t
我得-1,我明白为什么......所以我的问题如下:
如何从单个整数中获取从oracle过程在表中插入了多少条记录?
答案 0 :(得分:1)
最简单的方法是在命令之前和之后执行count(*)
命令:
var SGCodProdInsert = new OracleCommand
{
Connection = con,
CommandText = ProductFirstInsert,
CommandTimeout = 15,
Transaction = dbContextTransaction
};
var CountTable = new OracleCommand
{
Connection = con,
CommandText = "select count(*) from Products_TEST",
CommandTimeout = 15,
Transaction = dbContextTransaction
};
decimal beforeInsert = Convert.ToDecimal(CountTable.ExecuteScalar());
SGCodProdInsert.ExecuteNonQuery();
decimal afterInsert = Convert.ToDecimal(CountTable.ExecuteScalar());
Console.WriteLine($"Inserted rows: {afterInsert - beforeInsert}");
否则你必须创建一个临时的Oracle函数并阅读SQL%ROWCOUNT
答案 1 :(得分:0)
对于UPDATE,INSERT和DELETE语句,返回值是该命令影响的行数。对于所有其他类型的语句,返回值为-1。
微软自己的医生在说。