/ Published in: C#
How to set add a record in an Oracle table and return a value in the same query using C#.
Returning ID INTO : OUTPUT_ID is referring to returning the value found in the ID field in the SQL table to the OUTPUT_ID parameter set in the AddStatusCode method.
Returning ID INTO : OUTPUT_ID is referring to returning the value found in the ID field in the SQL table to the OUTPUT_ID parameter set in the AddStatusCode method.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
using Oracle.DataAccess.Client; private const string SqlInsertStatusCode = @"INSERT INTO STATUS_CODES(ID, STATUS_CODE, GROUP_CODE, DESCRIPTION, RANK) VALUES(STATUS_CODE_SEQ1.NEXTVAL, :STATUSCODE, :GROUPCODE, :DESCR, :STATUSCODE_RANK) RETURNING ID INTO :OUTPUT_ID"; public int AddStatusCode(StatusCode statusCode) { OracleParameter[] parameters = { CreateOracleParameter("OUTPUT_ID", null, OracleDbType.Int32,ParameterDirection.Output), CreateOracleParameter("DESCR",SafeDbConvert<string>(statusCode.Description),OracleDbType.Char), CreateOracleParameter("GROUPCODE", SafeDbConvert<string>(statusCode.GroupCode),OracleDbType.Char), CreateOracleParameter("STATUSCODE_RANK", SafeDbConvert<int>(statusCode.Rank),OracleDbType.Int32), CreateOracleParameter("STATUSCODE", SafeDbConvert<int>(statusCode.Status_Code), OracleDbType.Int32), }; ExecuteNonQuery(SqlInsertStatusCode, parameters); return int.Parse(parameters[0].Value.ToString()); }