public List<MuseumDto> GetMuseumsByName(string museum_Name)
{
var connectionString = ConfigurationManager.
ConnectionStrings["OracleConnectionString"].ConnectionString;
var museum = new List<MuseumDto>();
using (var connection = new OracleConnection(connectionString))
{
OracleCommand mycom = new OracleCommand();
connection.Open();
mycom.CommandText = "museum_package.get_MuseumByName";
mycom.Connection = connection;
mycom.CommandType = CommandType.StoredProcedure;
mycom.Parameters.Add("v_museum", museum_Name);
OracleParameter returnParameteraram = mycom.Parameters.Add("ReturnValue", OracleDbType.RefCursor);
returnParameteraram.Direction = ParameterDirection.ReturnValue;
OracleDataReader reader = mycom.ExecuteReader();
try
{
while (reader.Read())
{
museum.Add(new MuseumDto
{
museumId = reader.GetInt32(0),
name = reader.GetString(1),
city = reader.GetString(2),
about= reader.GetString(3),
schedule = reader.GetString(4),
noArtefacts= reader.GetInt32(5),
});
}
}
finally
{
// always call Close when done reading.
reader.Close();
}
}
return museum;
}
这是表格定义:
create table museum
( museumid number(5) not null
, name varchar2(30)
, city varchar2(30)
, about varchar2(200)
, schedule varchar2(40)
, noartefacts number(3) );
这是我的功能:
create or replace package body museum_package as
function get_MuseumByName
( v_museum Museum.Name%type )
return sys_refcursor
is
v_cursor sys_refcursor;
v_museumName museum.name%type := '%' || v_museum || '%';
begin
open v_cursor for
select museumID, name, city, about, schedule, noArtefacts
from museum
where name like v_museumName;
return v_cursor;
end;
end museum_package;
我收到例外:
ORA-06550:第1行第15栏:
PLS-00306:调用&#39; GET_MUSEUMBYNAME&#39;中的参数数量或类型错误 ORA-06550:第1行第7栏:
PL / SQL:忽略语句
答案 0 :(得分:1)
我无法评论其他人的帖子,因为我没有足够的声誉(我在这里很新)。您的问题可能是因为.NET无法将Oracle中列的类型与您在读取列时指定的列进行映射。
您能否告诉我们博物馆桌子栏目的数据类型?
答案 1 :(得分:0)
必须将返回值添加为第一个参数。
OracleParameter returnParameteraram = mycom.Parameters.Add("ReturnValue", OracleDbType.RefCursor);
returnParameteraram.Direction = ParameterDirection.ReturnValue;
mycom.Parameters.Add("v_museum", museum_Name);