Passing an array of objects to stored procedure(oracle)

I have to pass an array of objects to a pl/sql stored proc.
Its prototype is,
proc_orderins(ordernum varchar2(14), ct newTask)
where newTask is an array of objects:
type task as object ( name varchar2(20),odd varchar2(8),sdd varchar2(8));
create or replace type newTask as VARRAY(25) OF Task;
will the following work from the java code :
public class CriticalTask
String name,odd,sdd;
public CrticalTask(String name,String odd,String sdd)
this.name=name;
this.odd=odd;
this.sdd=sdd;
Object [] ctasks =new Object[7];
for(i=0;i<7;i++)
Object=new CrtitcalTask("x","x","x");
String query="{call proc_orderins(?,?)}";
CallableStatement cstmt=con.prepareCall(query);
cstmt.setInt(123);
cstmt.setObject(ctasks);
cstmt.execute();
will the above code work, when I am passing an array?

Use code tags when you post code.
I am rather certain that the code you posted will not work.
Technically you should be able to use the java.sql.Array interface.
The newest Oracle drivers might support that (you would have to investigate how to use it.)
It is however possible that it isn't supported. If not then you will have to use one of the Oracle specific classes that is documented in the Oracle jdbc documentation.

Similar Messages

  • How to pass array of Object in A Procedure using OCCI.......

    I m also trying for How to pass Object to a procedureb using OCCI...
    Steps....
    1. I created A type.....
    2. Then I created a VARRAY using that Type.
    3.After that I have written An Procedure with object as a parameter..
    now using OCCI how do u bind the parameter with this . plz note that using OTT
    i have already created the class representation of above object type i.e class
    four Files Created 1> demo.h 2>registermapping.h
    3> demo.cpp 2>registermapping.cpp
    After I want to Pass the Values in A Vector...
    vctor<full_name *> vect;
    stmt=con->createStatement("BEGIN Add_Object(:1); END;");
    full_name *name1 = new full_name; //Giving the Error here Given below....
    name1->
    name1->
    Through name1 Which Function I will call in which I will Pass a String....
    like
    name1->readSQL("Sanjay"); Or I have to add a function......
    vect.push_back(name1);
    setVector(stmt,1,vect,"FULL_NAME");
    error C2259: 'FullName' : cannot instantiate abstract class
    can u plz suggest me Why this Error is Giving......?
    How to pass the data?
    setFirst_name() and setLast_name() this two function I will add in Demo.cpp which one created automativcally by Using OTT command.....or other way plz tell me Boss ....
    Can u lz Suggest me ASAP....

    hi Nishant ,
    What u have done Now I mm trying ....
    can u Plz Suggest me......
    How to pass and Array of Object in Procedure using OCCI... Doing....
    90% finished Two Error's Are Coming...
    1> If I create the Class then Data Not Inserting table......
    2> If I will create the Class through OTT command.......
    then U can't Instantiate Object It is DIsplying ,this is Abstract Class(PObject)...
    Beco'z the below Method is Not adding Automatically by OTT command which is Pure Virtual Function.....
    But I added this Function Still SAme Error Giving..
    getSQLTypeName(oracle::occi::Environment env, void *schName,
    unsigned int &schNameLen, void **typeName,
         unsigned int &typeNameLen) const
    Plz Suggest me....
    regard's
    sanjay

  • How to bind arrays to PL/SQL stored procedure using OCI?

    Hi,
    We are having problems trying to bind arrays to PL/SQL stored procedure using OCI. Here is the situation:
    - We have a stored procedure called "GetVEPFindTasks" with the following interface:
    PROCEDURE GetVEPFindTasks (
    p_ErrorCode OUT NUMBER,
    p_ErrorMsg OUT VARCHAR2,
    p_RowCount OUT NUMBER,
    p_VEPFindTasks OUT t_VEPFindTaskRecordTable,
    p_MaxTask IN NUMBER);
    t_VEPFindTaskRecordTable is a record with the following entries:
    TYPE t_VEPFindTaskRecord IS RECORD (
    RTCID NUMBER,
    TransNum NUMBER,
    TransTimestamp VARCHAR2(20),
    Pathname1 image_data.pathname%TYPE,
    Pathname2 image_data.pathname%TYPE,
    Pathname3 image_data.pathname%TYPE,
    OperatorID operator.id%TYPE);
    - Now, we are trying to call the stored procedure from C++ using OCI (in UNIX). The call that we use are: OCIBindByName and OCIBindArrayOfStruct to bind the parameters to the corresponding buffers. We bind all parameters in the interface by name. Now, we do bind the record's individual item by name (RTCID, TransNum, etc.), and not as a record. I don't know if this is going to work. Then, we use the bind handles of the binded record items (only record items such as RTCID, TransNum, and NOT error_code which is not part of the record) to bind the arrays (using OCIBindArrayOfStruct).
    All of the parameters that are binded as arrays are OUTPUT parameters. The rest are either INPUT or INPUT/OUTPUT parameters. Now, when we try to execute, OCI returns with an error "Invalid number or types of arguments" (or something to that sort... the number was something like ORA-06550). Please help...
    Is there any sample on how to use the OCIBindArrayOfStruct with PL/SQL stored procedures? The sample provided from Oracle is only for a straight SQL statement.
    Thank's for all your help.
    ** Dannil Chan **

    As you said:
    You have to pass in an array for every field and deconstruct/construct the record in the procedure. There is no support for record type or an array of records. Can you give me a example? I'am very urgently need it.
    thanks
    email: [email protected]

  • Passing Multi-Value Parameter to a Stored Procedure

    Has anyone experienced passing a Parameter (MultiValue) to a Stored Procedure? I am aware that Crystal Passes the Param as an Array. How would you go about handling this within a Stored Procedure???

    Hi Daniel
    Try as below:
    1. Create a Crystal report, and add a multi-value parameter.
    2. Since the multi-value parameter is treated as an array, create a formula that uses the JOIN function. Create a formula as below:
    //Formula: @JoinFormula
    Join ({?Multi-value parameter array},";")
    ====================
    NOTE:
    In the formula above, a semi-colon (";") is the delimiter.
    ====================
    3. Within the main report, create a subreport based on the stored procedure, and include the parameter to be populated with the multi-value list.
    4. Link the Join formula in the main report to the stored procedure parameter in the subreport.
    Doing so passes a multi-value parameter to the stored procedure.
    Hope this helps!!!!
    Regards
    Sourashree

  • Passing an array of objects to a method.

    Hi I'm building a program to act as a CD Collection Database. An array of objects represents the entries: Artist, Album and NUmber of Tracks. What I want to do is in the Menu, user to choose wether he or she wants to Add new CD to collection, print or quit, if he/she does then I call a method addNewEntry, to which i pass the array of objects called array, and I want the user to enter the entries each in turn, after that i want the program to return to the method Menu and ask if he or she wants to quit, print or add new cd. The idea is that the details entered already would be contained in the array of objects [0], so the next set of details go to [1] and then to [2] and so on. I have build up the code at this stage but i get an error while copmiling and im totally stuck. Im a beginner in Java.
    Here is the code:
    //by Andrei Souchinski
    //Mini Project: CD Collection Database
    //Designed for a grade F
    //Defining new class of objects to represent CD database entries.
    //A database entry consists of the artist name, the album name and number of tracks.
    //A single entry can be entered by the user typing the details in and the entry can be printed out.
    import javax.swing.*;
    import java.util.*;
    public class MiniProject
         public static void main (String[] args)     
              System.out.println("\tCD Collection Database\n");
              System.out.println("1. Add new Compact Disk to the Database");
              System.out.println("2. Print out current database entries");
              System.out.println("3. Quit\n");          
              theMenu();
         public static void theMenu()
              CompactDisk [] array = new CompactDisk[20];
              String menu;
              menu = JOptionPane.showInputDialog("What would you like to do?");
              if (menu.equals ("3"))
                   JOptionPane.showMessageDialog(null, "Thank You For Using our Service! \nGoodbye!");
                   System.exit(0);     
              if (menu.equals ("2"))
              if (menu.equals ("1"))
              addNewEntry(array);
              else
                   JOptionPane.showMessageDialog(null, "Please select your choice form the menu");
                   theMenu();
         public int addNewEntry(int newcd[])
                   int i;          
                   newcd[i] = (JOptionPane.showInputDialog("Please enter the name of the Artist"));
                   newcd[i] = (JOptionPane.showInputDialog("Please enter the name of the Album"));
                   newcd[i] = (Integer.parseInt (JOptionPane.showInputDialog("Please enter the number of tracks on this album")));
    //A Compact Disk entry consists of three attributes: artist name, album and number of tracks
    class CompactDisk
         public String artistname; //Instance variables for artistname, albumname and numberoftracks.
         public String albumname;
         public int numberoftracks;
         public CompactDisk(String n, String a, int t)
         artistname = n; //Stores the 1st argument passed after "new Dates" into day
         albumname = a; //Stores the 2nd argument passed after "new Dates" into month
         numberoftracks = t; //Stores the 3rd argument passed after "new Dates" into year
         //When called from the main method, prints the contents of
         //artistname, albumname and numberoftracks on to the screen.
         public void printCompactDisk ()
                   String output = "\n " + artistname + "\n " + albumname + "\n " + numberoftracks;
                   System.out.println(output);
    }

    //by Andrei Souchinski
    //Mini Project: CD Collection Database
    //Designed for a grade F
    //Defining new class of objects to represent CD database entries.
    //A database entry consists of the artist name, the album name and number of tracks.
    //A single entry can be entered by the user typing the details in and the entry can be printed out.
    import javax.swing.*;
    import java.util.*;
    public class MiniProject
         public static void main (String[] args)     
              System.out.println("\tCD Collection Database\n");
              System.out.println("1. Add new Compact Disk to the Database");
              System.out.println("2. Print out current database entries");
              System.out.println("3. Quit\n");          
                theMenu();
         public static void theMenu()
              String menu;
              menu = JOptionPane.showInputDialog("What would you like to do?");
              if (menu.equals ("3"))
                   JOptionPane.showMessageDialog(null, "Thank You For Using our Service! \nGoodbye!");
                   System.exit(0);     
              if (menu.equals ("2"))
              if (menu.equals ("1"))
              addNewEntry();
              else
                   JOptionPane.showMessageDialog(null, "Please select your choice form the menu");
                   theMenu();
         public static void addNewEntry()
                   CompactDisk [] array = new CompactDisk[20];
                   int i = 0;
                   array.artistname = (JOptionPane.showInputDialog("Please enter the name of the Artist"));
                   array[i].albumname = (JOptionPane.showInputDialog("Please enter the name of the Album"));
                   array[i].numberoftracks = (Integer.parseInt (JOptionPane.showInputDialog("Please enter the number of tracks on this album")));
    //A Compact Disk entry consists of three attributes: artist name, album and number of tracks
    class CompactDisk
         public String artistname; //Instance variables for artistname, albumname and numberoftracks.
         public String albumname;
         public int numberoftracks;
         public CompactDisk(String n, String a, int t)
         artistname = n; //Stores the 1st argument passed after "new Dates" into day
         albumname = a; //Stores the 2nd argument passed after "new Dates" into month
         numberoftracks = t; //Stores the 3rd argument passed after "new Dates" into year
         //When called from the main method, prints the contents of
         //artistname, albumname and numberoftracks on to the screen.
         public void printCompactDisk ()
                   String output = "\n " + artistname + "\n " + albumname + "\n " + numberoftracks;
                   System.out.println(output);
    I've edited the code, itcompiles, but gives an error when i ran it..:(

  • Howto:pass an ado.recordset to a stored procedure

    Hi,
    I need to pass an adodb.recordset to a stored procedure in Oracle 8.0.5.
    I am programming with visualbasic 6, an exe application.
    I don4t know how to setting the parameter for the adodb.command which execute the procedure.
    Any idea??
    Thanks,
    Cesar,

    Hi,
    You can't do this using an OLEDB provider. There is no such a provider with this feature.
    Yuancai (Charlie) Ye
    See 30 real well-tested advanced OLEDB samples
    Use of free SocketPro for creating super client and server application with numerous samples
    www.udaparts.com

  • How to verify the user information pass by the form with a stored procedure?

    Hi,
    I would like to know how to verify user information pass by the form with a stored procedure.
    I want make a portal which accepts to new user registration, but I want verify the new user's informations (like the name don't contain a number etc).
    Thanks for your help
    regards
    jla

    Hi Samson,
    You can use the UI API to do this. You can catch the form_ADD event and then validate the input from the users. You can even block the event from completing (and stop the document from being added) if your code finds some incorrect data using the bubbleEvent functionality.
    I don't have one specific example to show you, but if you look at some of the SDK samples (for example C:\Program Files\SAP\SAP Business One SDK\Samples\COM UI\VB.NET\02.CatchingEvents) to see how to work with events, you can then create your own validation to ensure the users data is valid.
    Regards,
    Niall

  • Passing an array of objects.

    I have been trying to pass an array of objects from java to C. They are simple objects, only fields, no methods.
    Example...
    class User
    String name;
    int id;
    public class JNIExample
    User[] users = new User[10];
    public native void nativeCode(User[] usersarray);
    static
    try{
    System.loadLibrary("object");
    }catch(Exception e)
    System.out.println("Could not load library.");
    public static void main(String[] args)
    JNIExample anex = new JNIExample();
    anex.nativeCode(anex.users);
    Could someone give me sample code on how to access the array elements and get/set the object values on the C side. In the above code I did not create any of the objects in the array or set their field values but these will be set on the java side.
    Any help would be greatly appr.
    Thanks,
    Darrin

    JNIEXPORT void JNICALL Java_User_nativeCode
      (JNIEnv *env, jobject this, jobjectArray arr) {
      jsize  idx; // array index
      // accessing the Users
      for(idx = env->GetArrayLength(env, arr); idx-- > 0;) {
        jobject user = env->GetObjectArrayElement(env, arr, idx);
        // do something with it
      // setting the Users
      for(idx = env->GetArrayLength(env, arr); idx-- > 0;) {
        jobject user = ...
        env->SetObjectArrayElement(env, arr, idx, user);
    }

  • Passing ARRAY object to stored procedure problem

    I've created a stored procedure that accepts as a parameter a
    database type
    that I have defined as a VARRAY. (create type XXX)
    When I attempt to pass an ARRAY object to this stored procedure
    through JDBC
    (Thin-client driver) I recieve the Oracle internal error ORA-
    00600 and the
    first "parameter" is [12760].
    Has anyone else attempted the same sort of thing w/ success?
    I am including the Java source code to help the investigation
    private void chad(int[] railcarIds) throws NonFatalDBException,
    FatalDBException {
    CallableStatement theStatement = null;
    try {
    theStatement = this.getDatabaseConnection().prepareCall("{call
    RomsRepairPackage.chad(?)} ");
    // create an ARRAY object to send to the procedure
    ArrayDescriptor ad =
    ArrayDescriptor.createDescriptor("RAILCARIDVARRAYTYPE",
    this.getDatabaseConnection());
    ARRAY theArray = new ARRAY(ad, this.getDatabaseConnection(),
    railcarIds);
    // set the input parameter which is the array of railcar ids
    ((OracleCallableStatement)theStatement).setARRAY(1, theArray);
    theStatement.execute();
    theStatement.close();
    } catch (SQLException sqle) {
    System.out.println("ouch");
    Thank you for any help,
    Chad Sheley
    Senior Consultant
    Cap Gemini
    Des Moines, IA
    null

    Hi
    Can u plzz help me as to how did u write the procedure to take arrays as input.I also have to write aprocedure that takes arrays and returns arrays.Plzz can u give me a working sample as I have not found any help anywhere
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Chad Sheley ([email protected]):
    I've created a stored procedure that accepts as a parameter a
    database type
    that I have defined as a VARRAY. (create type XXX)
    When I attempt to pass an ARRAY object to this stored procedure
    through JDBC
    (Thin-client driver) I recieve the Oracle internal error ORA-
    00600 and the
    first "parameter" is [12760].
    Has anyone else attempted the same sort of thing w/ success?
    I am including the Java source code to help the investigation
    private void chad(int[] railcarIds) throws NonFatalDBException,
    FatalDBException {
    CallableStatement theStatement = null;
    try {
    theStatement = this.getDatabaseConnection().prepareCall("{call
    RomsRepairPackage.chad(?)} ");
    // create an ARRAY object to send to the procedure
    ArrayDescriptor ad =
    ArrayDescriptor.createDescriptor("RAILCARIDVARRAYTYPE",
    this.getDatabaseConnection());
    ARRAY theArray = new ARRAY(ad, this.getDatabaseConnection(),
    railcarIds);
    // set the input parameter which is the array of railcar ids
    ((OracleCallableStatement)theStatement).setARRAY(1, theArray);
    theStatement.execute();
    theStatement.close();
    } catch (SQLException sqle) {
    System.out.println("ouch");
    Thank you for any help,
    Chad Sheley
    Senior Consultant
    Cap Gemini
    Des Moines, IA<HR></BLOCKQUOTE>
    null

  • How to pass a array of object to oracle procedure using callable

    Hi,
    I am calling a oracle stored procedure using callable statement which has IN and OUT parameter of same type.
    IN and OUT are array of objects. (ie) IN parameter as Array of Objects and OUT parameter as Array of Objects
    here are the steps i have done as advised from oracle forum. correct me if i am in wrong direction
    ORACLE types and Stored Procedure
    CREATE OR REPLACE
    TYPE APPS.DEPARTMENT_TYPE AS OBJECT (
    DNO NUMBER (10),
    NAME VARCHAR2 (50),
    LOCATION VARCHAR2 (50)
    CREATE OR REPLACE
    TYPE APPS.DEPT_ARRAY AS TABLE OF department_type;
    CREATE OR REPLACE package body APPS.insert_object
    IS
    PROCEDURE insert_object_prc (d IN dept_array, d2 OUT dept_array)
    IS
    BEGIN
    d2 := dept_array ();
    FOR j IN 1 .. d.COUNT
    LOOP
    d2.EXTEND;
    d2 (j) := department_type (d (j).dno, d (j).name, d(j).location);
    END LOOP;
    END insert_object_prc;
    END insert_object;
    JAVA CODE
    Value Object
    package com.custom.vo;
    public class Dep {
    public int empNo;
    public String depName;
    public String location;
    public int getEmpNo() {
    return empNo;
    public void setEmpNo(int empNo) {
    this.empNo = empNo;
    public String getDepName() {
    return depName;
    public void setDepName(String depName) {
    this.depName = depName;
    public String getLocation() {
    return location;
    public void setLocation(String location) {
    this.location = location;
    to call stored procedure
    package com.custom.callable;
    import com.custom.vo.Dep;
    import oracle.jdbc.OracleCallableStatement;
    import oracle.jdbc.OracleConnection;
    import oracle.jdbc.OracleTypes;
    import oracle.jdbc.pool.OracleDataSource;
    import oracle.sql.ARRAY;
    import oracle.sql.ArrayDescriptor;
    import oracle.sql.Datum;
    import oracle.sql.STRUCT;
    import oracle.sql.StructDescriptor;
    public class CallableArrayTryOut {
    private static OracleDataSource odcDataSource = null;
    public static void main(String[] args) {
    OracleCallableStatement callStatement = null;
    OracleConnection connection = null;
    try {
    odcDataSource = new OracleDataSource();
    odcDataSource
    .setURL("......");
    odcDataSource.setUser("....");
    odcDataSource.setPassword("....");
    connection = (OracleConnection) odcDataSource.getConnection();
    } catch (Exception e) {
    System.out.println("DB connection Exception");
    e.printStackTrace();
    Dep[] dep = new Dep[2];
    dep[0] = new Dep();
    dep[0].setEmpNo(100);
    dep[0].setDepName("aaa");
    dep[0].setLocation("xxx");
    dep[1] = new Dep();
    dep[1].setEmpNo(200);
    dep[1].setDepName("bbb");
    dep[1].setLocation("yyy");
    try {
    StructDescriptor structDescriptor = new StructDescriptor(
    "APPS.DEPARTMENT_TYPE", connection);
    STRUCT priceStruct = new STRUCT(structDescriptor, connection, dep);
    STRUCT[] priceArray = { priceStruct };
    ArrayDescriptor arrayDescriptor = ArrayDescriptor.createDescriptor(
    "APPS.DEPT_ARRAY", connection);
    ARRAY array = new ARRAY(arrayDescriptor, connection, priceArray);
    callStatement = (OracleCallableStatement) connection
    .prepareCall("{call insert_object.insert_object_prc(?,?)}");
    ((OracleCallableStatement) callStatement).setArray(1, array);
    callStatement.registerOutParameter(2, OracleTypes.ARRAY,
    "APPS.DEPT_ARRAY");
    callStatement.execute();
    ARRAY outArray = callStatement.getARRAY(2);
    Datum[] datum = outArray.getOracleArray();
    for (int i = 0; i < datum.length; i++) {
    oracle.sql.STRUCT os = (oracle.sql.STRUCT) datum[0];
    Object[] a = os.getAttributes();
    for (int j = 0; j < a.length; j++) {
    System.out.print("Java Data Type :"
    + a[j].getClass().getName() + "Value :" + a[j]
    + "\n");
    connection.commit();
    callStatement.close();
    } catch (Exception e) {
    System.out.println("Mapping Error");
    e.printStackTrace();
    THE ERROR
    Mapping Errorjava.sql.SQLException: Inconsistent java and sql object types
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
    at oracle.jdbc.dbaccess.DBError.check_error(DBError.java:1130)
    at oracle.sql.StructDescriptor.toOracleArray(StructDescriptor.java:823)
    at oracle.sql.StructDescriptor.toArray(StructDescriptor.java:1735)
    at oracle.sql.STRUCT.<init>(STRUCT.java:136)
    at com.custom.callable.CallableArrayTryOut.main(CallableArrayTryOut.java:48)

    You posted this question in the wrong forum section. There is one dedicated to Java that was more appropriate.
    Anyway here is a link that describes what you should do.
    http://download.oracle.com/docs/cd/B19306_01/java.102/b14355/oraarr.htm#i1049179
    Bye Alessandro

  • Send a array of user-defined java objects to stored procedure

    hi,
    I´d like to know if its possible send java user-defined objects to a collection. I've tried the exemple bellow but it doesn´t work:
    1) In database
    -- nested table type
    create or replace type client_table_type is table of client%rowtype;
    -- table client:
    teste
    ( id number(18,0),
    name varchar2(80),
    birthday date)
    -- stored procedure
    create or replace package client_pkg
    is
    procedure insert_clients(
    p_array_clients client_table_type
    end;
    2) In Java
    java.lang.Class.forName ("oracle.jdbc.driver.OracleDriver");
    java.sql.Connection conn = java.sql.DriverManager.getConnection("jdbc:oracle:thin .....);
    ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor("client_table_type", conn);
    ARRAY a2 = new ARRAY(descriptor, conn, anArrayIn);
    PreparedStatement ps = (PreparedStatement)conn.prepareStatement("{ call client_pkg.insert_clients(?) }");
    ps.setArray(1, a2);
    ps.execute();
    Where anArrayIn is an array of Client and Client is a java user-defined class with these attributes:
    public class Client{
    public long id;
    public String name;
    public Date birthday;
    3) when I´ve tried to run the java code its returned the error in the ArrayDescriptor line:
    Exception in thread "main" java.sql.SQLException: .....:
    Unable to resolve type: "SISSERV.CLIENT_TABLE_TYPE"
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
    at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
    at oracle.sql.ArrayDescriptor.initPickler(ArrayDescriptor.java:1976)
    at oracle.sql.ArrayDescriptor.<init>(ArrayDescriptor.java:199)
    at oracle.sql.ArrayDescriptor.createDescriptor(ArrayDescriptor.java:118)
    at teste_array_oracle.Carga.callPLSQL(Carga.java:60)
    at teste_array_oracle.Carga.<init>(Carga.java:41)
    at teste_array_oracle.Carga.main(Carga.java:32)
    erro de execuþÒo
    Tks for any help!

    A brief answer to this from my side (not knowing Java that wel), but hopefully suffices to put you on the right track.
    <p>
    A SQL user defined type is basically a class (it can contain properties and methods). It has only superficial resemblence to a traditional record struct. So you cannot use one. Even if you could (assuming you code a PL/SQL "traditional" record struct), there are issues around how char and numeric data are represented binary inside Oracle and issues around byte/word alignment.
    <p>
    So bottom line - what you're doing will not work (as the errors show).
    <p>
    Okay, so what then? Well, the OCI (Oracle Call Interface) supports all Oracle data types, including these user types (also called Advance Data Types in Oracle-speak). You therefore need to use the supplied API calls to deal with instantiated objects (structures) of these type.
    You're best bet is to have a look Oracle® Database Java Developer's Guide

  • Memory leak problem while passing Object to stored procedure from C++ code

    Hi,
    I am facing memory leak problem while passing object to oracle stored procedure from C++ code.Here I am writing brief description of the code :
    1) created objects in oracle with the help of "create or replace type as objects"
    2) generated C++ classes corresponding to oracle objects with the help of OTT utility.
    3) Instantiating classes in C++ code and assigning values.
    4) calling oracle stored procedure and setting object in statement with the help of setObject function.
    5) deleted objects.
    this is all I am doing ,and getting memory leak , if you need the sample code then please write your e-mail id , so that I can attach files in reply.
    TIA
    Jagendra

    just to correct my previous reply , adding delete statement
    Hi,
    I am using oracle 10.2.0.1 and compiling the code with Sun Studio 11, following is the brief dicription of my code :
    1) create oracle object :
    create or replace type TEST_OBJECT as object
    ( field1 number(10),
    field2 number(10),
    field3 number(10) )
    2) create table :
    create table TEST_TABLE (
    f1 number(10),f2 number (10),f3 number (10))
    3) create procedure :
    CREATE OR REPLACE PROCEDURE testProc
    data IN test_object)
    IS
    BEGIN
    insert into TEST_TABLE( f1,f2,f3) values ( data.field1,data.field2,data.field3);
    commit;
    end;
    4) generate C++ classes along with map file for database object TEST_OBJECT by using Oracle OTT Utility
    5) C++ code :
    // include OTT generate files here and other required header files
    int main()
    int x = 0;
    int y = 0;
    int z =0;
    Environment *env = Environment::createEnvironment(Environment::DEFAULT);
    Connection* const pConn =
    env->createConnection"stmprf","stmprf","spwtrgt3nms");
    const string sqlStmt("BEGIN testProc(:1) END;");
    Statement * pStmt = pConn->createStatement(sqlStmt);
    while(1)
    TEST_OBJECT* pObj = new TEST_OBJECT();
    pObj->field1 = x++;
    pObj->field2 = y++;
    pObj->field3 = z++;
    pStmt->setObject(1,pObj);
    pStmt->executeUpdate();
    pConn->commit();
    delete pObj;
    }

  • Passing Objects to Stored Procedures in SQL Queries: UNREF(REF(o))

    To me it seems that passing an object (type) to stored procedure in a SQL query is quite laborious. See:
    I created the following simple type:
    TYPE LAST AS OBJECT (
    id NUMBER
    defined a function:
    FUNCTION "CHECKLAST" (l LAST)
    RETURN NUMBER
    AS LANGUAGE JAVA
    NAME 'Checker.checkLast(Last) return int';
    created a typed table:
    CREATE TABLE lastTable OF Last;
    inserted some objects:
    INSERT INTO lastTable VALUES (1003);
    NOW! If want to use the StoredFunction I have to use the following syntax:
    SELECT checkLast(DEREF(REF(o)))
    FROM lasttable o;
    That's not very elegant.
    I would expect the follwing to be working:
    SELECT checkLast(o)
    FROM lasttable o;
    Did I do something wrong? Or did Oracle forget to implement the simple syntax?
    Even worse, the DEREF(REF(o)) trick does not work for member functions...
    Regards,
    André

    I did some experiments and can now (partly) answer my own question:
    Indeed, it is possible to declare a function with a parameter passed as reference:
    CREATE OR REPLACE TYPE Point AS OBJECT
    ID INT,
    MEMBER FUNCTION distance(q IN REF Point) RETURN NUMBER
    Unfortunately, it is not possible to use the REF in PL/SQL directly:
    CREATE OR REPLACE TYPE BODY Point is
    MEMBER FUNCTION distance(q IN REF Point) RETURN NUMBER
    AS
    BEGIN
    RETURN q.ID - SELF.ID; --Error(5,14): PLS-00536: No navigation through REF
    END;
    end;
    So, for testing purposes I decided to implement a very simple PL/SQL member function:
    CREATE OR REPLACE TYPE BODY Point is
    MEMBER FUNCTION distance(q IN REF Point) RETURN NUMBER
    AS
    BEGIN
    RETURN -1;
    END;
    end;
    BUT: The SQL query without VALUE is still not possible. The query
    SELECT *
    FROM PointTable d, PointTable e
    WHERE d.distance(e) > 0
    renders ORA-00904: "E": invalid identifier
    Somehow the 'e' seems to be misinterpreted completely.
    Illogically, the following query works fine:
    SELECT *
    FROM PointTable d, PointTable e
    WHERE d.distance(REF(e)) > 0
    The illogical thing is that, now 'E' seems to refer to a VALUE and not to REF (because we can use the REF function), whereas in Gaverill's post 'O' seems to refer to a REF (because we can use the VALUE function).
    My intent is to avoid both the VALUE(o) from Gaverill's example and the REF(e) from my example, because both is not intuitive for end users...
    Maybe I have to define a VIEW holding the object values... But then the end user has to use it in the FROM part.
    All in all, there seems to be no elegant solution for passing objects as parameters to functions...
    Regards,
    André

  • Passing array of objects to the procedure

    Hi I have written a procedure to accept array of objects as input . it worked fine.
    this is the only input parameter in my procedure.
    But now I tried to add an out put parameter of type varchar2 to my procedure to send some return value but it gives me an error
    PLS-00410: duplicate fields in RECORD,TABLE or argument list are not permitted.
    please suggest cant i pass any other arguments when using a record or object array as parameter?
    this is my code
    CREATE OR REPLACE TYPE PREF_OBJ_TYPE as object (
    PREF_CD  varchar2(20),
    USR_ID   VARCHAR2(20),
    PROD_CD  VARCHAR2(50),
    DFLT_PREF_VAL_TX VARCHAR2(250),
    USR_PREF_VAL_TX VARCHAR2(250),
    CRE_USR_ID VARCHAR2(20),
    UPDT_USR_ID VARCHAR2(20) );
    CREATE OR REPLACE TYPE PREF_ARRAY is table of PREF_OBJ_TYPE;
    CREATE OR REPLACE procedure MMM(in_pref PREF_ARRAY,v_err out varchar2 )
    is
    v_prod_dim_nb NUMBER;
    v_usr_dim_nb  NUMBER;
    v_count NUMBER;
    v_err varchar2(50);
    begin
    for i in  in_pref.first.. in_pref.last
    LOOP
    /* Derive the product and user dim numbers */
    select prod_dim_nb into  v_prod_dim_nb from prod_dim where prod_cd=in_pref(i).prod_cd ;
    select usr_dim_nb into v_usr_dim_nb from usr_xref where usr_id=in_pref(i).usr_id and sys_id='ACCESS';
    /* check if the record already exist in usr_prod_pref corresponding to that  user,prod,pref */
    select count(1) into v_count from usr_prod_pref_test where prod_dim_nb=v_prod_dim_nb and usr_dim_nb=v_usr_dim_nb and pref_cd=in_pref(i).pref_cd;
    if v_count=0 then
    BEGIN
    INSERT INTO USR_PROD_PREF_TEST values(v_usr_dim_nb,in_pref(i).pref_cd,v_prod_dim_nb,in_pref(i).DFLT_PREF_VAL_TX,in_pref(i).usr_PREF_VAL_TX,'Active',NULL,
    in_pref(i).cre_usr_id,sysdate,in_pref(i).updt_usr_id,NULL);
    END;
    else
    update USR_PROD_PREF_TEST set USR_PREF_VAL_TX=in_pref(i).USR_PREF_VAL_TX,DFLT_PREF_VAL_TX=in_pref(i).DFLT_PREF_VAL_TX,UPDT_USR_ID=in_pref(i).updt_usr_id,updt_dt=sysdate,cre_usr_id=in_pref(i).cre_usr_id where
    prod_dim_nb=v_prod_dim_nb and usr_dim_nb=v_usr_dim_nb and pref_cd=in_pref(i).pref_cd;
    end if;
    end loop;
    commit;
    v_err:='abc';
    end;
    /Edited by: raj_fresher on Oct 9, 2009 6:56 AM

    okay i was wondering.... if he knew the error code in advance i thought user defined messages have numbers like -20000 to 209999 or something like that..
    neverthless one final question ....
    Now that my procedure is ready .. i have 2 final questions for this thread
    1) is my usage of errorcode and error message to return to the calling application correct?
    2) how to test this procedure in sql plus (or) toad?
    i mean how to call?
    exec modify_user_preferences(value, ?????(what should  i write here for output variable ) ) ?? i want to check what value is it returning?
    CREATE OR REPLACE procedure MODIFY_USER_PREFERENCES2(in_pref PREF_ARRAY,v_status_message out varchar2  )
    is
    v_prod_dim_nb NUMBER;
    v_usr_dim_nb  NUMBER;
    v_count NUMBER;
    v_product_exception EXCEPTION;
    v_user_exception EXCEPTION;
    p_error_code varchar2(50);
    p_error_msg varchar2(50);
    begin
    for i in  in_pref.first.. in_pref.last
    LOOP
    /* Derive the product and user dim numbers */
    begin
    select prod_dim_nb into  v_prod_dim_nb from prod_dim where prod_cd=in_pref(i).prod_cd ;
    EXCEPTION
        WHEN NO_DATA_FOUND THEN
            p_error_code := sqlcode;
            p_error_msg := SQLERRM;
            raise v_product_exception;
    end;
    BEGIN
    select usr_dim_nb into v_usr_dim_nb from usr_xref where usr_id=in_pref(i).usr_id and sys_id='ACCESS';
    EXCEPTION
        WHEN NO_DATA_FOUND THEN
            p_error_code := sqlcode;
            p_error_msg := SQLERRM ;
            raise v_product_exception;
          raise v_user_exception;
    END;
    /* check if the record already exist in usr_prod_pref corresponding to that  user,prod,pref */
    select count(1) into v_count from usr_prod_pref_test where prod_dim_nb=v_prod_dim_nb and usr_dim_nb=v_usr_dim_nb and pref_cd=in_pref(i).pref_cd;
    if v_count=0 then
    BEGIN
    INSERT INTO USR_PROD_PREF_TEST values(v_usr_dim_nb,in_pref(i).pref_cd,v_prod_dim_nb,in_pref(i).DFLT_PREF_VAL_TX,in_pref(i).usr_PREF_VAL_TX,'Active',NULL,
    in_pref(i).cre_usr_id,sysdate,in_pref(i).updt_usr_id,NULL);
    END;
    else
    update USR_PROD_PREF_TEST set USR_PREF_VAL_TX=in_pref(i).USR_PREF_VAL_TX,DFLT_PREF_VAL_TX=in_pref(i).DFLT_PREF_VAL_TX,UPDT_USR_ID=in_pref(i).updt_usr_id,updt_dt=sysdate,cre_usr_id=in_pref(i).cre_usr_id where
    prod_dim_nb=v_prod_dim_nb and usr_dim_nb=v_usr_dim_nb and pref_cd=in_pref(i).pref_cd;
    end if;
    end loop;
    commit;
    v_status_message:='SUCCESS';
    exception
    when v_product_exception then
    v_status_message:= 'invalid product code  '||p_error_code||p_error_msg;
    when v_user_exception then
    v_status_message:= 'invalid user'||p_error_code||p_error_msg;
    end;
    /Edited by: raj_fresher on Oct 9, 2009 7:33 AM

  • Can we pass the HashMap object to Stored procedure using toplink

    Can we send the java.util.Map object as input to the stored procedures.
    Can any one please tell how we can do this using toplink.
    I tried to do that by doing following steps
    1. Crated the
    -- Column Name - Value Pair
    CREATE TYPE col_data_pair IS OBJECT (column_name varchar2(50), data VARCHAR2(32767))
    2. create or replace PROCEDURE XL_MAP_TEST (poData In COL_DATA_PAIR) as
    v_timestamp TIMESTAMP;
    BEGIN
    INSERT INTO RECON_ATTR_UD_TFCHILD(RECON_TABLE_KEY, RE_KEY, RECON_UD_TESTFORM_KEY,RECON_UD_TFCHILD_GROUP)
    values (RECON_TABLE_KEY_SEQ.NEXTVAL,15, 25 ,'Persistentss23');
    END XL_MAP_TEST;
    3. .
    [junit] Exception [TOPLINK-4002] (Oracle TopLink - 11g Release 1 (11.1.1.0.0) (Build 080121)): oracle.toplink.exceptions.DatabaseException
    [junit] Internal Exception: java.sql.SQLException: Invalid column type
    [junit] Error Code: 17004
    [junit] Call: BEGIN XL_MAP_TEST(?); END;
    [junit] bind => [null => poData]
    [junit] Query: ValueReadQuery()
    [junit] at oracle.toplink.exceptions.DatabaseException.sqlException(DatabaseException.java:304)
    [junit] at oracle.toplink.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:613)
    [junit] at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:467)
    [junit] at oracle.toplink.threetier.ServerSession.executeCall(ServerSession.java:447)
    [junit] at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193)
    [junit] at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:179)
    [junit] at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:250)
    [junit] at oracle.toplink.internal.queryframework.DatasourceCallQueryMechanism.executeSelect(DatasourceCallQueryMechanism.java:232)
    [junit] at oracle.toplink.queryframework.DirectReadQuery.executeNonCursor(DirectReadQuery.java:92)
    [junit] at oracle.toplink.queryframework.DataReadQuery.executeDatabaseQuery(DataReadQuery.java:118)
    [junit] at oracle.toplink.queryframework.ValueReadQuery.executeDatabaseQuery(ValueReadQuery.java:55)
    [junit] at oracle.toplink.queryframework.DatabaseQuery.execute(DatabaseQuery.java:671)
    [junit] at oracle.toplink.queryframework.DataReadQuery.execute(DataReadQuery.java:104)
    [junit] at oracle.toplink.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:2260)
    [junit] at oracle.toplink.internal.sessions.AbstractSession.executeQuery(AbstractSession.java
    [junit] Caused by: java.sql.SQLException: Invalid column type
    [junit] at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
    [junit] at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:110)
    [junit] at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:171)
    [junit] at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:
    4. StoredProcedureCall spc = new StoredProcedureCall();
    HashMap poData = new HashMap();
    poData.put("d", "s");
    poData.put("s", "s");
    spc.setProcedureName(procedureName);
    spc.addUnamedInOutputArgument("poData", "poData", Types.OTHER,
    "COL_DATA_PAIR",HashMap.class);
    ValueReadQuery query = new ValueReadQuery();
    query.setCall(spc);
    query.addArgument("poData");
    Vector args = new Vector();
    args.add(poData);
    session.executeQuery(query, args);

    Hi
    Thanks for your inputs. Can you please send me the code stuff how we can use ObjectRelationalDescriptor. I tried to do that by doing following steps
    1. Crated one class
    oracle.InputOfTypeMap poData =
                        new oracle.InputOfTypeMap();
    poData.setKay("ddd");
    poData.setValue("ddd");
    2. oracle.toplink.objectrelational.ObjectRelationalDescriptor descriptor =
         new oracle.toplink.objectrelational.ObjectRelationalDescriptor();          descriptor.setJavaClass(oracle.iam.reconciliation.vo.InputOfTypeMap.class);      
              descriptor.setStructureName("COL_DATA_PAIR");      
              descriptor.addFieldOrdering("column_name");
              descriptor.addFieldOrdering("data");      
              descriptor.addDirectMapping("key", "column_name");
              descriptor.addDirectMapping("value", "data");
    3. I was not sure how to use this further StoredProcedureCall
    Can you plese help me, how we can do that?

Maybe you are looking for

  • How to get rid of "unchecked or unsafe operation" in J2SE 5.0?

    There is always such inofmration after I compile the code. How can I check if the code contains unchecked or unsafe operation"?

  • House Bank for Vendor

    Dear FI experts, My client need that No of House Banks are assigned for one vendor . Is it possible to make that assignment If possible pl give me the solution. Venkata Raju Khottari

  • Register system r3 in the portal transaction rz70

    Please helpme. I have a problem, I need register my system r3 in the portral but I can´t The follow is the error Error when opening an RFC connection ERROR: file communicate with  gateway SAP ¿ Gateway SAP started. In the potal sld  I put this parame

  • [SOLVED] Looking for an audio player; specific requirements

    I've searched around and can't really find what I'm looking for in an audio player(though Audacious and Exaile come close). What I need is one with these aspects: - Based on GTK+ - Relatively lightweight - Skinnable I'd like something with a look sim

  • Photoshop CS6 + CS5

    Will I be able to run CS6 alongside CS5 hassle-free?