gpt4 book ai didi

java - 从 Java 调用 PL/SQL 函数时为 "SQLException: ORA-06550"

转载 作者:行者123 更新时间:2023-12-03 23:14:22 25 4
gpt4 key购买 nike

我想使用 Java 从数据库中检索数据并显示它,所以我创建了这个 PL/SQL 函数,它返回一个游标:

create or replace function std_getInfoFunc return types.cursortype 
as
my_cursor types.cursorType;
begin
open my_cursor FOR
SELECT s.FirstName, s.LastName, s.Address, s.City, s.Province
, s.PostalCode, c.CourseName
FROM Students s, Courses c, StudentAndCourses cs
Where s.StudentID = cs.StudentID
AND c.CourseID = cs.CourseID;
Return my_cursor;
end;

在我的 Java 代码中,我调用函数如下:

try{
CallableStatement cst=connection.prepareCall("{? = call std_getInfoFunc}");
cst.registerOutParameter(1, oracle.jdbc.OracleTypes.CURSOR);
cst.execute();

res=(ResultSet) cst.getObject(1);

while(res.next()){
System.out.println(res.getString(1));
}
}
catch(SQLException e){
e.printStackTrace();
}
finally{
res.close();
cst.close();
conn.close();
}

代码产生以下异常:

 run:
java.sql.SQLException: ORA-06550: line 1, column 13:
PLS-00905: object SAS.STD_GETINFOFUNC is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521)
at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:202)
at
oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1005)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1307)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3449)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3550)
at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:4710)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1374)
at DBControler.viewStdInfo(DBControler.java:95)
at Test_02.main(Test_02.java:18)

为什么?

最佳答案

可能的错误原因是:(在代码段 - 函数中)

1.包“类型”不存在。

  create or replace package types 
as
type cursorType is ref cursor;
end;
/

2 无效的 SQL select 语句(创建函数后表或列已被删除或更改)。

您需要使用简单 sql 语句编写一个新函数,并在Sql 提示符下使用Java 运行它> 代码。

关于java - 从 Java 调用 PL/SQL 函数时为 "SQLException: ORA-06550",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8276139/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com