使用SQL存储函数给出无效的SQL语句 [英] Using SQL stored function gives invalid SQL statement
本文介绍了使用SQL存储函数给出无效的SQL语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在c#应用程序中使用Oracle Express数据库中的存储功能.
I'm trying to use stored function from Oracle Express database in c# application.
OdbcCommand com = new OdbcCommand("SILNIA",sqlConn);
com.CommandType = CommandType.StoredProcedure;
OdbcParameter sqlParam = new OdbcParameter("@ReturnValue", OdbcType.Int);
sqlParam.Direction = ParameterDirection.ReturnValue;
com.Parameters.Add(sqlParam);
com.ExecuteNonQuery();
label1.Content = com.Parameters["@ReturnValue"].Value.ToString();
其中定义了SILNIA函数(无错误编译):
where SILNIA function (compiles without errors) is defined:
create or replace
FUNCTION SILNIA RETURN NUMBER IS
w NUMBER := 1;
BEGIN
for i in 1..5 loop
w:=w*i;
end loop;
RETURN w;
END SILNIA;
在线:
com.ExecuteNonQuery();
我明白了
ERROR [42000] [Microsoft][ODBC driver for Oracle][Oracle]ORA-00900: invalid SQL statement.
但这有效,没有任何问题:
But this works works without any problems:
OdbcCommand sqlCom = new OdbcCommand("SELECT SILNIA() FROM DUAL", sqlConn);
label1.Content = sqlCom.ExecuteScalar().ToString();
推荐答案
您不能使用ExecuteNonQuery()运行SP.您还必须做其他事情-ExecuteScalar或ExecuteReader
You can't use ExecuteNonQuery() to run a SP. You have to do something else -- ExecuteScalar or ExecuteReader
这是因为ExecuteNonQuery()仅设计用于UPDATE,INSERT和DELETE语句.
This is because ExecuteNonQuery() is designed to only work with UPDATE, INSERT, and DELETE statements.
这篇关于使用SQL存储函数给出无效的SQL语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文