public ActionResult<object> Try()
OracleConnection conn = (OracleConnection)_context.Database.GetDbConnection();
if (conn.State != ConnectionState.Open)
conn.Open();
var cmd = conn.CreateCommand();
cmd.CommandText = "select * from mytable fetch first 1 rows only";
var result = new List<string>();
using (OracleDataReader reader = cmd.ExecuteReader())
while (reader.Read())
result.Add(reader.GetName(0)+": "+reader.GetValue(0).ToString());
return string.Join(',',result);
}
然后执行以下操作:
1创建和填写表:
create table mytable (f1 number(10), f2 varchar2(10));
insert into mytable values (32,'32');
grant select on mytable to myuser;
2呼吁行动:
http://localhost/MyController/Try
// output is okay:
// F1: 32
3然后:
alter table mytable add f3 varchar2(5) default ('f3') null;