Creating an own object-relational function.

Hi
I'd like to create a new function on a object-relational datatype. Where can I find information about comparable methods like SDO_AREA and how to build an own.
Thanks
Chris

You can use PL/SQL to write such functions.
I have written many functions that operates on SDO_Geometry objects.
This exampla calculates the minimal bounding rectangle of a sdo_geometry:
FUNCTION Calc_mbr( Geo Mdsys.Sdo_geometry )
RETURN VARCHAR2 IS
Resultat VARCHAR2( 100 );
Antelem NUMBER;
Antord NUMBER;
X1 NUMBER;
Y1 NUMBER;
X2 NUMBER;
Y2 NUMBER;
X NUMBER;
Y NUMBER;
E NUMBER;
C NUMBER;
Startingoffset NUMBER;
Startingoffsetnext NUMBER;
Etype NUMBER;
Interpretation NUMBER;
BEGIN
Resultat := NULL;
IF NOT Geo.Sdo_point IS NULL THEN
Resultat :=
TO_CHAR( Geo.Sdo_point.Y ) || ';' || TO_CHAR( Geo.Sdo_point.X ) || ';' ||
TO_CHAR( Geo.Sdo_point.Y ) ||
';' ||
TO_CHAR( Geo.Sdo_point.X ) ||
RETURN Resultat;
END IF;
IF Geo IS NOT NULL THEN
Antelem := Geo.Sdo_elem_info.COUNT( );
Antord := Geo.Sdo_ordinates.COUNT( );
E := 1;
WHILE E < Antelem LOOP
Startingoffset := Geo.Sdo_elem_info( E );
Etype := Geo.Sdo_elem_info( E + 1 );
Interpretation := Geo.Sdo_elem_info( E + 2 );
IF ( Antelem > E * 3 ) THEN
Startingoffsetnext := Geo.Sdo_elem_info( E + 3 );
--Start of ordinates for next element
ELSE
Startingoffsetnext := Antord + 1;
END IF;
IF Etype > 0 THEN
IF ( E = 1 ) THEN -- initalization .
X1 := Geo.Sdo_ordinates( 1 );
X2 := X1;
Y1 := Geo.Sdo_ordinates( 2 );
Y2 := Y1;
END IF;
C := Startingoffset;
WHILE C < Startingoffsetnext LOOP
X := Geo.Sdo_ordinates( C );
Y := Geo.Sdo_ordinates( C + 1 );
IF X < X1 THEN
X1 := X;
ELSIF X > X2 THEN
X2 := X;
END IF;
IF Y < Y1 THEN
Y1 := Y;
ELSIF Y > Y2 THEN
Y2 := Y;
END IF;
C := C + 4; -- x,y,z,m
END LOOP;
END IF;
E := E + 3; -- Elements are always triplets.
END LOOP;
Resultat :=
TO_CHAR( Y1 ) || ';' || TO_CHAR( X1 ) || ';' || TO_CHAR( Y2 ) || ';' ||
TO_CHAR( X2 ) ||
ELSE
Resultat := NULL;
END IF;
RETURN Resultat;
END;

