後,我想要得到的值插入在C#中的表,這樣的事情:甲骨文12C:返回記錄插入值
begin
insert into bk_library(floor,section) values('foo2','bar')
returning id into :outid;
select *from bk_library where id=:outid;
end;
不幸的是,我失敗了
錯誤信息:親吻.Linq.Linq2Sql.Test.EntryPoint.TestInsertReturnId: Oracle.DataAccess.Client.OracleException:ORA-06550:線3,列 1:PLS-00428:INTO子句預計在該SELECT語句
[Test] public void TestInsertReturnId() { int ret = 0; string connstring = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=pdborcl)));User Id=system;Password=****;"; string sql = @"insert into bk_library(floor,section) values('foo','bar') returning id into :outid"; sql = getSqlString(); using (DbConnection conn = new OracleConnection(connstring)) { conn.Open(); DbCommand command = conn.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = sql; OracleParameter lastId = new OracleParameter(":outid", OracleDbType.Int32); lastId.Direction = ParameterDirection.Output; command.Parameters.Add(lastId); ret = command.ExecuteNonQuery(); // this code work fine ,now I want to get the entire record LogManager.GetLogger<EntryPoint>().Info("The new id ={0}", lastId.Value.ToString()); conn.Close(); } Assert.AreNotEqual(ret, 0); }
什麼是你真正想幹什麼?你剛剛在數據庫中創建了「行」,並且你已經有了數據,爲什麼再次獲取它?也許看看實體框架或LinqToSql? – flindeberg
在這種情況下,表的主列同一性(http://www.oracle-base.com/articles/12c/identity-columns-in-oracle-12cr1.php)中,當插入一個值不知身份證,現在我想獲得整個記錄。 – Aliceljm
是的,但是您從查詢中獲得了id,爲什麼需要整個記錄?既然你沒有使用任何建模框架? – flindeberg