以下函数返回VARCHAR2
数据类型,它可以正常工作:
select Get_Desc("45") from dual;
但是当我尝试使用C#运行时,我在cmd.ExecuteNonQuery()
上收到了错误消息:
ORA-06550:第1行第7列:PLS-00221:'F_GET_DESC'不是程序或未定义ORA-06550:第1行第7列:PL / SQL:语句被忽略
public void Get_Desc()
{
string oradb = "Data Source=source;User Id=myuser;Password=ss;";
string CommandStr = "F_Get_Desc()";
using (OracleConnection conn = new OracleConnection(oradb))
using (OracleCommand cmd = new OracleCommand(CommandStr, conn))
{
conn.Open();
cmd.CommandType = CommandType.StoredProcedure;
OracleParameter pDesc = new OracleParameter("pDesc", OracleDbType.Varchar2,128);
pOfficeDesc.Direction = ParameterDirection.Input;
pOfficeDesc.Value = Current_code.ToString();
cmd.Parameters.Add(pDesc);
cmd.ExecuteNonQuery();
MessageBox.Show(pDesc.Value.ToString(););
}
}
功能代码
CREATE OR REPLACE FUNCTION Schema.F_Get_Desc(P_CODE VARCHAR2)
RETURN VARCHAR2
IS
v_DESC VARCHAR2(64);
BEGIN
IF P_CODE IS NULL THEN
RETURN('');
END IF;
SELECT NAME_dsec
INTO V_DESC
FROM My_table
WHERE CODE = P_CODE;
RETURN(V_DESC);
END;
/
答案 0 :(得分:0)
您是否尝试在命令字符串中指定架构名称?这样的事情。
string CommandStr = "Schema.F_Get_Desc()";
还要确保您登录的用户可以访问该功能并具有正确的授权来执行。如果此函数没有公共同义词,则可能必须在命令字符串中指定模式名称。
答案 1 :(得分:0)
public void Get_Desc()
{
string oradb = "Data Source=schema;User Id=user;Password=pwd;";
string CommandStr = "F_Get_Office_Desc";
using (OracleConnection conn = new OracleConnection(oradb))
using (OracleCommand cmd = new OracleCommand(CommandStr, conn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("iCode", OracleDbType.Varchar2).Value = Current_code;
cmd.Parameters.Add("oDesc", OracleDbType.Varchar2, 4).Direction = ParameterDirection.ReturnValue;
conn.Open();
cmd.ExecuteNonQuery();
Current_Desc.Text = cmd.Parameters["oDesc"].Value.ToString();
}
}