使用asp.net调用oracle存储过程。视觉工作室2005
我们有一个驻留在 oracle 10.2 数据库中的 oracle 存储过程。存储的过程包含某些输入和输出参数。我们正在尝试创建一个 ASP.NET Web 应用程序来执行存储过程并将来自输出参数的结果绑定到网格视图中。但没有运气。
这是我到目前为止所做的
Oracle.DataAccess.dll
我使用 Oracle Developer Tools for Visual Studio 安装了 Oracle 数据访问组件 (ODAC),并用它来调用 Oracle 存储过程。
** 这是我收到的错误 **
ORA-06550: 第 1 行,第 7 列:
PLS-00306:调用“CALC_NUMBERVOTES”时参数数量或类型错误
ORA-06550: 第 1 行,第 7 列:
PLS-00306:调用“CALC_NUMBERVOTES”时参数数量或类型错误
ORA-06550: 第 1 行,第 7 列:
PLS-00306:调用“CALC_NUMBERVOTES”时参数数量或类型错误
ORA-06550: 第 1 行,第 7 列:
PLS-00306:调用“CALC_NUMBERVOTES”时参数数量或类型错误
ORA-06550: 第 1 行,第 7 列:
PL/SQL:语句被忽略
非常感谢任何帮助。
oralce 存储过程代码
PROCEDURE calc_numbervotes (
i_Office IN ELECTIONRESULTS.office%TYPE,
o_candidate OUT tblcandidate ,
o_party OUT tblparty,
o_votes OUT tblvotes,
o_percAll OUT tblpercAll)
IS
/***************Find Number of candidate per office and party******************/
CURSOR c1 is
SELECT distinct candidate, party,sum(votes) totalvotes
FROM ELECTIONRESULTS
WHERE candidate not in ('Registered Voters' )
AND office = i_office
AND Precinct <> ' '
GROUP BY candidate,party
ORDER BY sum(votes) desc;
/****************** Find total county votes per candidate *********************/
CURSOR c2 is
SELECT sum(votes) from ELECTIONRESULTS
WHERE candidate !='Registered Voters'
AND office = i_Office
AND Precinct <> ' ';
recCount NUMBER DEFAULT 0;
totvotesall NUMBER;
totvotescandidateprec NUMBER;
BEGIN
OPEN c2;
FETCH c2 into totvotesall;
CLOSE c2;
************************************************************/
FOR rec in c1 LOOP
recCount:= recCount + 1;
o_candidate(recCount):= rec.candidate;
o_party(recCount) := rec.party;
o_votes(recCount) := rec.totalvotes;
if rec.totalvotes = 0 then
o_percAll(recCount) := 0;
else
o_percAll(recCount) := round((rec.totalvotes/totvotesall)*100,2);
end if;
END LOOP;
END calc_numbervotes;
asp.net 代码
Dim constr As String = "data source=ds;user id=uid;password=pwd;"
Dim orclCon As OracleConnection
orclCon = New OracleConnection(constr)
Dim objCmd As OracleCommand = New OracleCommand()
objCmd.Connection = orclCon
objCmd.CommandText = "pkg_calc_votes.calc_numbervotes"
objCmd.CommandType = CommandType.StoredProcedure
objCmd.Parameters.Add(New OracleParameter("i_office", OracleDbType.NVarchar2, 255)).Value = "U.S. CONGRESS 05"
objCmd.Parameters.Add(New OracleParameter("o_party", OracleDbType.NVarchar2, 10)).Direction = ParameterDirection.Output
objCmd.Parameters.Add(New OracleParameter("o_candidate", OracleDbType.NVarchar2, 255)).Direction = ParameterDirection.Output
objCmd.Parameters.Add(New OracleParameter("o_votes", OracleDbType.Decimal, 10)).Direction = ParameterDirection.Output
objCmd.Parameters.Add(New OracleParameter("o_percAll", OracleDbType.Double, 10)).Direction = ParameterDirection.Output
orclCon.Open()
Dim orclDtRdr As OracleDataReader = Nothing
orclDtRdr = objCmd.ExecuteReader()
gvCursor.DataSource() = orclDtRdr
gvCursor.DataBind()
orclDtRdr.Close()
orclCon.Close()
存储过程从数据库的表中选择所有数据,除了 _o_percAll_.该参数正在 sp 中计算。
谢谢你, 埃亚德
We have a oracle stored procedure that resides in oracle 10.2 database. The stored procedur contains certain inputs and outputs parameters. We are trying to create an asp.net webapplication to execute the stored procedure and bind the result that comes from the output paramerters into a gridview. But no luck.
Here is what I have done so far
Oracle.DataAccess.dll
I installed the Oracle Data Access Components (ODAC) with Oracle Developer Tools for Visual Studio and used it to call the oracle stored procedure.
** Here is the error I am getting **
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'CALC_NUMBERVOTES'
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'CALC_NUMBERVOTES'
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'CALC_NUMBERVOTES'
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'CALC_NUMBERVOTES'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
any help is really appreciated.
oralce stored procedure code
PROCEDURE calc_numbervotes (
i_Office IN ELECTIONRESULTS.office%TYPE,
o_candidate OUT tblcandidate ,
o_party OUT tblparty,
o_votes OUT tblvotes,
o_percAll OUT tblpercAll)
IS
/***************Find Number of candidate per office and party******************/
CURSOR c1 is
SELECT distinct candidate, party,sum(votes) totalvotes
FROM ELECTIONRESULTS
WHERE candidate not in ('Registered Voters' )
AND office = i_office
AND Precinct <> ' '
GROUP BY candidate,party
ORDER BY sum(votes) desc;
/****************** Find total county votes per candidate *********************/
CURSOR c2 is
SELECT sum(votes) from ELECTIONRESULTS
WHERE candidate !='Registered Voters'
AND office = i_Office
AND Precinct <> ' ';
recCount NUMBER DEFAULT 0;
totvotesall NUMBER;
totvotescandidateprec NUMBER;
BEGIN
OPEN c2;
FETCH c2 into totvotesall;
CLOSE c2;
************************************************************/
FOR rec in c1 LOOP
recCount:= recCount + 1;
o_candidate(recCount):= rec.candidate;
o_party(recCount) := rec.party;
o_votes(recCount) := rec.totalvotes;
if rec.totalvotes = 0 then
o_percAll(recCount) := 0;
else
o_percAll(recCount) := round((rec.totalvotes/totvotesall)*100,2);
end if;
END LOOP;
END calc_numbervotes;
asp.net code
Dim constr As String = "data source=ds;user id=uid;password=pwd;"
Dim orclCon As OracleConnection
orclCon = New OracleConnection(constr)
Dim objCmd As OracleCommand = New OracleCommand()
objCmd.Connection = orclCon
objCmd.CommandText = "pkg_calc_votes.calc_numbervotes"
objCmd.CommandType = CommandType.StoredProcedure
objCmd.Parameters.Add(New OracleParameter("i_office", OracleDbType.NVarchar2, 255)).Value = "U.S. CONGRESS 05"
objCmd.Parameters.Add(New OracleParameter("o_party", OracleDbType.NVarchar2, 10)).Direction = ParameterDirection.Output
objCmd.Parameters.Add(New OracleParameter("o_candidate", OracleDbType.NVarchar2, 255)).Direction = ParameterDirection.Output
objCmd.Parameters.Add(New OracleParameter("o_votes", OracleDbType.Decimal, 10)).Direction = ParameterDirection.Output
objCmd.Parameters.Add(New OracleParameter("o_percAll", OracleDbType.Double, 10)).Direction = ParameterDirection.Output
orclCon.Open()
Dim orclDtRdr As OracleDataReader = Nothing
orclDtRdr = objCmd.ExecuteReader()
gvCursor.DataSource() = orclDtRdr
gvCursor.DataBind()
orclDtRdr.Close()
orclCon.Close()
The stored proceder is selecting all the data from a table in the database except for one value which the _o_percAll_. this parameter is being calculated in the sp.
Thank you,
Eyad
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要使用 ExecuteReader(),您的存储过程需要返回结果集。您的存储过程似乎没有这样做。考虑这样做,它返回一个结果集而不使用输出参数:
我的 PL/SQL 技能远不及我的 T-SQL 技能,但我认为这会让你接近。您甚至可以删除光标,如下所示:
To use
ExecuteReader()
, your stored procedure needs to return a result set. Your stored procedure doesn't seem to do that. Consider doing this, which returns a result set without the use of output parameters:My PL/SQL skill is nowhere near my T-SQL skill, but I think this gets you close. You might even be able to remove the cursor, like so:
您的存储过程有四个输出参数,它们是 pl/sql 关联数组(大概是这样,尽管您没有显示代码示例中如何准确定义 tblcandidate 等)。因此,在 .Net 代码中,您需要指定将四个输出参数绑定为 pl/sql 关联数组,即:
o_party.CollectionType = OracleCollectionType.PLSQLAssociativeArray
等等。请参阅此处了解更多详细信息:
OracleCommand 对象 - 数组绑定详细信息
Your stored procedure has four output parameters that are pl/sql associative arrays (presumably, although you don't show how exactly tblcandidate etc. are defined in your code sample). So, in your .Net code, you need to specify that you are binding the four output parameters as pl/sql associative arrays, thusly:
o_party.CollectionType = OracleCollectionType.PLSQLAssociativeArray
and so on. See here for further details:
OracleCommand Object - Array Binding details