Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6355039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:41:12+00:00 2026-05-24T22:41:12+00:00

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

  • 0

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;

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

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;

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) } ");

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

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

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:41:13+00:00Added an answer on May 24, 2026 at 10:41 pm

    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;
    

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

    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\n"
     18              + "    x foo_type;\n"
     19              + "begin\n"
     20              + "    x := foo_type(5);\n"
     21              + "    x.proc(10);\n"
     22              + "    ? := x;\n"
     23              + "end;\n");
     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  /
    

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since I started studying object-oriented programming, I frequently read articles/blogs saying functions are better,
Just getting started with DB4O object oriented database. I'm very familiar with SQL, if
As a rule in object-oriented paradigm, a static method can have access only to
In object-oriented programming, we might say the core concepts are: encapsulation inheritance, polymorphism What
I'm familiar with object-oriented architecture, including use of design patterns and class diagrams for
I understand object oriented programming, and have been writing OO programs for a long
I'm developing an object-oriented PHP website right now and am trying to determine the
There's some object-oriented engineering principle that states something along the lines of a class
In your object-oriented language, what guidelines do you follow for grouping classes into a
I recently read Object Oriented Exception Handling in Perl Perl.com article. Is there any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.