How to pass an object of the stored procedure?

Hello.

After reading the documentation online 'The JDBC Oracle9i developer reference Guide' how to use oracle.sql.STRUCT to pass the java classes to database objects and how do the same thing in the sense opposite, I still don't know how to do what I need, I would like to know a few resourse online where I could find more examples.
I guess it must be quite easy to do.

I learned to create a java class that will be used to call a stored procedure (9i database) that has a single input/output parameter whose type is a user-defined object.

I'm trying to do something similar, by I was not able. This is my essay:

CREATE OR REPLACE TYPE                  FERNANDO.TIPOBD AS OBJECT (   ID INTEGER,   NOMBRE VARCHAR2(50),   HORA TIMESTAMP ); / CREATE OR REPLACE PACKAGE FERNANDO.prueba_java AS   PROCEDURE prueba (objetoJava IN OUT TIPOBD); END prueba_java; / CREATE OR REPLACE PACKAGE BODY FERNANDO.prueba_java AS   PROCEDURE prueba (objetojava IN OUT TIPOBD)   AS   BEGIN       NULL;   END prueba; END prueba_java; /
import java.sql.*; //import oracle.sql.*; import oracle.jdbc.*; import oracle.sql.*; public class Prueba { public static void main(String[] args) { Connection conexion = GestorConexion.getConexion(); if (conexion != null) {   try {     DatabaseMetaData meta = conexion.getMetaData();     System.out.println("JDBC driver version is " + meta.getDriverVersion()); int num = 0; String consulta = "select 1 from dual"; PreparedStatement ps = conexion.prepareStatement(consulta); ResultSet rs = ps.executeQuery(); if (rs.next()) { num = rs.getInt(1); } System.out.println("num == "+num); ObjetoOracle oo = new ObjetoOracle(1, "Fernando", new Timestamp(1) ); System.out.println("id: "+oo.getId()+"; nombre: "+oo.getNombre()); // Se llama al procedimiento almacenado String llamada = new String(); llamada += "BEGIN "; llamada += "  FERNANDO.prueba_java.prueba(?)"; llamada += "END;"; StructDescriptor structdesc = StructDescriptor.createDescriptor("FERNANDO.TIPOBD", conexion); STRUCT struct = new STRUCT(structdesc, conexion, null); OracleCallableStatement ca = (OracleCallableStatement)conexion.prepareCall(llamada); //ca.setObject(1, oo); ca.setObject(1, null); ca.registerOutParameter(1, OracleTypes.JAVA_OBJECT); ca.execute(); } catch (SQLException sqle) { System.out.println(sqle.toString()); } } else { System.out.println("CONEXIÓN con bd nula"); } } }

My if intend to create an oracle.sql.STRUCT object that I'll pass to the procedure and then get back to the procedure, but I can not even create the StructDescriptor.
It is the output that I get:

Conexión con BD ok JDBC driver version is 9.2.0.8.0 num == 1 id: 1; nombre: Fernando java.sql.SQLException: Tipo no definido: get_next_type

Any help would be welcome. Thanks in advance.

You must add the name of the type of your call registerOutParameter (.).
ca.registerOutParameter ("", OracleTypes.JAVA_OBJECT, FERNANDO. TIPOBD);

You can consider using OracleTypes.STRUCT instead of JAVA_OBJECT.

You must also change your call set *;.
ca.setObject ("", FERNANDO of the object. TIPOBD, OracleTypes.STUCT);

You can use the same string parameter "" to the two parameters or
You can use the same parameter INT for both parameters.

You cannot combine parameters named and numbered together. I was using both for a single method or both using the other.
The syntax may be different according to the method you in order to verify the Java Doc.

Tags: Oracle