Similar Messages

  • HR ABAP - Generic method or function to create a PD object & Relat (IT1001)

    Hi,
    This question is related to HR Abap .
    Do we have a generic class method or function module which can be used to create any PD object(O,S,C,...) and relationships (A008, A003, 007,...)between these objects .(not RH_INSERT_INFTY) . It should also trigger change pointers .
    And also do we have a decoupled or generic infotype(1000,1001,1002,....) classes in PD side also similar to PA infotype classes(CL_HRPA_INFOTYPE_0002, CL_HRPA_INFOTYPE_0008,....) . It should also trigger change pointers .
    Thanks in advance

    Generic function to create infotypes 1000 and 1001 is RH_INSERT_OBJECTS
    Classes are CL_HRBAS_INFTY_1000, CL_HRBAS_INFTY_1001, etc

  • Create a infocube object with function module

    Hi,
    Is it possible to create one infocube object via rfc call? If yes, could you pls give me an example how to do it? Many thanks.
    regards,
    Hai

    Hi Julian,
    I couldn't work out how to do this either, so I did it using the oracle.express.spl.SPLExecutor class and sending Express commands to create a program.
    Let me know if you want to see some sample code.
    Cheers,
    Mark...

  • Benefits of object-relational

    Hi,
    I am having a problem with the object-relational features and JDBC.
    It seems that when I select objects from the database into my Java program, those objects can't be used after the Connection is returned to the pool.
    I want to read a bunch of objects from the database and cache them in my program. When I use those objects later, I reference their attributes using the accessor methods. If I have returned the Connection to the pool, I get a "Logical handle no longer valid" error.
    I'm using Oracle 9.0.1, getting a Connection from a OracleConnectionCacheImpl. I am using JPublisher to generate my Java classes, telling it to use the ORAData interface.
    The object features of Oracle looked really nice -- database objects are nicely materialized as Java objects in my program. But what good does it do to have all this fancy generated code if I need to create my own objects from the retrieved objects if I want to use them later?
    Am I missing something? Any comments or pointers?
    Here is the relevant portion of the code.
    try {
    DataSource ds = (DataSource)JndiClient.getConnectionPoolDataSource(poolAlias, "test1", "test1");
    conn = (OracleConnection)ds.getConnection();
    Statement stmt = conn.createStatement();
    rset = (OracleResultSet)stmt.executeQuery("SELECT VALUE(p) FROM process_types p");
    if (rset.next()) {
    np = (NapProcessType)rset.getORAData(1, NapProcessType.getORADataFactory());
    catch (Exception e) {
    System.err.println("Exception: " + e);
    e.printStackTrace();
    finally {
    // Free up resources.
    try {
    if (cs != null)
    cs.close();
    if (rset != null)
    rset.close();
    if (conn != null)
    conn.close();
    catch (SQLException ignore) {
    try {
    System.out.println("getPtName: " + np.getPtName()); // causes Exception
    catch (Exception e) {
    System.err.println("Exception: " + e);
    e.printStackTrace();
    Thanks.
    Mark

    Peter,
    Glad to see you took my advice and posted your question over here. Although I am a frequent user of the Oracle usenet groups, I have found that this is a much better place to get help with Spatial. My experiences suggest that the population of people using spatial is small--and of them the ones that really know alot are few and far between. I can only claim to be in the former group.
    As far as your problem goes--this is probably something you've already considered--is there a way to model the data such that you don't have to replicate the geometry components? Another option would be to handle the replication without using snapshots. Examples would be to export the data and then ftp/copy it to the target machines and import it. If you need real-time replication you could experiment with triggers that execute INSERTs/UPDATEs/DELETEs on the remote databases. This of course has its own issues--but you're going to end up with some sort of compromise no matter how you slice this.
    Of course you could use the relational model. I have never used it so I'm hard pressed to give any advice on it. As I posted on the usenet board, it is heading for desupport in 9i Release 2 according to the documentation available. So if you go relational you'll eventually have to migrate to object/relational. I'm not sure how automatic (or non-automatic) that process is. Hopefully someone on here will have some more concrete advice on that.
    Good luck.
    Matt.

  • Migrating Relational Model to Object-Relational Model

    Hi,
    Can someone direct me to appropriate tutorial/examples in migrating spatial relational model to object-relatonal model.
    I have the following tables in the relational model:
    ROADS
    ROADS_SDODIM
    ROADS_SDOGEOM
    ROADS_SDOINDEX
    ROADS_SDOLAYER
    What tables would I need to create in the object-relational model?
    Can someone advice me on how to use this function sdo_migrate.to_current?
    Thanks in advance!

    There are a number of Object Oriented databases out there, with Gemstone perhaps the best known. Also, Oracle, and other RDBMS vendors are adding more object oriented features all the time.
    However, there are some downsides to OO databases. One of the biggest is that it is often really difficult to query the data directly. All interaction with the database needs some sort of mapping layer to instantiate the objects and get their attributes. It is also difficult, and sometimes impossible, to generate ad hoc queries that try to look at the data in a way that does not match the object model, something that is relatively easy in a well designed relational model.
    Finally, object oriented databases represent a more or less one to one mapping to a currently popular programming paradigm. What happens to the data when the next great programming paradigm (foo perspective) comes along? Will the foo prgrammer be able to easily read the objects in the OO database? Probably not. Will the foo programmer be able to easily read the relational data? Almost certainly.
    John

  • Can I create my own .cbx file or modify a current .cbx file?

    What I would like to do is create an object that will give me a DOUBLE Action Verification message (Are you sure? YES! Are you REALLY SURE? YES!) I'm doing this already with a cloggy of pop-up messages, and wanted a CLEANER and Easier way to do this. My thought was to modify the current PUSHBUTTON -- logctrl.cbx file. Or create a similar one. Any thoughts???

    If this is the case, have you thought of using the Aggregate object? You can "create" your own Object out of the existing pop-up windows and push-buttons once and for all and keep using this as an "Object" in future.
    Here's a snippet from the Online Help on the Aggregate Object:
    The Aggregate object is a way for you to create a collection of Lookout objects, already connected and configured, and use that collection multiple times as an element in your processes.
    Create an aggregate by creating a Lookout process and saving the process as an aggregate definition file, choosing which of the object parameters and data members to expose when aggregate is used in another process. Then use that aggregate definition process in other processe
    s by creating an aggregate object that uses your aggregate definition as its source. ...

  • Yes, I want to create object-relational schema from DTD.

    Thank you for reply~~
    I want to create object-relational schema from DTD using object type or collections as mentioned.
    In reply, it is impossible.
    But, I read Oracle supports storing an XML document with object-relation. I executed storing sample, but I had to create schema manually.
    Is it really impossible to create OR schema from DTD automatically?

    Yes. You need to create your database schema before insert XML data to it.

  • COMMIT failed in RSORAADM, object JOB, function CREATE, return code 4

    Dear Gurus,
    When I am trying to schedule a backup through DB13, I am getting an error as
    "COMMIT failed in RSORAADM, object JOB, function CREATE, return code 4"
    Can any body tell me what is the error about and how to resolve it.
    Thanks
    Best Regards
    Dilip

    hi Kaushal,
    Thanks for your reply.  Yes I could solve the issue as my Operation mode was inactive, I made it active and then could schedule the DB13 jobs. 
    Can you tell me what is the relationship between DB13 jobs scheduling and Operation mode.  Also note when I am scheduling DB13 jobs that time none of the background job is running ie my background wp is free. It is only after I activated day/night operation mode, I could schedule the backup.
    Thanks once again.  Your input was of great help to me.
    Best Regards
    Dilip

  • Need help with creating B*Tree XMLIndex on a structured object-relational xmltype column

    The following is my schema:
    CREATE TABLE TST_AUDIT_TBL
       NOTE                  VARCHAR2(25 CHAR)     null,
       CHANGE_HISTORY        XMLTYPE               not null,
       CHANGE_HISTORY_EXT    XMLTYPE               null
    XMLTYPE COLUMN CHANGE_HISTORY STORE AS OBJECT RELATIONAL XMLSCHEMA "http://www.oracle.com/a.xsd" element "A"
    XMLTYPE COLUMN CHANGE_HISTORY_EXT STORE AS CLOB XMLSCHEMA "http://www.oracle.com/a.xsd" element "AX"
    XML Schema for the above is defined as follows:
    <schema targetNamespace="http://www.oracle.com/a.xsd"
            xmlns:a="http://www.oracle.com/a.xsd"
            xmlns="http://www.w3.org/2001/XMLSchema"  elementFormDefault="qualified">
        <complexType name="AuditExtType">
          <sequence>
            <element name="C" maxOccurs="unbounded" minOccurs="0">
              <complexType>
                <sequence>
                  <element type="string" name="CN"/>
                  <element type="string" name="OV" minOccurs="0" maxOccurs="1"/>
                  <element type="string" name="NV" minOccurs="0" maxOccurs="1"/>
                </sequence>
              </complexType>
            </element>
          </sequence>
        </complexType>
        <complexType name="AuditType">
          <sequence>
            <element type="string" name="M" maxOccurs="1" minOccurs="0"/>
            <element type="string" name="O"/>
            <element name="B" maxOccurs="1" minOccurs="0">
              <complexType>
                <sequence>
                  <element name="BC" minOccurs="1" maxOccurs="unbounded">
                    <complexType>
                      <sequence>
                        <element type="string" name="BN"/>
                        <element name="F" maxOccurs="unbounded" minOccurs="0">
                          <complexType>
                            <sequence>
                              <element type="string" name="FN"/>
                              <element type="string" name="OV" minOccurs="0" maxOccurs="1"/>
                              <element type="string" name="NV" minOccurs="0" maxOccurs="1"/>
                            </sequence>
                          </complexType>
                        </element>
                      </sequence>
                    </complexType> 
                  </element>
                </sequence>
              </complexType>
            </element>
            <element name="T" maxOccurs="1" minOccurs="0">
              <complexType>
                <sequence>
                  <element name="TL" minOccurs="1" maxOccurs="unbounded">
                    <complexType>
                      <sequence>
                        <element type="string" name="TN"/>
                        <element name="C" maxOccurs="unbounded" minOccurs="0">
                          <complexType>
                            <sequence>
                              <element type="string" name="CN"/>
                              <element type="string" name="OV" minOccurs="0" maxOccurs="1"/>
                              <element type="string" name="NV" minOccurs="0" maxOccurs="1"/>
                            </sequence>
                          </complexType>
                        </element>
                      </sequence>
                    </complexType>
                  </element>
                </sequence>
              </complexType>
            </element>
            <element name="I" maxOccurs="1" minOccurs="0">
              <complexType>
                <sequence>
                  <element name="K" maxOccurs="unbounded" minOccurs="0">
                    <complexType>
                      <sequence>
                        <element type="string" name="N"/>
                        <element type="string" name="V"/>
                      </sequence>
                    </complexType>
                  </element>
                </sequence>
              </complexType>
            </element>
          </sequence>
        </complexType>
        <element name="A" type="a:AuditType"/>
        <element name="AX" type="a:AuditExtType"/>
    </schema>
    I want to create a B*Tree XML Index on the above table for the following:
    1. CN
    2. TN
    in the above schema.
    Following the doc, this is what I am issuing:
    SQL> CREATE INDEX audt_audit_idx1 ON TST_AUDIT_TBL(CHANGE_HISTORY) INDEXTYPE IS XDB.XMLINDEX PARAMETERS ('XMLTABLE IXTAB
      2  XMLNAMESPACES(DEFAULT ''http://www.oracle.com/a.xsd''), ''/A'' COLUMNS COLUMN_NAME VARCHAR2(128) PATH ''A/T/TL/C/CN'' ');
    CREATE INDEX audt_audit_idx1 ON TST_AUDIT_TBL(CHANGE_HISTORY) INDEXTYPE IS XDB.XMLINDEX PARAMETERS ('XMLTABLE IXTAB
    ERROR at line 1:
    ORA-29958: fatal error occurred in the execution of ODCIINDEXCREATE routine
    ORA-19276: XPST0005 - XPath step specifies an invalid element/attribute name:
    (A)
    Not sure what is going wrong (and what would be a working xmlindex will look like?)

    Here goes...
    1) Schema registration
    begin
    dbms_xmlschema.registerSchema(
      schemaURL => 'http://www.oracle.com/a.xsd'
    , local     => true
    , genTypes  => true
    , genTables => false
    , enableHierarchy => dbms_xmlschema.ENABLE_HIERARCHY_NONE
    , schemaDoc =>
    '<schema targetNamespace="http://www.oracle.com/a.xsd"
            xmlns:a="http://www.oracle.com/a.xsd"
            xmlns="http://www.w3.org/2001/XMLSchema"  elementFormDefault="qualified">
        <complexType name="AuditExtType">
          <sequence>
            <element name="C" maxOccurs="unbounded" minOccurs="0">
              <complexType>
                <sequence>
                  <element type="string" name="CN"/>
                  <element type="string" name="OV" minOccurs="0" maxOccurs="1"/>
                  <element type="string" name="NV" minOccurs="0" maxOccurs="1"/>
                </sequence>
              </complexType>
            </element>
          </sequence>
        </complexType>
        <complexType name="AuditType">
          <sequence>
            <element type="string" name="M" maxOccurs="1" minOccurs="0"/>
            <element type="string" name="O"/>
            <element name="B" maxOccurs="1" minOccurs="0">
              <complexType>
                <sequence>
                  <element name="BC" minOccurs="1" maxOccurs="unbounded">
                    <complexType>
                      <sequence>
                        <element type="string" name="BN"/>
                        <element name="F" maxOccurs="unbounded" minOccurs="0">
                          <complexType>
                            <sequence>
                              <element type="string" name="FN"/>
                              <element type="string" name="OV" minOccurs="0" maxOccurs="1"/>
                              <element type="string" name="NV" minOccurs="0" maxOccurs="1"/>
                            </sequence>
                          </complexType>
                        </element>
                      </sequence>
                    </complexType>
                  </element>
                </sequence>
              </complexType>
            </element>
            <element name="T" maxOccurs="1" minOccurs="0">
              <complexType>
                <sequence>
                  <element name="TL" minOccurs="1" maxOccurs="unbounded">
                    <complexType>
                      <sequence>
                        <element type="string" name="TN"/>
                        <element name="C" maxOccurs="unbounded" minOccurs="0">
                          <complexType>
                            <sequence>
                              <element type="string" name="CN"/>
                              <element type="string" name="OV" minOccurs="0" maxOccurs="1"/>
                              <element type="string" name="NV" minOccurs="0" maxOccurs="1"/>
                            </sequence>
                          </complexType>
                        </element>
                      </sequence>
                    </complexType>
                  </element>
                </sequence>
              </complexType>
            </element>
            <element name="I" maxOccurs="1" minOccurs="0">
              <complexType>
                <sequence>
                  <element name="K" maxOccurs="unbounded" minOccurs="0">
                    <complexType>
                      <sequence>
                        <element type="string" name="N"/>
                        <element type="string" name="V"/>
                      </sequence>
                    </complexType>
                  </element>
                </sequence>
              </complexType>
            </element>
          </sequence>
        </complexType>
        <element name="A" type="a:AuditType"/>
        <element name="AX" type="a:AuditExtType"/>
    </schema>'
    end;
    2) Table creation
    CREATE TABLE TST_AUDIT_TBL
       NOTE                  VARCHAR2(25 CHAR)     null,
       CHANGE_HISTORY        XMLTYPE               not null,
       CHANGE_HISTORY_EXT    XMLTYPE               null
    XMLTYPE COLUMN CHANGE_HISTORY STORE AS OBJECT RELATIONAL XMLSCHEMA "http://www.oracle.com/a.xsd" element "A"
    XMLTYPE COLUMN CHANGE_HISTORY_EXT STORE AS CLOB XMLSCHEMA "http://www.oracle.com/a.xsd" element "AX"
    3) Retrieving the nested table and column related to the target element :
    SQL> select dbms_xmlstorage_manage.xpath2TabColMapping(
      2           owner_name => 'DEV'
      3         , table_name => 'TST_AUDIT_TBL'
      4         , column_name => 'CHANGE_HISTORY'
      5         , xpath => '/A/T/TL/C/CN'
      6         , namespaces =>'default ''http://www.oracle.com/a.xsd'''
      7         )
      8  from dual;
    DBMS_XMLSTORAGE_MANAGE.XPATH2T
    <Result>
      <Mapping TableName="SYS_NTr0U7dPWyRu6OVvDN2f5HEg==" ColumnName="CN"/>
    </Result>
    4) Creating the index :
    SQL> create index CHANGE_HISTORY_IX1 on "SYS_NTr0U7dPWyRu6OVvDN2f5HEg==" ("CN");
    Index created
    If you're going to create multiple indexes like this, you could really benefit from renaming all the nested tables to meaningful names. That can be done via DBMS_XMLSTORAGE_MANAGE as well.

  • How to create Object related messages using cl_bsp_wd_message_service?

    Hi Gurus,
    Can any ony explain how to create the object related messages using add_message method of cl_bsp_wd_message_service?
    Thanks,
    Murali.

    Hi Murali,
    Check the below code .. hope it helps..
      DATA lr_msg_service     TYPE REF TO cl_bsp_wd_message_service.
      DATA lr_exception       TYPE REF TO cx_root.
      DATA lr_rtti            TYPE REF TO cl_abap_objectdescr.
      DATA lv_msg_type        TYPE        symsgty.
      DATA lv_msg_id          TYPE        symsgid.
      DATA lv_msg_number      TYPE        symsgno.
      DATA lv_msg_v1          TYPE        symsgv.
      DATA lv_msg_v2          TYPE        symsgv.
      DATA lv_msg_v3          TYPE        symsgv.
      DATA lv_msg_v4          TYPE        symsgv.
      DATA lv_msg_level       TYPE        bsp_wd_message_level.
      DATA lr_verification    TYPE REF TO if_bsp_wd_message_handler."#EC NEEDED
      DATA lv_important_info  TYPE        abap_bool.
      DATA lv_exc_prog_name   TYPE        syrepid.
      DATA lv_exc_incl_name   TYPE        syrepid.
      DATA lv_exc_src_line    TYPE        i.
      lr_exception = ir_exception.
    drill down to first exception
      WHILE lr_exception->previous IS BOUND.
        lr_exception = lr_exception->previous.
      ENDWHILE.
      lr_rtti ?= cl_abap_typedescr=>describe_by_object_ref( p_object_ref = lr_exception ).
      lr_exception->get_source_position( IMPORTING program_name = lv_exc_prog_name
                                                   include_name = lv_exc_incl_name
                                                   source_line  = lv_exc_src_line ).
    prepare message
      lr_msg_service = cl_bsp_wd_message_service=>get_instance( ).
      lv_msg_type   = if_genil_message_container=>mt_warning.
      lv_msg_id     = 'CRM_IC_APPL'.
      lv_msg_number = '003'.
      lv_msg_v1     = lr_rtti->get_relative_name( ).
      lv_msg_v2     = ir_exception->get_text( ).
      lv_msg_v3     = lv_exc_incl_name.
      lv_msg_v4     = lv_exc_src_line.
      lv_msg_level  = '9'.
    add message to error log
      lr_msg_service->add_message(
          iv_msg_type       = lv_msg_type
          iv_msg_id         = lv_msg_id
          iv_msg_number     = lv_msg_number
          iv_msg_v1         = lv_msg_v1
          iv_msg_v2         = lv_msg_v2
          iv_msg_v3         = lv_msg_v3
          iv_msg_v4         = lv_msg_v4
          iv_msg_level      = lv_msg_level
          iv_verification   = lr_verification
          iv_important_info = lv_important_info ).
    Regards,
    Raghu

  • Can i Create A business object of my own without inheriting

    hi gurus,
                  Can i Create A business object of my own without inheriting from any other business object. i Know how to create sub type.

    yes, u can choose 'create' button in SWO1 and not fill field Supertype.
    or copy your new BO from already exist.

  • Can I use classes and objects to create my own package in LabVIEW?

    Hi....I am writing my thesis on develpoing a simulation package.  I am trying to compare simulation packages and their feautures as a scope of my project.  Does anyone know if LabVIEW allows users to create their own toolboxes like MATLAB?...i mean something that can be done in object-oriented programming by making classes and objects.
    thanks guys 

    The short answer is yes. NI sells toolkits. There's also OpenG. How you code the guts is up to you - you can do it non-LVOOP or LVOOP.

  • Printing out results in case of object-relational table (Oracle)

    I have made a table with this structure:
    CREATE OR REPLACE TYPE Boat AS OBJECT(
    Name varchar2(30),
    Ident number,
    CREATE OR REPLACE TYPE Type_boats AS TABLE OF Boat;
    CREATE TABLE HOUSE(
    Name varchar2(40),
    MB Type_boats)
    NESTED TABLE MB store as P_Boat;
    INSERT INTO House VALUES ('Name',Type_boats(Boat('Boat1', 1)));
    I am using java to print out all the results by calling a procedure.
    CREATE OR REPLACE package House_boats
    PROCEDURE add(everything works here)
    PROCEDURE results_view;
    END House_boats;
    CREATE OR REPLACE Package.body House_boats AS
    PROCEDURE add(everything works here) AS LANGUAGE JAVA
    Name House_boats.add(...)
    PROCEDURE results_view AS LANGUAGE JAVA
    Name House_boats.resuts_view();
    END House_boats;
    However, I am not able to get Results.view working in case of object-relation table. This is how I do it in the situation of relational table.
    CALL House_boats.results_view();
    House_boats.java file which is loaded using LOADJAVA:
    import java.sql.*;
    import java io.*;
    public class House_boats {
    public static void results_view ()
       throws SQLException
       { String sql =
       "SELECT * from House";
       try { Connection conn = DriverManager.getConnection
    ("jdbc:default:connection:");
       PreparedStatement pstmt = conn.prepareStatement(sql);
       ResultSet rset = pstmt.executeQuery();
      printResults(rset);
      rset.close();
      pstmt.close();
       catch (SQLException e) {System.err.println(e.getMessage());
    static void printResults (ResultSet rset)
       throws SQLException { String buffer = "";
       try { ResultSetMetaData meta = rset.getMetaData();
       int cols = meta.getColumnCount(), rows = 0;
       for (int i = 1; i <= cols; i++)
       int size = meta.getPrecision(i);
       String label = meta.getColumnLabel(i);
       if (label.length() > size) size = label.length();
       while (label.length() < size) label += " ";
      buffer = buffer + label + " "; }
      buffer = buffer + "\n";
       while (rset.next()) {
      rows++;
       for (int i = 1; i <= cols; i++) {
       int size = meta.getPrecision(i);
       String label = meta.getColumnLabel(i);
       String value = rset.getString(i);
       if (label.length() > size) size = label.length();
       while (value.length() < size) value += " ";
      buffer = buffer + value + " ";  }
      buffer = buffer + "\n";   }
       if (rows == 0) buffer = "No data found!\n";
       System.out.println(buffer); }
       catch (SQLException e) {System.err.println(e.getMessage());}  }
    How do I print out the results correctly in my case of situation?
    Thank you in advance

    I have made a table with this structure:
    I am using java to print out all the results by calling a procedure.
    However, I am not able to get Results.view working in case of object-relation table. This is how I do it in the situation of relational table.
    How do I print out the results correctly in my case of situation?
    There are several things wrong with your code and methodology
    1. The code you posted won't even compile because there are several syntax issues.
    2. You are trying to use/test Java in the database BEFORE you get the code working outside the DB
    3. Your code is not using collections in JDBC properly
    I suggest that you use a different, proven approach to developing Java code for use in the DB
    1. Use SIMPLE examples and then build on them. In this case that means don't add collections to the example until ALL other aspects of the app work properly.
    2. Create and test the Java code OUTSIDE of the database. It is MUCH easier to work outside the database and there are many more tools to help you (e.g. NetBeans, debuggers, DBMS_OUTPUT windows, etc). Trying to debug Java code after you have already loaded it into the DB is too difficult. I'm not aware of anyone, even at the expert level, that develops that way.
    3. When using complex functionality like collections first read the Oracle documentation (JDBC Developer Guide and Java Developer's Guide). Those docs have examples that are known to work.
    http://docs.oracle.com/cd/B28359_01/java.111/b31225/chfive.htm
    http://docs.oracle.com/cd/E11882_01/java.112/e16548/oraarr.htm#sthref583
    The main issue with your example is #3 above; you are not using collections properly:
    String value = rset.getString(i);
    A collection is NOT a string so why would you expect that to work for a nested table?
    A collection needs to be treated like a collection. You can even treat the collection as a separate result set. Create your code outside the database and use the debugger in NetBeans (or other) on this replacement code for your 'printResults' method:
    static void printResults (ResultSet rset) throws SQLException {
        try {
           ResultSetMetaData meta = rset.getMetaData();
           while (rset.next()) {
               ResultSet rs = rset.getArray(2).getResultSet();
               rs.next();
               String ndx = rs.getString(1);
               Struct struct = (Struct) rs.getObject(2);
               System.out.println(struct.getSQLTypeName());
               Object [] oa = struct.getAttributes();
               for (int j = 0; j < oa.length; j++) {
                  System.out.println(oa[j]);
        } catch  (SQLException e) {
           System.err.println(e.getMessage());
    That code ONLY deals with column 2 which is the nested table. It gets that collection as a new resultset ('rs'). Then it gets the contents of that nested table as an array of objects and prints out the attributes of those objects so you can see them.
    Step through the above code in a debugger so you can SEE what is happening. NetBeans also lets you enter expressions such as 'rs' in an evaluation window so you can dynamically try the different methods to see what they do for you.
    Until you get you code working outside the database don't even bother trying to load it into the DB and create a Java stored procedure.
    Since your current issue has nothing to do with this forum I suggest that you mark this thread ANSWERED and repost it in the JDBC forum if you need further help with this issue.
    https://forums.oracle.com/community/developer/english/java/database_connectivity
    When you repost you can include a link to this current thread if you want. Once your Java code is actually working then try the Java Stored procedure examples in the Java Developer's Guide doc linked above.
    At the point you have any issues that relate to Java stored procedures then you should post them in the SQL and PL/SQL forum
    https://forums.oracle.com/community/developer/english/oracle_database/sql_and_pl_sql

  • Need help in Object-Relational Mapping

    I'm writing a simple two-tiered business application with Swing application on the client side and a DBMS on the server side. To make my client code more maintainable, I decided to create Business Objects instead of having my client accessing the database directly via SQL. For simplicity, I'm not using any features from the J2EE framework, and the Business Objects will be hosted on the client side, with one-to-one mapping to tables in the database. Since this is my first attempt in Object-Relational Mapping, I'm faced with the following problems:
    1. What kind of methods are appropriate for business objects? For example, if I have a Machine and Employee entity. A Machine is owned by an employee, and this is represented in the DB by storing the employee ID (not the name) as a foreign key in the Machine table. Let's say in the user interface I have a table that needs to display the list of Machines, but instead of displaying the owner employee's ID, I want to display the owner employee's name by doing a join select. Should the findMachines() method always perform a join select to get owner's name and store it in the Machine object which is returned, or should findMachines() simply return the owner's ID so the UI will need to make another SQL call (through the Employee object) to get the employee's name? The latter is more elegant, but would it be horribly inefficient if there are lots of machines to be displayed (and for each machine we make a separate select call to get the owner's name).

    Business objects should be separate from how they're persisted.
    When you say object-relational mapping, do you mean a tool like Hibernate? Or are you writing your own persistence layer using JDBC and SQL?
    I'd recommend that you read about the Data Access Object pattern and keep the persistence code out of the business objects themselves:
    http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
    url=http://www-106.ibm.com/developerworks/java/library/j-dao/

  • Query on object-relational data takes forever

    hello all
    i have a problem with a query performance... it seems like whenever i call a specific object function, the query executes very very slow. The results though are correct.
    let me explain what i do... I have some relational tables, and i recreate the schema into an object relational one. Then i insert data from relational tables to object tables. I follow this tutorial: [A Sample Application Using Object-Relational Features|http://download.oracle.com/docs/cd/B12037_01/appdev.101/b10799/adobjxmp.htm]
    these are the types that make up the transaction object table.
    CREATE OR REPLACE TYPE  TransactionItem_objtyp AS OBJECT
      transItemID   NUMBER,
      Quantity      NUMBER,
      iValue        NUMBER,
      item_ref      REF Item_objtyp
    CREATE TYPE TransactionItemList_ntabtyp AS TABLE OF TransactionItem_objtyp;
    CREATE OR REPLACE TYPE Transaction_objtyp AS OBJECT
      transID             NUMBER,
      cust_ref            REF Customer_objtyp,
      transTameio         NUMBER,
      transDateTime       DATE,
      isStoreCustomer     CHAR(1),
      store_ref           REF Store_objtyp,
      transItemList_ntab  TransactionItemList_ntabtyp,
      MAP MEMBER FUNCTION
        getTransID  RETURN NUMBER,
      MEMBER FUNCTION
        getTotalCost  RETURN NUMBER
    );the function that causes the query to run very slow (fetching 10 rows per sec in a query that should return 130.000 rows) is the getTotalCost:
    CREATE OR REPLACE TYPE BODY Transaction_objtyp AS
    MAP MEMBER FUNCTION getTransID RETURN NUMBER IS
    BEGIN
    RETURN transID;
    END;
    MEMBER FUNCTION getTotalCost RETURN NUMBER IS
    i       INTEGER;
    Total   NUMBER := 0;
    BEGIN
    IF(UTL_COLL.IS_LOCATOR(transItemList_ntab))
    THEN
    SELECT SUM(L.Quantity * L.iValue) INTO Total
    FROM TABLE(CAST(transItemList_ntab AS TransactionItemList_ntabtyp)) L;
    ELSE
    FOR i IN 1..SELF.transItemList_ntab.COUNT LOOP
    Total := Total + SELF.transItemList_ntab(i).Quantity * SELF.transItemList_ntab(i).iValue;
    END LOOP;
    END IF;
    RETURN ROUND(Total,2);
    END;
    END;the table transaction_objtab that contains the nested table is this
    CREATE TABLE Transaction_objtab OF Transaction_objtyp(
      PRIMARY KEY(transID),
      FOREIGN KEY(cust_ref) REFERENCING Customer_objtab,
      FOREIGN KEY(store_ref) REFERENCING Store_objtab)
      OBJECT IDENTIFIER IS PRIMARY KEY
      NESTED TABLE transItemList_ntab STORE AS TransItem_ntab (
        (PRIMARY KEY(transItemID))
        ORGANIZATION INDEX)
      RETURN AS LOCATOR
    ALTER TABLE TransItem_ntab ADD (SCOPE FOR (item_ref) IS Item_objtab);and this is how i insert the values into the transaction_objtab and the nested tables from the relational ones:
    INSERT INTO Transaction_objtab
    SELECT  t.transID,
            REF(c),
            t.transTameio,
            t.transDateTime,
            t.isStoreCustomer,
            REF(s),
            TransactionItemList_ntabtyp()
    FROM transactions t, Customer_objtab c, store_objtab s
    WHERE t.transCustomer = c.custCode AND t.transStore = s.storeCode;
    BEGIN
      FOR i IN (SELECT DISTINCT transID FROM transactionItems) LOOP
        INSERT INTO TABLE(  SELECT p.TransItemList_ntab
                            FROM Transaction_objtab p
                            WHERE p.transID = i.transID)
        SELECT transItemIDseq.nextval, t.Quantity, t.iValue, REF(i)
        FROM transactionItems t, item_objtab i
        WHERE t.transID = i.transID AND t.itemID = i.itemID;
      END LOOP;
    END;so whenever i use transaction_objtab t, t.getTotalCount() query takes for ever.
    is there anything i do wrong?
    sorry for this long post.
    thanks in advance

    So, how many transactions? How many items? There is a whole series of questions I would normally ask at this point, because performance tuning is - to a certain extent - largely a matter of rote. But there's a more fundamental issue.
    You are experiencing the problem with objects. They are cool enough when handling individual "things" but they suck when it comes to set-based processing. SQL and relational programming, on the other hand, excels at that sort of thing. So the question which has to asked is, why are you using objects for this project?
    Cheers, APC
    blog: http://radiofreetooting.blogspot.com

Maybe you are looking for