在 C# 中的存储过程中使用全局临时表



我想在 Oracle 的过程中使用全局临时表。为此,我创建了一个全局临时表:

CREATE GLOBAL TEMPORARY TABLE temp_test
(id int)
ON COMMIT PRESERVE ROWS;

我也创建了一个程序:

CREATE OR REPLACE PROCEDURE PROC_TEST ( p_recordset OUT SYS_REFCURSOR) AS 
BEGIN
OPEN p_recordset FOR  
SELECT * FROM temp_test;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;    
END PROC_TEST;

当我执行在临时表中插入行的过程时,它正常工作:

INSERT INTO temp_test (id) values(1);
INSERT INTO temp_test (id) values(2);
INSERT INTO temp_test (id) values(3);
INSERT INTO temp_test (id) values(4);
INSERT INTO temp_test (id) values(5);
INSERT INTO temp_test (id) values(6);
INSERT INTO temp_test (id) values(7);
INSERT INTO temp_test (id) values(8);
INSERT INTO temp_test (id) values(9);
INSERT INTO temp_test (id) values(10);
INSERT INTO temp_test (id) values(11);
var c refcursor;
execute proc_test(:c);
print c;

但是当我在 C# 应用程序中运行它时,它不会在此过程中通过以下代码返回任何行:

using (OracleConnection connection = new OracleConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MyContext"].ToString()))
{
connection.Open();
OracleCommand command = connection.CreateCommand();
command.CommandText = "DELETE FROM temp_test";
command.ExecuteNonQuery();
for (int i = 0; i < 10; i++)
{
command.CommandText = string.Format("INSERT INTO TEMP_INT_1(ID_INT) VALUES ({0})", i);
command.ExecuteNonQuery();
}
command.CommandText = "PROC_TEST";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new OracleParameter("p_recordset", OracleType.Cursor)).Direction = ParameterDirection.Output;
OracleDataAdapter adapter = new OracleDataAdapter(command);
DataSet ds = new DataSet();
adapter.Fill(ds);

connection.Close();
}

我应该怎么做才能在 C# 应用程序中正确返回这些行?

我正在寻找TEMP_INT_1表中的插入行并尝试选择TEMP_TEST表,这就是为什么它不起作用。

最新更新