Similar Questions

  • How to create a table in a stored procedure

    Please help me to answer the following question...

    How to create a table inside the stored procedure... I want a detailed explanation... Please help me

    Please see this link:
    http://tinyurl.com/cmq5vo

  • Passing an array as a parameter of java (java controls) for the stored procedure

    Hello

    I use java controls (BEA Weblogic Workshop 8.1) to call a stored procedure and send an array as a parameter to the stored procedure of java. The following code throws an exception 'Fail to convert the internal representation.

    Java code
    import com.bea.control.DatabaseControl.SQLParameter;

    Here I create the java
    int [] = {12,13,14} javaArray.

    The code below is used to create the table from sql to oracle for the procedure
    SQLParameter [] params = new SQLParameter [1];
    Object obj0 = javaArray;
    params [0] = new SQLParameter (obj0, oracle.jdbc.OracleTypes.ARRAY, SQLParameter.IN);

    the code below calls the myFunc in file OJDBCtrl.jcx
    String success = dbControl.testFunc (params);

    OJDBCtrl.jcx
    /**
    * @jc: = sql statement ' call CMNT_TST_PROC (?)).
    */
    String Myfunc (SQLParameter [] param);

    The stored procedure that is used:

    SL_tab IS NUMBER TABLE INDEX BY PLS_INTEGER;
    Procedure cmnt_tst_proc (cmnt_tst sl_tab);
    Procedure cmnt_tst_proc (cmnt_tst sl_tab) is
    BEGIN
    dbms_output.put_line ('Hello');
    END;


    I'm getting the following exception

    Failure = Java.Sql.SqlException: Internal failure to convert the representation: [I@438af4 [ServiceException] >]
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:162)
    at oracle.jdbc.driver.DatabaseError.check_error(DatabaseError.java:861)
    at oracle.sql.ARRAY.toARRAY(ARRAY.java:210)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:7768)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7449)
    at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7837)
    at oracle.jdbc.driver.OracleCallableStatement.setObject(OracleCallableStatement.java:4587)
    at weblogic.jdbc.wrapper.PreparedStatement.setObject(PreparedStatement.java:244)
    at com.bea.wlw.runtime.core.control.DatabaseControlImpl._setParameter(DatabaseControlImpl.jcs:1886)
    at com.bea.wlw.runtime.core.control.DatabaseControlImpl.getStatement_v2(DatabaseControlImpl.jcs:1732)
    at com.bea.wlw.runtime.core.control.DatabaseControlImpl.invoke(DatabaseControlImpl.jcs:2591)
    at com.bea.wlw.runtime.core.dispatcher.DispMethod.invoke(DispMethod.java:377)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:433)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:406)
    at com.bea.wlw.runtime.core.container.Invocable.invoke(Invocable.java:249)
    at com.bea.wlw.runtime.jcs.container.JcsContainer.invoke(JcsContainer.java:85)
    at com.bea.wlw.runtime.core.bean.BaseContainerBean.invokeBase(BaseContainerBean.java:224)
    at com.bea.wlw.runtime.core.bean.SLSBContainerBean.invoke(SLSBContainerBean.java:109)
    at com.bea.wlwgen.StatelessContainer_ly05hg_ELOImpl.invoke(StatelessContainer_ly05hg_ELOImpl.java:153)
    ...

    Can you please let me know, what am I doing wrong and how can I pass an array to a procedure/function using java controls.

    Any help will be much appreciated.



    Published by: user12671762 on February 24, 2010 05:03

    Published by: user9211663 on February 24, 2010 21:04

    Try using an oracle.sql.ARRAY with a nested table or varray instead of a table index. Create the type SQL and Java object as follows

        SQL> create type sl_tab as varray(3) of integer;
        Java:
            ArrayDescriptor ad = ArrayDescriptor.createDescriptor
                (".SL_TAB", java.sql.Connection);
            Object elements = new Object[3];
            elements[0] = new Integer(12);
            elements[1] = new Integer(13);
            elements[2] = new Integer(14);
            oracle.sql.ARRAY array =
                new oracle.sql.ARRAY(ad, oracle.jdbc.OracleTypes.ARRAY, elements);
            SQLParameter[] params = new SQLParameter[1];
            params[0] =
                new SQLParameter(array, oracle.jdbc.OracleTypes.ARRAY, SQLParameter.IN);
            String succ = dbControl.testFunc(params);
    

    I don't think that you can pass an array of Java, this is why you have more success using an oracle.sql.ARRAY with a SQL varray. -Michael-

  • How can I transfer content from an XML file in a MS SQL database of the stored procedure using LabWindows/CVI SQL Toolkit?

    Hello

    I have a problem to transfer content to an XML file in a MS SQL database through a stored procedure data/fixed. I am able to transfer the content of the file using method...

    HSTMT = DBPrepareSQL (hdbc, EXEC usp_InsertReport " ... ");

    resCode = DBExecutePreparedSQL (hstmt);

    resCode = DBClosePreparedSQL (hstmt);

    ... but in this case, I am not able to read the return value of the stored procedure.

    I tried to follow the example of the stored procedure in the help documentation (DBPrepareSQL), but I miss a xml data type?

    No idea how to solve my problem?

    Cake of KR

    DianaS salvation,

    Thanks for your comments. During this time I found another way which fullfill my needs:

    resCode = DBSetAttributeDefault (hdbc, ATTR_DB_COMMAND_TYPE, DB_COMMAND_TEXT);

    sprintf (sz_SqlStatement, "DECLARE @TESTID INT EXEC @TESTID = usp_InsertReport ' SELECT 'RetVal' %s = @TESTID", sz_Buffer ");
    HSTMT = DBActivateSQL (hdbc, sz_SqlStatement);

    While ((resCode = DBFetchNext (hstmt)) == DB_SUCCESS)

    {

    / * Enter values in the record. */

    resCode = DBGetColInt (hstmt, 1, & s32_TestId);
    }

    resCode = DBDeactivateSQL (hstmt);

    sz_Buffer is the content of the XML file.

    Cake of KR

  • How can I force DAC to run always full load for one of the task that executes the stored procedure? And remaining tasks load incremental in the second and sub sequent executions.

    Hello

    How can I force DAC to run always full load for one of the task that executes the stored procedure? And remaining tasks load incremental in the second and sub sequent executions.

    Thank you

    Jay.

    Hi if your task is running an informatica mapping you can set your DAC task to run the full mapping for incremental and full loads, so tab task just point to the mapping.

    Hope that helps.

    Thank you

  • How you cloud an object on the pdf

    How you cloud an object on the pdf

    Hi steveg8884273,

    You can use the drawing tools & markup in the comments Acrobat Help toolbar | Commenting in a PDF file.

    Kind regards

    Nicos

  • How to make an object follow the mouseX when clicked on

    How to make an object follow the mouseX if clicked? Help, please.

    You should think it through - your code does not match your very simple explanation of what you say, it should do so, and it should... click an element and follow the mouse.

    A game loop (ENTER_FRAME) could work, but in this case it wastes unnecessary treatment if the mouse does not move.  And in your code example, it does not expect the clicks.

    Use a MOUSE_MOVE instead of an ENTER_FRAME event listener.  Inside of the event by clicking on the handler function is where you must be defined the MOUSE_MOVE listener.  The MOUSE_MOVE listener Manager is where you assign rock1Cnt.x = mouseX.

    public void Main (): void {}

    rock1Cnt.addEventListener (MouseEvent.CLICK, mouseClickHandler);

    }

    private void mouseClickHandler(e:MouseEvent):void {}

    stage.addEventListener (Event.MOUSE_MOVE, followMouse);

    }

    private void followMouse(e:MouseEvent):void {}

    rock1Cnt.x = mouseX

    }

  • How to show the stored procedure code

    Hello
    How can I get the code for creating a stored procedure using sqlplus instead of sql-developer? I want to get all of the code of the stored procedure. I saw it in writing

    SQL > desc proced_1

    I get the Argument Name, Type and input/output by default of the stored procedure, but if I want to get the code 'create procedure', how can I do?
    Thank you!

    Hai

    Try this

    Select * from user_source where name = 'Procedure_name '.
    online ordering;

    Concerning

    Srikkanth.M

  • How to call the stored procedure from javascript? (Google suggest, AJAX)

    Hi I want to set up a text field so that it behaves like [Google Suggest | http://www.google.com/webhp?complete=1 & hl = en].

    I read this post .

    Now, I installed everything according to this document. But it simply doesn't. And I don't know why.

    I think that problems can fall into the following three categories:
    1. the text field and the page invoking the appropriate javascript?
    2 - is the JavaScript call the stored procedure?
    3. the stored procedure correctly returns the result formatted?

    I'm assertive for 1 and 3, but I'm not sure 2. Because I don't know how if a stored procedure has been called? Is there a PL/SQL statement that I can query in SQL * more?

    Also, I would like to know how to debug AJAX in the APEX. It involves a lot of things.

    Finally, I used APEX 3.2 and Oracle XE. I can't find file dads.conf or marvel.conf. Is ' / apex / "the virtual directory for APEX?

    Thank you very much!

    Buffalo,

    I managed to make it work on XE with APEX 3.2!
    It took more time than expected because my XE installation was still on an earlier version of the Apex and I had put it first...

    But that's what I did:
    -in the ac.js file, I changed the path ' / apex / "and I added the ac.js file to my candidacy as a static file. So as you did.
    -J' copied my request to the XE and copied my procedure on the schema that is related to my request
    -J' gave to run anonymous rights my procedure

    Now at first, it did not work...
    Then I suddenly remembered something: If you want to run a procedure through the pl/sql gateway in the XE, XE please how it is.
    Do you this by changing the APEX_030200.wwv_flow_epg_include_mod_local function!

    This is the code for the function changed for my example:

    CREATE OR REPLACE function APEX_030200.wwv_flow_epg_include_mod_local(
        procedure_name in varchar2)
    return boolean
    is
    begin
        --return false; -- remove this statement when you modify this function
        --
        -- Administrator note: the procedure_name input parameter may be in the format:
        --
        --    procedure
        --    schema.procedure
        --    package.procedure
        --    schema.package.procedure
        --
        -- If the expected input parameter is a procedure name only, the IN list code shown below
        -- can be modified to itemize the expected procedure names. Otherwise you must parse the
        -- procedure_name parameter and replace the simple code below with code that will evaluate
        -- all of the cases listed above.
        --
        if upper(procedure_name) in (
              'MATTHIASH.INCSEARCH') then
            return TRUE;
        else
            return FALSE;
        end if;
    end wwv_flow_epg_include_mod_local;
    /
    

    After that, the AJAX function worked as expected...

    HTH
    Matthias Hoys

    Published by: mhoys on August 13, 2009 15:24

  • How to remove unused objects from the webcatalogs?

    Hi friends,

    How to remove unused objects from the webcatalogs?
    is there a utility like the removal of unused objects of the physical layer in RPD?

    Thank you

    Hello

    Click link responses to the left of the answers click on the catalog button manage manage catalog, you can delete the unused objects

    Concerning

    NGO

  • How to view the run log in the stored procedure?

    Hello

    I'm working on a project of migrating from Sybase to Oracle (10g).

    On Sybase, when I run a stored procedure, it will connect to the console as:
    100 rows inserted
    200 rows affected
    ...

    One line per request in the stored procedure.


    Oracle, I only: 'Procedure completed successfully' (Yes, I'm french :-)


    Is there a way to get the logs for each request in my stored procedure?
    -An option?
    -One command after each request?


    Thanks in advance.

    user9321154 wrote:
    OK, it's great.

    Otherwise, there is not an option on Oracle to achieve this same result automatically.

    No, if you want to do this, you must do it yourself. PL/SQL is a real language, not a script like T - SQL language. Therefore, it is the procedure that one is successful or not, not every instruction.

    You should also be aware that if you use % ROWCOUNT SQL to get the number of rows processed and DBMS_OUTPUT. Put_line to show them on the screen, that the output will not appear before once you have completed the process, not as each DBMS_OUTPUT statement is processed.

    If you want to t shelves where in the procedure, you will need to insert the release of record in a table by using an autonomous transaction or something like UTL_FILE use to write the instructions in an o/s file.

    John

  • Call the stored procedure, and bind parameters by name

    Hello

    I use the Oracle ODBC 12 c driver to pass values from one Interface to our database Oracle 11.2. The Interface software collects data from modbus protocoll and calls a stored procedure. Right now my syntax to call the stored procedure looks like this:

    CALL procedure-name ('STRING', 'Timestamp as String', numValue1);

    It works very well. Now, I have to add a default setting to my procedure. To stay flexible to make other changes, I want to call the procedure and bind the parameters by name. Release 10.2.0.1.0 ISC ODBC Notes:

    Added support for the named parameter, binding the parameters by name. ODBC Oracle driver now allows the application to specify the parameters of a stored procedure by name, in the procedure call. Named parameters are to be used in calls to stored procedures and should not be used in other SQL statements.

    So, it shouldn't be a problem to use named notation, but how do I do this in ODBC? I tried like this, but oracle returns an ora-00936 error of missing expression:

    call procedure-name (paramName1 = > 'STRING',= paramName2 > 'Timestamp as String',paramName3 = > numValue1).


    Thank you for your help.

    Finally, I was able to find the error. The syntax of the statement was very good. The problem was caused by another declaration that I edited before and the error has not attracted Attention immediately.

    Thanks for reading and looking for an answer.

  • In a table - looping through the rows and the stored procedure call

    APEX version: 3.2.0.00.27

    Hello

    I searched the forum and tried a few things but could not make it work.

    I have a tabular presentation, developed with the help of the ATD (Cascading LOV - method of tabular presentation - AJAX - ATD )

    What I'm trying to do now:
    -After submit and validations, loop through all the lines and
    -call a stored procedure passing 3 parameters obtained from each of the lines on the form of tables. This procedure will be an update of a database table.

    On the forum, I found that I could do the loop "* FOR i IN 1..." APEX_APPLICATION.g_f03. "LOOP COUNT *" syntax.

    Only for testing purposes, I tried just to view information with the following (On Load - after a footer) process (example of Denes Kubicek == > http://deneskubicek.blogspot.com/2009/05/execute-javascript-throuhg-plsql.html):
    declare
      v_today  varchar2 (200);
    begin
    --  :P40_test := APEX_APPLICATION.g_f03(1);
    --  :P40_test2 := APEX_APPLICATION.g_f04.COUNT;
      :P40_test2 := 100;
    
      v_today := to_char (sysdate, 'dd.mm.yyyy');
    
    --FOR i IN 1.. APEX_APPLICATION.g_f03.COUNT LOOP 
    
      :P40_test := APEX_APPLICATION.g_f02(2);
    
      HTP.p ('<script type="text/javascript">');
      HTP.p (   'alert(''Today is '
              || v_today
    --          || APEX_APPLICATION.g_f04(APEX_APPLICATION.g_f03(i))
              || '.\n'
              || 'end!'');'
             );
      HTP.p ('</script>');
    
    --    :P40_test := APEX_APPLICATION.g_f02(APEX_APPLICATION.g_f02(i));
    
    --END LOOP;
    
    end;
    The foregoing would give me a ' * ORA-01403: no data found * ' message. I tried through various variants of APEX_APPLICATION.g_f0* #*, but still can't get anything to display correctly. In commenting on all the lines referring to APEX_APPLICATION.g_f0x above, the date would be are they displayed fine.

    I tried uncomment the FOR... LOOP and play with the code (defining the process runs "On submit - after calculations" and Validations), I got was a ' * ORA-06502: PL/SQL: digital error or value: character conversion number error * "message.

    Here is the script of the form in a table:
    select 
    "V"."MSLINK",                                       -- hidden (number)
    "V"."INSTALLATION_DATE",                        -- editable date picker
    "V"."MANUFACTURER_INDICATOR",              -- editable (cascading LOV -- text)
    "V"."MODEL_INDICATOR",                           -- editable (cascading LOV -- text)
    "V"."DIAMETER_INDICATOR",                      -- editable (LOV -- number)
    "V"."PURPOSE_INDICATOR",                        -- editable (LOV -- text)
    "V"."VALVE_NUMBER",                                -- shown but not editable -- number
    "V"."MODIFY_DATE",                                  -- shown but not editable
    "V"."MODIFY_USER",                                   -- shown but not editable
    "V"."VALVES_STYLE"."FEATURE"                  -- shown but not editable -- number
    from "#OWNER#"."VALVES" "V"
    Where
      "V"."PROJECT_ID" = :P1_PROJECT_NUMBER AND
      "V"."VALVES_DFLAG" = 0
    Regarding the parameters for the stored procedure, it would the MSLINK, VALVE_NUMBER and the VALVES_STYLE. FEATURE.

    Help, please!
    (Sorry for the long post).

    Thank you

    Tan

    Hi, Tan,

    I have not seen that type of object - I've only used custom types for purposes of test years ago and have never used their within Apex!

    One possibility is that the value of checksum being is based on all of the content of these fields, rather than only the part of the FEATURE. If there are other parts of the object, you could include those items as well.

    Otherwise, as you f01 KP for a record, you will need to retrieve the values of the FUNCTION in your PL/SQL code directly from the table (because the user cannot modify these fields, you can be sure that the values in the table will be still valid).

    Andy

  • Key of the stored procedure

    Hello

    I have a function in the db that returns a numeric value after passing an Id (digital). How do I create a join in physical layer as funtion will return a digital and given that it is a function, it can return only a single column.

    is it possible that I can keep the id (parameter) in the phycisal layer which I'm passing to the function, so that I can join neccasy in the physical layer with fact/Sun to the stored procedure.

    is the possible creation of mutiple stored procedure in physics if my function to only return a single column.

    Concerning
    Issue

    If I understand your question, you have a function that returns a numerical value based on an ID, we'll call it Customer ID as a sample. What you need to do is to create a view like this:

    CREATE THE VIEW IN CIRCULATION
    SELECT CUSTOMER_ID, get_outstanding (CUSTOMER_ID) FROM CLIENT

    You can then query this view like this:

    SELECT * EXCEPTIONAL WHERE CUSTOMER_ID = 999

    You could also use this point of view in your physical layer and attach it by customer ID. If you already have a table of facts, you could put a top view to add the extra column with your function. It of all good and should work fine with a warning. PL/SQL execution on SQL functions is not effective. Oracle has switch context between SQL and PL/SQL for each line and change in context is an expensive operation. In a proper system of DWH you préremplira your fact table with the results of get_outstanding for all customers so that there is no delay in the calculation it when OBIEE queries data.

  • Dbms_parallel_execute.run_task of execution and pass several Params to the target procedure

    Hello

    I look for my hand on the dbms_parallel_execute package in Oracle 11 g Release 2 and needed help to find a way to pass additional parameters

    the target procedure when it is called from dbms_parallel_execute.run_task.

    Please see this link for an explanation of the use of the package:

    https://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:4248554900346593542

    Usage example:

    declare
      l_var NUMBER := 0;
    begin
      --Sample execution from above link
      dbms_parallel_execute.run_task
      ( task_name      => ‘PROCESS BIG TABLE’,
       sql_stmt       => 'begin serial( :start_id, :end_id ); end;',
       language_flag  => DBMS_SQL.NATIVE,
       parallel_level => 4 );
    
      --Desired execution
      dbms_parallel_execute.run_task
      ( task_name      => ‘PROCESS BIG TABLE’,
       sql_stmt       => 'begin serial( :start_id, :end_id, "HOW TO PASS l_var VARIABLE HERE" ); end;',
       language_flag  => DBMS_SQL.NATIVE,
       parallel_level => 4 ); 
    end;
    /
    

    Now, for the procedure of series, apart from the parameters start_id and end_id, we have additional params such as l_var.

    Can someone help me please to solve this problem?. Any help on this approach would be highly appreciated.

    Thank you

    Hardcode the parameters in the dynamic statement as literals. After all, these globals are set of constants for the task parallel, correct?

    Just make sure that you are coding explicit data type conversions. For example

    pqStatement := 'begin DoSerial( startRow => :start_id, endRow => :end_id, day=> to_date('''||||''',''yyyy-mm-dd'') ); end;';
    

    Of course, also explicitly caste global parameter to a string when concat'ing in the dynamic instruction of the PQ.

Maybe you are looking for