0

以下是我的 Oracle 程序。当我使用java调用这个过程时,它会抛出这样的错误。

CREATE OR REPLACE PROCEDURE sp_Get_Menu_Parents
(
  v_inMenuID IN VARCHAR2 DEFAULT NULL,
  cv_1 IN OUT SYS_REFCURSOR
)
AS
BEGIN

   OPEN cv_1 FOR
       SELECT MenuItemId,
              MenuItemName,
              MenuItemDisplayName,
              MenuItemDescription,
              ParentMenuItem,
              MenuLevel,
              MenuOrder,
              CreatedBy,
              CreatedOn,
              LastModifiedBy,
              LastModifiedOn,
              IsValid
         FROM MenuItems
       START WITH MenuItemId = v_inMenuID
       CONNECT BY PRIOR ParentMenuItem  = MenuItemId
         ORDER BY MenuItemId;
END;

例外是,

java.sql.SQLException: ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'SP_GET_MENU_PARENTS'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
    at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:579)
    at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1894)
    at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1094)
    at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2132)
    at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2015)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2877)
    at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:608)
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:536)
    at com.savant.securityadmin.MenuConstructor.getValidResourceAndMenuIDs(MenuConstructor.java:349)
    at com.savant.securityadmin.MenuConstructor.getMenuItemDetails(MenuConstructor.java:227)
    at com.savant.securityadmin.MenuConstructor.getConstructedMenuScripts(MenuConstructor.java:497)
    at org.apache.jsp.index_jsp._jspService(index_jsp.java:59)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

这是我的java代码:

CallableStatement cs = objDBConnection.getCallableStatement("{CALL sp_Get_Menu_Parents(?)}");
                    ResultSet rsDetails = null;
                    cs.setInt(1, menID);

我哪里错了?

4

2 回答 2

2

sproc 有两个参数——你只提供一个给 Callable 语句。

1) 把过程改成函数:

CREATE OR REPLACE FUNCTION sp_Get_Menu_Parents(IN_MENUITEMID IN MENUITEMS.MENUITEMID%TYPE) 
RETURN SYS_RECURSOR IS

  results_cursor SYS_REFCURSOR;

BEGIN

   OPEN results_cursor FOR
       SELECT t.menuitemid,
              t.menuitemname,
              t.menuitemdisplayname,
              t.menuitemdescription,
              t.parentmenuitem,
              t.menulevel,
              t.menuorder,
              t.createdby,
              t.createdon,
              t.lastmodifiedby,
              t.lastmodifiedon,
              t.isvalid
         FROM MENUITEMS t
       START WITH t.menuitemid = IN_MENUITEMID
       CONNECT BY PRIOR t.parentmenuitem = t.menuitemid
         ORDER BY t.menuitemid;

   RETURN results_cursor;

END;

2)Java:

CallableStatement cs = objDBConnection.getCallableStatement("{CALL sp_Get_Menu_Parents(?)}");
cs.setInt(1, menID);
ResultSet rsDetails = cs.executeQuery();
于 2009-11-04T07:03:03.177 回答
0

您的程序

创建或替换过程 sp_Get_Menu_Parents
(
  VARCHAR2 中的 v_inMenuID 默认为 NULL,
  cv_1 输入输出 SYS_REFCURSOR
)

需要两个参数,但您只在 java 代码中提供一个。您还必须提供第二个参数SYS_REFCURSOR

于 2009-11-04T07:00:46.263 回答