How to pass a user defined table type to stored procedure?

Hi,
I am trying to call a stored procedure from Java. The store procedure has three IN parameter, 2 IN/OUT params and 3 OUT parameters. The two IN/OUT parameters are user defined objects. Can anyone tell me how to set these IN/OUT parameters in Java.
Thanks

It is database/driver specific so you need to use the specific functionality of the driver (not jdbc) to access it.

Similar Messages

  • How do i declare a user defined table type sproc parameter as a local variable?

    I have a procedure that uses a user defined table type.
    I am trying to redeclare the @accountList parameter into a local variable but it's not working and says that i must declare the scalar variable @accountList.this is the line that is having the issue: must declare the scalar variable @accountListSET @local_accountList = @accountListALTER PROCEDURE [dbo].[sp_DynamicNumberVisits] @accountList AS integer_list_tbltype READONLY
    ,@startDate NVARCHAR(50)
    ,@endDate NVARCHAR(50)
    AS
    BEGIN
    DECLARE @local_accountList AS integer_list_tbltype
    DECLARE @local_startDate AS NVARCHAR(50)
    DECLARE @local_endDate AS NVARCHAR(50)
    SET @local_accountList = @accountList
    SET @local_startDate = @startDate
    SET @local_endDate = @endDate
    CREATE TYPE [dbo].[integer_list_tbltype] AS TABLE(
    [n] [int] NOT NULL,
    PRIMARY KEY CLUSTERED
    [n] ASC
    )WITH (IGNORE_DUP_KEY = OFF)
    GO

    Why are you asking how to be an awful SQL programmer??  Your whole approach to SQL is wrong.
    We have a DATE data type so your insanely long NVARCHAR(50) of Chinese Unicode strings is absurd. Perhaps you can post your careful research on this? Can you post one example of a fifty character date in any language? 
    The use of the "sp_" prefix has special meaning in T-SQL dialect. Good SQL programmers do not use CREATE TYPE for anything. It is dialect and useless. It is how OO programmers fake it in SQL. 
    The design flaw of using a "tbl-" prefix on town names is called "tibbling" and we laugh at it. 
    There are no lists in RDBMS; all values are shown as scalar values. First Normal Form (1NF)? This looks like a set, which would have a name. 
    In any -- repeat any -- declarative programming language, we do not use local variables. You have done nothing right at any level. You need more help than forum kludges. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • User defined table types sometimes show up a unknown data type in Profiler

    A couple of our users have a problem when using user defined table types. Calls are made using UDTT as variables and these are then passed to a stored procedure as parameters. Sometimes the application returns a timeout. In such situations a Profiler-Trace
    shows the following:
    declare @p4 unknown
    whereas the correct trace (that is sometimes displayed) should be:
    declare @p4 dbo.ReportFilterTableType
    ReportFilterTableType is a UDTT. The users do have correct permissions for the UDTT (otherwise they would never be usable for the user). What could be the reason that the data types for the variable
    @p4 in the example are sometimes returned as unknown and at other times are returned correctly as
    ReportFilterTableType? Could this possibly be a network related issue?
    Thank you.
    Graham Goodwin Email: [email protected]

    I know this is a old post, but i am also facing the same issue that too in my production server. Did you find any workarround for this issue. Please do reply. Critical problem we are facing.
    Alka, Is your problem timeouts when passing TVP parameters, or is it that a Profiler Trace shows type "unknown" for the TVP data type name?
    If your problem is timeouts, be aware that TVPs do not have statistics so the optimizer might not be able to generate an optimal plan for non-trivial queries. Declaring a primary key or unique constraint on the table type may help since that will provide
    useful cardinality information.  You may need to resort to hints in some cases.
    I suggest you start a new thread with details of your specific situation if the information in this thread doesn't help.
    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

  • User defined table type output not coming

    hi all,
    i have a userdefined type delcared as:
    create or replace TYPE SAMPLE_SEARCH AS OBJECT (
    -- LIST OF VARIABLE NAMES AND RESPECTIVE DATA TYPE
    i have a user defined table type defined as:
    create or replace TYPE SAMPLE_SEARCH_TABLE IS TABLE OF SAMPLE_SEARCH;
    I have a stored proc which has an output paramter of type SAMPLE_sEARCH_TABLE.
    that is,
    sp_sample_proc(sample_search_tb OUT SAMPLE_SEARCH_TABLE);
    When i invoke the above stored proc from an anonymous pl/sql block , how can i display the contents of the output parameter using dbms_Output statements?

    Try this.........This is just a sample code.
    CREATE OR REPLACE TYPE address1 AS OBJECT
    (country VARCHAR2(1000),
    city VARCHAR2(1000),
    zip NUMBER,
    add1 VARCHAR2(4000),
    add2 VARCHAR2(4000));
    CREATE OR REPLACE TYPE t_addObj IS TABLE OF address1;
    CREATE OR REPLACE PROCEDURE Sp_Address_Obj(Out_Add_Obj OUT t_Addobj) IS
    v_Addobj t_Addobj := t_Addobj();
    BEGIN
    SELECT Address1(u.Object_Name,
    u.Object_Type,
    u.Object_Id,
    'Add01' || Rownum,
    'Add02' || Rownum) BULK COLLECT
    INTO v_Addobj
    FROM User_Objects u;
    Out_Add_Obj := v_Addobj;
    END Sp_Address_Obj;
    DECLARE
    v_Addobj t_Addobj := t_Addobj();
    BEGIN
    Sp_Address_Obj(v_Addobj);
    Dbms_Output.Put_Line(v_Addobj(1).City);
    FOR i IN 1 .. v_Addobj.Count LOOP
    Dbms_Output.Put_Line(v_Addobj(i).Country || '-' ||
    v_Addobj(i).City || '-' ||
    v_Addobj(i).Zip || '-' ||
    v_Addobj(i).Add1 || '-' ||
    v_Addobj(i).Add2);
    END LOOP;
    END;

  • How to reference a pre-defined table type in entity definition

    I have a Table Type brc.sapere.gso.DDL::domain.TIME_PERIOD defined.
    I try to use it in an entity definition. (dbcommon.hdbdd is attached.)
    But there is an error saying
    ERROR      brc/sapere/gso/DDL/dbcommon.hdbdd
               CDS activation failed;Full qualified names are not allowed
    How can I reference the table type?

    Kalhari wrote:
    Hi, Thanks, but I've seen this. What I need to know is if there is a way to map "user defined table type" specifically, which is a new SQL type introduced with SQL 2008.1. Depends on the database.
    2. Depends on the JDBC driver
    3. Depends on JDBC spec that it being used.

  • Syntax error when creating a user-defined table type in SQL Server 2012

    Why am I getting a syntax error when creating a user-defined table type in SQL Server 2014?
    CREATE TYPE ReportsTableType AS TABLE 
    ( reportId INT
    , questionId INT
    , questionOrder INT );
    Results:
    Msg 156, Level 15, State 1, Line 1
    Incorrect syntax near the keyword 'AS'.

    Hope these posts could help, 
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/37a45a9a-ed8c-4655-be93-f6e6d5ef44be/getting-incorrect-syntax-while-creating-a-table-type-in-sql-server-2008-r2?forum=transactsql
    Regards, Dineshkumar,
    Please Mark as Answer if my post answers your question and
    Vote as Helpful if it helps you

  • User-Defined Table Types - Where is it in SQL Server 2008?

    I am having 2 issues:
    1.  I don't see a folder for 'User-Defined Table Types' under programmability-->Types
    2.  When I execute the following code to create a Type; I get an error 'Incorrect syntax near the keyword 'AS'.'
    USE Locations;
    GO
    /* Create a user-defined table type */
    CREATE TYPE LocationTableType AS TABLE
    ( LocationName VARCHAR(50)
    , CostRate INT );
    GO

    Hi Shayann,
    The  user-defined table type is a new
    feature from SQL Server 2008. If you want to use it you have to upgrade your database to SQL Server 2008 or above.
    In you scenario(SQL Server 2005),as a workaround, you can use the  local temporary table instead. 
    --in SQL Server 2005
    CREATE TABLE tblType(id INT,name VARCHAR(99))
    GO
    CREATE PROC proc1
    AS
    BEGIN
    SELECT * FROM #temp;
    END
    GO
    SELECT * INTO #temp FROM tblType; -- the #temp name is fixed
    INSERT INTO #temp VALUES(1,'Eric');
    EXEC proc1
    --In SQL Server 2008 or above
    CREATE TYPE LocationTableType AS TABLE
    ( id INT,
    name VARCHAR(99) );
    GO
    CREATE PROC proc1 @t LocationTableType READONLY
    AS
    BEGIN
    SELECT * FROM @t
    END
    GO
    DECLARE @t LocationTableType;
    INSERT INTO @t VALUES(1,'Eric');
    EXEC proc1 @t
    I still suggest you upgrade to higher SQL Server.
    If you have any question, feel free to let me know.
    Best regards,
    Eric

  • "user defined exception" in a stored procedure and APEX

    I would like to use user defined exception in a stored procedure or trigger in a APEX application.
    Does anybody know how to do it ? or know where can I find a good reference ?
    Thanks,

    raise_application_error(-20001, 'error message');
    Scott

  • Pass an array of a user defined class to a stored procedure in java

    Hi All,
    I am trying to pass an array of a user defined class as an input parameter to a stored procedure. So far i have done the following:
    Step 1: created an object type.
    CREATE TYPE department_type AS OBJECT (
    DNO NUMBER (10),
    NAME VARCHAR2 (50),
    LOCATION VARCHAR2 (50)
    Step 2: created a varray of the above type.
    CREATE TYPE dept_array1 AS TABLE OF department_type;
    Step 3:Created a package to insert the records.
    CREATE OR REPLACE PACKAGE objecttype
    AS
    PROCEDURE insert_object (d dept_array);
    END objecttype;
    CREATE OR REPLACE PACKAGE BODY objecttype
    AS
    PROCEDURE insert_object (d dept_array)
    AS
    BEGIN
    FOR i IN d.FIRST .. d.LAST
    LOOP
    INSERT INTO department
    VALUES (d (i).dno,d (i).name,d (i).location);
    END LOOP;
    END insert_object;
    END objecttype;
    Step 4:Created a java class to map the columns of the object type.
    public class Department
    private double DNO;
    private String Name;
    private String Loation;
    public void setDNO(double DNO)
    this.DNO = DNO;
    public double getDNO()
    return DNO;
    public void setName(String Name)
    this.Name = Name;
    public String getName()
    return Name;
    public void setLoation(String Loation)
    this.Loation = Loation;
    public String getLoation()
    return Loation;
    Step 5: created a method to call the stored procedure.
    public static void main(String arg[]){
    try{
    Department d1 = new Department();
    d1.setDNO(1); d1.setName("Accounts"); d1.setLoation("LHR");
    Department d2 = new Department();
    d2.setDNO(2); d2.setName("HR"); d2.setLoation("ISB");
    Department[] deptArray = {d1,d2};
    OracleCallableStatement callStatement = null;
    DBConnection dbConnection= DBConnection.getInstance();
    Connection cn = dbConnection.getDBConnection(false); //using a framework to get connections
    ArrayDescriptor arrayDept = ArrayDescriptor.createDescriptor("DEPT_ARRAY", cn);
    ARRAY deptArrayObject = new ARRAY(arrayDept, cn, deptArray); //I get an SQLException here
    callStatement = (OracleCallableStatement)cn.prepareCall("{call objecttype.insert_object(?)}");
    ((OracleCallableStatement)callStatement).setArray(1, deptArrayObject);
    callStatement.executeUpdate();
    cn.commit();
    catch(Exception e){ 
    System.out.println(e.toString());
    I get the following exception:
    java.sql.SQLException: Fail to convert to internal representation
    My question is can I pass an array to a stored procedure like this and if so please help me reslove the exception.
    Thank you in advance.

    OK I am back again and seems like talking to myself. Anyways i had a talk with one of the java developers in my team and he said that making an array of structs is not much use to them as they already have a java bean/VO class defined and they want to send an array of its objects to the database not structs so I made the following changes to their java class. (Again hoping some one will find this useful).
    Setp1: I implemented the SQLData interface on the department VO class.
    import java.sql.SQLData;
    import java.sql.SQLOutput;
    import java.sql.SQLInput;
    import java.sql.SQLException;
    public class Department implements SQLData
    private double DNO;
    private String Name;
    private String Location;
    public void setDNO(double DNO)
    this.DNO = DNO;
    public double getDNO()
    return DNO;
    public void setName(String Name)
    this.Name = Name;
    public String getName()
    return Name;
    public void setLocation(String Location)
    this.Location = Location;
    public String getLoation()
    return Location;
    public void readSQL(SQLInput stream, String typeName)throws SQLException
    public void writeSQL(SQLOutput stream)throws SQLException
    stream.writeDouble(this.DNO);
    stream.writeString(this.Name);
    stream.writeString(this.Location);
    public String getSQLTypeName() throws SQLException
    return "DOCCOMPLY.DEPARTMENT_TYPE";
    Step 2: I made the following changes to the main method.
    public static void main(String arg[]){
    try{
    Department d1 = new Department();
    d1.setDNO(1);
    d1.setName("CPM");
    d1.setLocation("LHR");
    Department d2 = new Department();
    d2.setDNO(2);
    d2.setName("Admin");
    d2.setLocation("ISB");
    Department[] deptArray = {d1,d2};
    OracleCallableStatement callStatement = null;
    DBConnection dbConnection= DBConnection.getInstance();
    Connection cn = dbConnection.getDBConnection(false);
    ArrayDescriptor arrayDept = ArrayDescriptor.createDescriptor("DEPT_ARRAY", cn);
    ARRAY deptArrayObject = new ARRAY(arrayDept, cn, deptArray);
    callStatement = (OracleCallableStatement)cn.prepareCall("{call objecttype.insert_array_object(?)}");
    ((OracleCallableStatement)callStatement).setArray(1, deptArrayObject);
    callStatement.executeUpdate();
    cn.commit();
    catch(Exception e){
    System.out.println(e.toString());
    and it started working no more SQLException. (The changes to the department class were done manfully but they tell me JPublisher would have been better).
    Regards,
    Shiraz

  • 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

  • How to pass a list of IDs to a stored procedure ?

    Hi All,
    My table has two columns customerID (int) and customerName
    I want to write a stored procedure that will get a list of integers and then return all the customers names associated with these IDs. How to do that ?
    Thanks

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    <Removed unrelated comments>
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking in
    Sets / Trees and Hierarchies in SQL

  • How to pass a "user defined" object to a thread?

    Hi...
    I have created an object say 'obj1' . I want to pass to a thread say 'T1' .
    The thread T1 implements the runnable class.
    I need to pass the "obj1" object to the T1 for it to be processed in the "run" method of T1.
    As far as I have seen there is no thread constructor in Java that accepts an object created by the user.
    My question is there any way to pass an object to a thread? and if so how can it be done?

    You can just add your own method to the class. Then call that method to pass the object to the thread before you call start on the thread.
    class MyThread implements Runnable
       public void run()
          userObj.whatever();
       public void addObj(Object obj)
          userObj = obj;
       Object userObj = null;
    // your code
    MyThread thread = new MyThread();
    thread.addObj(myObj);
    thread.start();As long as you don't call start before your pass the object to your thread, then you won't have a problem. Hope this helps.

  • How to pass parameters when we create datablock through stored procedure..

    I have one table emp table.
    I have created one package pk_ref_cursor,In that my recursor return type is record type.
    I created one procedure p_test with two parameters...
    1. ref cursor type
    2. deptno
    Now i created one data block through procedure...
    Then i run my form it's giving no records.Because i am not passing parameter deptno.
    Now i go to block property 'QUERY DATA SOURCE ARGUMENTS'.Here i set the parameter p_deptno is 20
    Then i run the form it's giving some records for deptno 20.
    But every time i cannot open fmb form and change the property.
    Is there any way to pass parameter..
    Just see my code...
    --Package spec
    CREATE OR REPLACE PACKAGE pk_ref_cursor IS
    TYPE p_record IS RECORD(p_num emp.empno%TYPE,
    p_name emp.ename%TYPE);
    TYPE p_ref IS REF CURSOR RETURN p_record;
    PROCEDURE p_test(p_data IN OUT p_ref,p_deptno IN NUMBER);
    END pk_ref_cursor;
    --Package body
    CREATE OR REPLACE PACKAGE BODY pk_ref_cursor IS
    PROCEDURE p_test(p_data IN OUT p_ref,p_deptno IN NUMBER) IS
    BEGIN
    OPEN p_data FOR SELECT empno,ename FROM EMP WHERE deptno = p_deptno;
    END;     
    END pk_ref_cursor;
    Thanks,

    But how to use package variables...
    Can u show me one example..

  • How to register OUT param to  RECORD type for STORED PROCEDURE???

    hi
    i have a SP like this
    CREATE OR REPLACE PACKAGE P1 AS
    TYPE g_con_ref_cursor is REF CURSOR ;
    TYPE g_con_error IS RECORD
      error_code NUMBER,
      error_desc varchar2(2000)
    PROCEDURE PROC_CURSOR
    (i_str_userid  IN VARCHAR2,
      o_cur_ref_cur OUT g_con_ref_cursor,
      o_rec_error   OUT g_con_error,
      o_num_status  OUT NUMBER);
    END;and now i am trying to call this SP using my java program
    i am able to register the out put params for 2nd and 4 th variable
    my doubt is how i can register the output param for 3rd (g_con_error) which is of record type
    and how i can get result from this ????
    my java program is like this
    Connection connection = DatabaseHelper.prepareConnection();
    CallableStatement proc = connection.prepareCall("{ call P1.PROC_CURSOR(?, ?, ?, ?) }");
    proc.setString(1,"jn26557");
    proc.registerOutParameter(2,oracle.jdbc.driver.OracleTypes.CURSOR);
    proc.registerOutParameter(3,???,????); //HOW TO SET  THIS ?????
    proc.registerOutParameter(4,oracle.jdbc.driver.OracleTypes.NUMERIC);
    proc.execute();plz help me in this
    i have no idea how to do it
    any help would be appreciated
    Thanks in advance
    Jaya Prakash Nalajala

    You might give a try using:
    proc.registerOutParameter(3, java.sql.Types.REF, "RECORD");

  • Issue in passing Oracle User Defined Types to PL SQL from Websphere Applica

    HI,
    I am facing an issue when trying to pass Oracle collection object(User Defined Types) from Java to PL SQL. The issue happens inside J2EE application which is running inside Websphere Application Server 6.x. My database is Oracle 10g and i am using ojdbc1.4.jar as thin driver.
    The issue is that when i pass the Oracle Object from java side, the attribute values of the collection objects at the Oracle PL SQL side is coming as empty. I have tried the same java code in a standalone application and it works fine. The issue happens only when the application is running inside WAS.
    Anybody has any idea how to pass Oracle User Defined Types from WAS 6.x server to Oracle PL SQL?

    Andy Bowes wrote:
    Hi
    I am using WebLogic 8.14 & Oracle 9i with thin JDBC driver.
    Our application needs to perform the same DB operation for every item in a Java Collection. I cannot acheive the required performance using the standard Prepare & Execute loop and so I am looking to push the whole collection to Oracle in a single invocation of a Stored Procedure and then loop on the database.
    Summary of Approach:
    In the Oracle database, we have defined a Object Type :
    CREATE OR REPLACE
    TYPE MYTYPE AS OBJECT
    TxnId VARCHAR2(40),
    Target VARCHAR2(20),
    Source VARCHAR2(20),
    Param1 VARCHAR2(2048),
    Param2 VARCHAR2(2048),
    Param3 VARCHAR2(2048),
    Param4 VARCHAR2(2048),
    Param5 VARCHAR2(2048),
    and we have defined a collection of these as:
    CREATE OR REPLACE
    TYPE MYTYPE_COLLECTION AS VARRAY (100) OF MYTYPE
    There is a stored procedure which takes one of these collections as an input parameter and I need to invoke these from within my code.
    I am having major problems when I attempt to get the ArrayDescriptor etc to allow me to create an Array to pass to the stored procedure. I think this is because the underlying Oracle connection is wrapped by WebLogic.
    Has anyone managed to pass an array to an Oracle Stored procedure on a pooled DB connection?
    Thanks
    AndyHi. Here's what I suggest: First please get the JDBC you want to work in a
    small standalone program that uses the Oracle thin driver directly. Once
    that works, show me the JDBC code, and I will see what translation if
    any is needed to make it work with WLS. Will your code be running in
    WebLogic, or in an external client talking to WebLogic?
    Also, have you tried the executeBatch() methods to see if you can
    get the performance you want via batches?
    Joe

Maybe you are looking for