Oracle 存储过程可以返回可在 Java 中使用的对象吗?
我正在与 PL/SQL 开发人员合作开展一个项目。另一个开发人员正在编写我需要调用的存储过程。
其中一个存储过程需要返回有关产品的所有信息:
名称、价格、描述、颜色、 重量、制造商等 - ( 15 总计信息)
我假设存储过程将接受一个 IN 参数、产品 ID 并返回 15 个 OUT 参数。
有没有一种方法可以让存储过程返回一个可以转换为自定义数据类型的对象?这是一种典型的技术,还是您通常会返回多个 OUT 参数?
I am working with a PL/SQL developer on a project. The other developer is writing the stored procedures I need to call.
One of the stored procedures needs to return everything about a product:
name, price, description, color,
weight, manufacturer, etc - ( 15
pieces of info in total )
I assumed that the stored procedure would accept one IN parameter, the product-id and return 15 OUT parameters.
Is there a way that the stored procedure can return an object that I can cast to a custom datatype? Is this a typical technique, or would you normally return multiple OUT parameters?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我的偏好是该过程(或者如果它只是检索产品信息,则为一个函数)返回一个 PL/SQL 产品对象,Java 代码将其检索为 java.sql.STRUCT 或更强类型的对象。
Oracle 在其网站上提供了这两种方法的示例代码。以下是 java.sql 的示例.STRUCT方法。这是强类型对象方法< /a>.强类型示例使用 JPublisher 创建强类型对象类,但 JDBC 开发人员指南将引导您创建自己的映射。
My preference would be that the procedure (or if it is just retrieving the product information, a function) returned a PL/SQL product object that the Java code retrieves either as a java.sql.STRUCT or as a more strongly typed object.
Oracle has sample code for both approaches on its web site. Here is an example of the java.sql.STRUCT approach. And here is the strongly typed object approach. The strongly typed example uses JPublisher to create the strongly typed object classes but the JDBC Developer's Guide walks you through creating your own mappings.
Hiberante 提供了一种方法来映射结果java 对象的 SQL 查询或存储过程。这是一个复杂的对象关系映射解决方案,但在大多数情况下,这是值得的。
Hiberante provides a way to map the result of a sql query or a stored procedure to a java object. It is a complex Object-Relational Mapping solution, but in most cases it's worth the effort.
SQL 查询不能以任何方式返回对象
您应该只返回选择运算符的结果,然后用该结果自己构造一个对象
SQL queries cannot return an object in any way
you should just return the result of a select operator then construct an object yourself with that result