ODP.NET:我如何从动态sql数据集中获取数据
我的应用程序使用TimesTen DB来存储数据。 以下是我的代码来更新数据并返回更新的行。
conn = new OracleConnection("My Connection");
conn.Open();
OracleTransaction tran = conn.BeginTransaction(IsolationLevel.ReadCommitted);
OracleCommand command = new OracleCommand();
command = new OracleCommand(@"DECLARE idNo NUMBER;
BEGIN
select id into idNo from " + prefix_db + @"tbl_request_in where upper(status)='PENDING' and ROWNUM <= 1 order by priority, id FOR update;
update " + prefix_db + @"tbl_request_in set status ='Processing',begin_time= SYSDATE(),response_node='10.9.70.47'
where upper(status) <> 'PROCESS' and upper(status) <> 'PROCESSING' and upper(status) <> 'OK' and upper(status)<>'ERROR'
and id=idNo;
OPEN :RETURNCURSOR for select * from APITT_tbl_request_in where id=idNo;
END;", conn);
command.Transaction = tran;
command.BindByName = true;
OracleParameter outNumPrm = command.Parameters.Add("RETURNCURSOR", OracleDbType.RefCursor, DBNull.Value, ParameterDirection.ReturnValue);
// create a data adapter to use with the data set
OracleDataAdapter da = new OracleDataAdapter(command);
// create the data set
DataSet ds = new DataSet();
// fill the data set
da.Fill(ds);
我给错误了
{Oracle.DataAccess.Client.OracleException ORA-01722:无效号码
在Oracle.DataAccess.Client.OracleException.HandleError上的Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode,OracleConnection conn,IntPtr opsErrCtx,OpoSqlValCtx * pOpoSqlValCtx,Object src,String procedure,Boolean bCheck)(Int32 errCode,OracleConnection conn, IntPtr opsErrCtx,Object src,Boolean bCheck)在System.Data.Common.DataAdapter.FillFromReader(DataSet数据集,DataTable)上的System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping映射)上的Oracle.DataAccess.Client.OracleDataReader.Read()在Oracle.DataAccess上System.Data.Common.DataAdapter.Fill(DataSet数据集,字符串srcTable,IDataReader数据读取器,Int32 startRecord,Int32 maxRecords)上的DataTable,String srcTable,DataReaderContainer dataReader,Int32 startRecord,Int32 maxRecords,DataColumn parentChapterColumn,Object parentChapterValue) .Client.OracleDataAdapter.Fill(DataSet dataSet,String srcTable,IDataReader dataReader,Int32 startRecord,Int32 maxRecords)at Oracle.DataAccess.Client.Or System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)中的acleDataAdapter.Fill(DataSet dataSet,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand command,CommandBehavior行为)
我该如何解决它?
匿名PL / SQL块不能返回任何值。 写一个这样的函数:
CREATE OR REPLACE FUNCTION APITT_tbl_request(prefix_db IN VARCHAR2) RETURN SYS_REFCURSOR AS
idNo NUMBER;
res SYS_REFCURSOR;
BEGIN
EXECUTE IMMEDIATE 'SELECT ID '
||'FROM '|| prefix_db || 'tbl_request_in '
||'WHERE UPPER(status)=''PENDING'' AND ROWNUM <= 1 ORDER BY priority, ID FOR UPDATE'
INTO idNo;
EXECUTE IMMEDIATE 'UPDATE '|| prefix_db || 'tbl_request_in SET status =''Processing'', begin_time= :bt, response_node=''10.9.70.47'' '
||'WHERE UPPER(status) <> ''PROCESS'' AND UPPER(status) <> ''PROCESSING'' AND UPPER(status) <> ''OK'' AND UPPER(status)<>''ERROR'' AND ID= :id'
USING SYSDATE, idNo
OPEN res FOR SELECT * FROM APITT_tbl_request_in WHERE ID=idNo;
RETURN res;
END;
并像这样调用这个函数
DataTable dt = new DataTable();
OracleCommand command = new OracleCommand(@"BEGIN :RETURNCURSOR := APITT_tbl_request(:prefix_db); END;");
command.CommandType = CommandType.Text;
command.Parameters.Add("RETURNCURSOR", OracleDbType.RefCursor, ParameterDirection.ReturnValue);
command.Parameters.Add("prefix_db", OracleDbType.Varchar2, ParameterDirection.Input).Value = prefix_db;
OracleDataAdapter da = new OracleDataAdapter(command);
da.Fill(dt);
如果您不能在数据库中创建函数,请尝试替换字符串APITT_tbl_request(:prefix_db);
与函数体,但我不知道这是否工作。
上一篇: ODP.NET: How can i get data from dynamic sql to dataset
下一篇: Data is not inserting oracle table using ODP.NET through asp.net