1. <tfoot id='yjFlA'></tfoot>
      <bdo id='yjFlA'></bdo><ul id='yjFlA'></ul>

    <small id='yjFlA'></small><noframes id='yjFlA'>

      <i id='yjFlA'><tr id='yjFlA'><dt id='yjFlA'><q id='yjFlA'><span id='yjFlA'><b id='yjFlA'><form id='yjFlA'><ins id='yjFlA'></ins><ul id='yjFlA'></ul><sub id='yjFlA'></sub></form><legend id='yjFlA'></legend><bdo id='yjFlA'><pre id='yjFlA'><center id='yjFlA'></center></pre></bdo></b><th id='yjFlA'></th></span></q></dt></tr></i><div id='yjFlA'><tfoot id='yjFlA'></tfoot><dl id='yjFlA'><fieldset id='yjFlA'></fieldset></dl></div>
    1. <legend id='yjFlA'><style id='yjFlA'><dir id='yjFlA'><q id='yjFlA'></q></dir></style></legend>

      从 JDBC 调用 Oracle 面向对象的 PL/SQL 成员过程

      Call Oracle object-oriented PL/SQL member procedures from JDBC(从 JDBC 调用 Oracle 面向对象的 PL/SQL 成员过程)
      <tfoot id='Es9EG'></tfoot>
        <tbody id='Es9EG'></tbody>

        <small id='Es9EG'></small><noframes id='Es9EG'>

        • <i id='Es9EG'><tr id='Es9EG'><dt id='Es9EG'><q id='Es9EG'><span id='Es9EG'><b id='Es9EG'><form id='Es9EG'><ins id='Es9EG'></ins><ul id='Es9EG'></ul><sub id='Es9EG'></sub></form><legend id='Es9EG'></legend><bdo id='Es9EG'><pre id='Es9EG'><center id='Es9EG'></center></pre></bdo></b><th id='Es9EG'></th></span></q></dt></tr></i><div id='Es9EG'><tfoot id='Es9EG'></tfoot><dl id='Es9EG'><fieldset id='Es9EG'></fieldset></dl></div>

            • <bdo id='Es9EG'></bdo><ul id='Es9EG'></ul>

                <legend id='Es9EG'><style id='Es9EG'><dir id='Es9EG'><q id='Es9EG'></q></dir></style></legend>
                本文介绍了从 JDBC 调用 Oracle 面向对象的 PL/SQL 成员过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在面向对象的 PL/SQL 中,我可以向类型添加成员过程和函数.这里给出了一个例子:

                In object-oriented PL/SQL, I can add member procedures and functions to types. An example is given here:

                create type foo_type as object (
                  foo number,
                
                  member procedure proc(p in number),
                  member function  func(p in number) return number
                );
                
                create type body foo_type as 
                  member procedure proc(p in number) is begin
                    foo := p*2;
                  end proc;
                
                  member function func(p in number) return number is begin
                    return foo/p;
                  end func;
                end;
                

                来自:http://www.adp-gmbh.ch/ora/plsql/oo/member.html

                在 PL/SQL 中,我可以这样调用这些成员过程/函数:

                In PL/SQL, I can then call these member procedures/functions like this:

                declare
                    x foo_type;
                begin
                    x := foo_type(5);
                    x.proc(10);
                    dbms_output.put_line(x.func(2));
                end;
                

                如何使用 JDBC 的 CallableStatement 来实现?我似乎无法在文档中轻松找到它.

                How can I do it with JDBC's CallableStatement? I can't seem to find this in the documentation easily.

                注意:这是一种可能性,内联类型构造函数:

                NOTE: This is one possibility, inlining the type constructor:

                CallableStatement call = c.prepareCall(
                    " { ? = call foo_type(5).func(2) } ");
                

                但我正在寻找的是这样的东西(使用 java.sql.SQLData 作为参数):

                But what I'm looking for is something like this (using java.sql.SQLData as a parameter):

                CallableStatement call = c.prepareCall(
                    " { ? = call ?.func(2) } ");
                

                另外,成员函数、程序可能会修改对象.如何在 Java 中取回修改后的对象?

                Also, member functions, procedures may modify the object. How can I get the modified object back in Java?

                推荐答案

                jdbc 中,您可以使用 out 变量解析和执行 PL/SQL 块.您可以准备一个可调用的语句,例如:

                In jdbc you can parse and execute PL/SQL blocks with out variables. You could prepare a callable statement such as:

                declare
                    x foo_type;
                begin
                    x := foo_type(5);
                    x.proc(10);
                    ? := x.func(2);
                end;
                

                然后你可以使用 CallableStatement.registerOutParameter 并在语句执行后,使用适当的 get 函数来检索值.

                Then you can use CallableStatement.registerOutParameter and after the statement has been executed, use the appropriate get function to retrieve the value.

                你可以直接在java中直接访问一个FOO_TYPE类型,但是你真的要这样做吗?请参阅下面的工作示例:

                You can access directly a FOO_TYPE type directly in java, but do you really want to do this? See below for a working example:

                SQL> create or replace and compile java source named "TestOutParam" as
                  2  import java.sql.*;
                  3  import oracle.sql.*;
                  4  import oracle.jdbc.driver.*;
                  5  
                  6  public class TestOutParam {
                  7  
                  8     public static int get() throws SQLException {
                  9  
                 10        Connection conn =
                 11           new OracleDriver().defaultConnection();
                 12  
                 13        StructDescriptor itemDescriptor =
                 14           StructDescriptor.createDescriptor("FOO_TYPE",conn);
                 15  
                 16        OracleCallableStatement call =
                 17           (OracleCallableStatement) conn.prepareCall("declare
                "
                 18              + "    x foo_type;
                "
                 19              + "begin
                "
                 20              + "    x := foo_type(5);
                "
                 21              + "    x.proc(10);
                "
                 22              + "    ? := x;
                "
                 23              + "end;
                ");
                 24  
                 25        call.registerOutParameter(1, OracleTypes.STRUCT, "FOO_TYPE");
                 26  
                 27        call.execute();
                 28  
                 29        STRUCT myObj = call.getSTRUCT(1);
                 30  
                 31        Datum[] myData = myObj.getOracleAttributes();
                 32  
                 33        return myData[0].intValue();
                 34  
                 35     }
                 36  }
                 37  /
                

                这是一个测试类,用于展示如何在 SQL 对象上使用 registerOutParameter 方法,我们称之为:

                This is a test class to show how you can use the method registerOutParameter on an SQL object, let's call it:

                SQL> CREATE OR REPLACE
                  2  FUNCTION show_TestOutParam RETURN NUMBER
                  3  AS LANGUAGE JAVA
                  4  NAME 'TestOutParam.get() return java.lang.int';
                  5  /
                
                Function created
                
                SQL> select show_testoutparam from dual;
                
                SHOW_TESTOUTPARAM
                -----------------
                               20
                

                这篇关于从 JDBC 调用 Oracle 面向对象的 PL/SQL 成员过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to call Oracle function or stored procedure using spring persistence framework?(如何使用 Spring 持久化框架调用 Oracle 函数或存储过程?)
                What can cause intermittent ORA-12519 (TNS: no appropriate handler found) errors(什么会导致间歇性 ORA-12519(TNS:找不到合适的处理程序)错误)
                SQL to return the number of working days between 2 passed in dates(SQL 返回两个传入日期之间的工作日数)
                Oracle Date Subtraction(Oracle 日期减法)
                Is using quot;select *quot; for a cursor in PL/SQL considered bad programming?(正在使用“选择 *PL/SQL 中的游标被认为是糟糕的编程?)
                Using sql/plsql, how do you find out which character set a text uses?(使用 sql/plsql,你如何找出文本使用的字符集?)

                    <bdo id='Hppoy'></bdo><ul id='Hppoy'></ul>

                      <tbody id='Hppoy'></tbody>
                        • <tfoot id='Hppoy'></tfoot>

                          <small id='Hppoy'></small><noframes id='Hppoy'>

                        • <legend id='Hppoy'><style id='Hppoy'><dir id='Hppoy'><q id='Hppoy'></q></dir></style></legend>
                          <i id='Hppoy'><tr id='Hppoy'><dt id='Hppoy'><q id='Hppoy'><span id='Hppoy'><b id='Hppoy'><form id='Hppoy'><ins id='Hppoy'></ins><ul id='Hppoy'></ul><sub id='Hppoy'></sub></form><legend id='Hppoy'></legend><bdo id='Hppoy'><pre id='Hppoy'><center id='Hppoy'></center></pre></bdo></b><th id='Hppoy'></th></span></q></dt></tr></i><div id='Hppoy'><tfoot id='Hppoy'></tfoot><dl id='Hppoy'><fieldset id='Hppoy'></fieldset></dl></div>