Query or procedure reformatting xmltype (clob)

help me out with this one, please. I have not been able to narrow it down:
platform: Ora 9.2.0.5 on AIX, accessed remotely, character set AL32UTF8.
Table with multiple of columns, 2 SYS.XMLTYPE columns (storage CLOB, not compiled schema (xsd:datetime timezone issues)).
One column is a digitally signed xml doc; must be image consistent (char for char).
test 1:
select digitalsignedxml from table where ....;
result is identical to input; life is good.
test 2:
select XMLeleement("digitallysigneddoc", digitallysignedxml) from table where ....;
the body is still identical to the input (ignoring the wrapper), life is good.
test3:
same query as 2, but in a packaged function that is returning XMLTYPE.
The body is not identical, but reformatted. sigh. life is not good.
I have not been able to pin (narrow) this down. I have verified identical, not identical using sqlplus (set long 20000 linesize 20000 header off) and with the team's java application.
???

The problem appears to be that "SELECT xmltype_column" from table (XMLTYPE on clob) returns the data as is with no reformatting, and "SELECT XML("wrapper", xmltype_column) from table will totally reformat the xml in the column. Even though the data is stored in CLOB, it is no longer image consistent. yeah, it is still DOM consistent, but if we are dealing with a digitally signed doc, then how can I include that digitally signed doc in a larger XML doc, and still have it valid?
here are teh test cases:
REM for posting purposes I put ";" at all eol (if not already there).
environment: server 9.2.0.5 on AIX
client: sqlplus 9.2.0.5.0 also on AIX (remote, not ORACLE_SID)
set long 20000 linesize 20000 heading off
def vxml1='<testDoc id="6734"> <authSignature><ds:Signature xmlns:ds="http://www
.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="h
ttp://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>';
def vxml2='<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-
sha1"/><ds:Reference URI="testDoc"><ds:Transforms><ds:Transform Algorithm="http:
//www.w3.org/TR/2001/REC-xml-c14n-20010315"/>';
def vxml3='</ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09
/xmldsig#sha1"/><ds:DigestValue>00OrCVzig5V9p5SLbjDXbryYZkQ=</ds:DigestValue></d
s:Reference></ds:SignedInfo>';
def vxml4='<ds:SignatureValue>foo</ds:SignatureValue><ds:KeyInfo><ds:KeyName>Pub
lic key of certificate</ds:KeyName><ds:KeyValue><ds:RSAKeyValue>';
def vxml5='<ds:Modulus>bar</ds:Modulus><ds:Exponent>AQAB</ds:Exponent></ds:RSAKe
yValue></ds:KeyValue><ds:X509Data>';
def vxml6='<ds:X509Certificate>data here</ds:X509Certificate></ds:X509Data></ds:
KeyInfo></ds:Signature></authSignature></testDoc>';
select xmltype('&vxml1.&vxml2.&vxml3.&vxml4.&vxml5.&vxml6') from dual;
select XMLelement("testdoc",xmltype('&vxml1.&vxml2.&vxml3.&vxml4.&vxml5.&vxml6')
) from dual;
results:
15:25:43 dev58 SQL> select xmltype('&vxml1.&vxml2.&vxml3.&vxml4.&vxml5.&vxml6') from dual;
<testDoc id="6734"> <authSignature><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI="testDoc"><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>00OrCVzig5V9p5SLbjDXbryYZkQ=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>foo</ds:SignatureValue><ds:KeyInfo><ds:KeyName>Public key of certificate</ds:KeyName><ds:KeyValue><ds:RSAKeyValue><ds:Modulus>bar</ds:Modulus><ds:Exponent>AQAB</ds:Exponent></ds:RSAKeyValue></ds:KeyValue><ds:X509Data><ds:X509Certificate>data here</ds:X509Certificate></ds:X509Data></ds:KeyInfo></ds:Signature></authSignature></testDoc>
1 row selected.
Elapsed: 00:00:00.01
15:25:43 dev58 SQL>
15:25:43 dev58 SQL> select XMLelement("testdoc",xmltype('&vxml1.&vxml2.&vxml3.&vxml4.&vxml5.&vxml6')) from dual;
<testdoc><testDoc id="6734">
<authSignature>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
<ds:Reference URI="testDoc">
<ds:Transforms>
<ds:Transform Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315"/>
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
<ds:DigestValue>00OrCVzig5V9p5SLbjDXbryYZkQ=</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>foo</ds:SignatureValue>
<ds:KeyInfo>
<ds:KeyName>Public key of certificate</ds:KeyName>
<ds:KeyValue>
<ds:RSAKeyValue>
<ds:Modulus>bar</ds:Modulus>
<ds:Exponent>AQAB</ds:Exponent>
</ds:RSAKeyValue>
</ds:KeyValue>
<ds:X509Data>
<ds:X509Certificate>data here</ds:X509Certificate>
</ds:X509Data>
</ds:KeyInfo>
</ds:Signature>
</authSignature>
</testDoc>
</testdoc>
1 row selected.
Elapsed: 00:00:00.04
REM REM hint: this is much stripped down bare bones of actual digitial signed xml doc ...

Similar Messages

  • XML, XMLType, Clob???

    Hi,
    In our system we need to interface with an external system using an xml interface. We use a staging table that contains the data that is needed to collect data from our database. For this we used the xmlelement en xmlagg query in a stored procedure into a clob parameter. We are using ODP.net driver 9207.
    We query chunks of 100 records from our staging table and retrieve the xml data calling our stored procedure. This will run ok for a while but after an unpredictable amount of time we got ORA-03127: no new operations allowed until the active operation ends.
    We switched to an xmltype parameter, that seemed to solve that error. But now after app. 500 successful attempts our .net application crashes. We have correct error handling implemented but it does not even get there. I read about leaking xmltype later on, but I'm not sure if this could be the case. It is running on a server as a windows service.
    The strange thing is that the exact same code runs fine on my machine (the famous last words....), same odp.net driver version, against the same database...
    Well, we just want xml out of this Oracle database, calling a stored procedure and getting desperate....
    Any advice?
    Best regards,
    Richard

    I found it!
    After going through some posts on this forum, I found an example of the ODP.net team how to use xmltype.
    It is crucial to call the dispose method of your parameters, yep I should have thought of that!.
    We populated a parametercollection in our data access assembly to return to the client, but failed to dispose the parameter we retrieved the data from.
    The explanation for the process not crashing on my laptop vs the service on a server could be that the server has 4 processors and is much faster. The .net garbage collector might not have been able to clear our objects?
    Oh well, perhaps some unlucky wandering soul with xmltype problems reads this and can use this stuff ;-)
    Richard

  • Newbie trying to query an XML field in Clob

    I've been unsuccessfully trying to query XML data in a CLOB field today without much success.
    The clob field stores approvals (Edited, Reviewed, Published) for each version.
    I'm trying to get the latest version (in this case 13) and what state (name) it is at (in this case 'Reviewed')
    Below is an example of the table and field with a single XML column...
    desc WIKI.OS_PROPERTYENTRY
    Name                                              Null?       Type
    ENTITY_NAME                                         NOT NULL VARCHAR2(125)
    ENTITY_ID                                         NOT NULL NUMBER(19)
    ENTITY_KEY                                         NOT NULL VARCHAR2(200)
    KEY_TYPE                                               NUMBER(10)
    BOOLEAN_VAL                                               NUMBER(1)
    DOUBLE_VAL                                               FLOAT(126)
    STRING_VAL                                               VARCHAR2(255)
    TEXT_VAL                                               CLOB
    LONG_VAL                                               NUMBER(19)
    INT_VAL                                               NUMBER(10)
    DATE_VAL                                               DATE
    SQL> select xmltype(text_val) from wiki.os_propertyentry where entity_id = 7274716 and entity_key = 'com.comalatech.workflow.approvals';
    XMLTYPE(TEXT_VAL)
    <ApprovalChecks>
      <ApprovalCheck>
        <name>Edited</name>
        <version>7</version>
        <approvers>
          <Approver>
         <approved>true</approved>
         <user>bgra030</user>
         <date>2008-10-31 13:47:25.638 NZDT</date>
         <comment>Initial import from Word document without change</comment>
          </Approver>
        </approvers>
        <weight>10</weight>
        <id>1</id>
        <stateId>0</stateId>
        <attachments/>
      </ApprovalCheck>
      <ApprovalCheck>
        <name>Reviewed</name>
        <version>7</version>
        <approvers>
          <Approver>
         <approved>true</approved>
         <user>bgra030</user>
         <date>2008-10-31 13:47:30.532 NZDT</date>
         <comment/>
          </Approver>
        </approvers>
        <weight>20</weight>
        <id>2</id>
        <stateId>0</stateId>
        <attachments/>
      </ApprovalCheck>
      <ApprovalCheck>
        <name>Signoff</name>
        <version>7</version>
        <approvers>
          <Approver>
         <approved>true</approved>
         <user>bgra030</user>
         <date>2008-10-31 13:47:32.532 NZDT</date>
         <comment/>
          </Approver>
        </approvers>
        <weight>30</weight>
        <id>3</id>
        <stateId>0</stateId>
        <attachments/>
      </ApprovalCheck>
      <ApprovalCheck>
        <name>Edited</name>
        <version>8</version>
        <approvers>
          <Approver>
         <approved>true</approved>
         <user>bgra030</user>
         <date>2008-11-02 10:54:07.903 NZDT</date>
         <comment>Updated references re Wiki, removed unwanted sections</comment>
          </Approver>
        </approvers>
        <weight>10</weight>
        <id>4</id>
        <stateId>0</stateId>
        <attachments/>
      </ApprovalCheck>
      <ApprovalCheck>
        <name>Reviewed</name>
        <version>8</version>
        <approvers>
          <Approver>
         <approved>true</approved>
         <user>bgra030</user>
         <date>2008-11-02 10:54:10.552 NZDT</date>
         <comment/>
          </Approver>
        </approvers>
        <weight>20</weight>
        <id>5</id>
        <stateId>0</stateId>
        <attachments/>
      </ApprovalCheck>
      <ApprovalCheck>
        <name>Signoff</name>
        <version>8</version>
        <approvers>
          <Approver>
         <approved>true</approved>
         <user>bgra030</user>
         <date>2008-11-02 10:54:13.161 NZDT</date>
         <comment/>
          </Approver>
        </approvers>
        <weight>30</weight>
        <id>6</id>
        <stateId>0</stateId>
        <attachments/>
      </ApprovalCheck>
      <ApprovalCheck>
        <name>Edited</name>
        <version>9</version>
        <approvers>
          <Approver>
         <approved>true</approved>
         <user>bgra030</user>
         <date>2009-11-13 08:53:00.649 NZDT</date>
         <comment>Testing approval information</comment>
          </Approver>
        </approvers>
        <weight>10</weight>
        <id>7</id>
        <stateId>0</stateId>
        <attachments/>
      </ApprovalCheck>
      <ApprovalCheck>
        <name>Edited</name>
        <version>9</version>
        <approvers>
          <Approver>
         <approved>false</approved>
         <user>bgra030</user>
         <date>2009-11-13 08:53:13.830 NZDT</date>
         <comment/>
          </Approver>
        </approvers>
        <weight>10</weight>
        <id>8</id>
        <stateId>0</stateId>
        <attachments/>
      </ApprovalCheck>
      <ApprovalCheck>
        <name>Edited</name>
        <version>12</version>
        <approvers>
          <Approver>
         <approved>true</approved>
         <user>bgra030</user>
         <date>2009-11-23 11:08:14.666 NZDT</date>
         <comment>Changes due to self auditing, using Study Audit Checklist and DM Study Checklist</comment>
          </Approver>
        </approvers>
        <weight>10</weight>
        <id>9</id>
        <stateId>0</stateId>
        <attachments/>
      </ApprovalCheck>
      <ApprovalCheck>
        <name>Reviewed</name>
        <version>12</version>
        <approvers>
          <Approver>
         <approved>true</approved>
         <user>bgra030</user>
         <date>2009-11-23 11:08:20.345 NZDT</date>
         <comment/>
          </Approver>
        </approvers>
        <weight>20</weight>
        <id>10</id>
        <stateId>0</stateId>
        <attachments/>
      </ApprovalCheck>
      <ApprovalCheck>
        <name>Signoff</name>
        <version>12</version>
        <approvers>
          <Approver>
         <approved>true</approved>
         <user>bgra030</user>
         <date>2009-11-23 11:08:23.997 NZDT</date>
         <comment/>
          </Approver>
        </approvers>
        <weight>30</weight>
        <id>11</id>
        <stateId>0</stateId>
        <attachments/>
      </ApprovalCheck>
      <ApprovalCheck>
        <name>Edited</name>
        <version>13</version>
        <approvers>
          <Approver>
         <approved>true</approved>
         <user>bgra030</user>
         <date>2011-10-31 10:42:37.703 NZDT</date>
         <comment>No change, just change of name of a linked page</comment>
          </Approver>
        </approvers>
        <weight>10</weight>
        <id>12</id>
        <stateId>0</stateId>
        <attachments/>
      </ApprovalCheck>
      <ApprovalCheck>
        <name>Reviewed</name>
        <version>13</version>
        <approvers>
          <Approver>
         <approved>true</approved>
         <user>bgra030</user>
         <date>2011-10-31 10:42:40.596 NZDT</date>
         <comm
    1 row selected.My query is way off,... I can't even get it to run, let alone getting the record I want without some hard coding...
    Can anyone help?
    Thanks in advance.
    select y.y_name, y.y_version, z.z_approved, z.z_user, z.z_date, z.z_comment
    from WIKI.os_propertyentry t,
         XMLTABLE('$p/ApprovalChecks/ApprovalCheck'
                  PASSING t.text_val as "p"
                  COLUMNS y_name       VARCHAR2(30) PATH 'ApprovalCheck/name',
                          y_version    NUMBER       PATH 'ApprovalCheck/version',
                          Approver     XMLTYPE      PATH 'ApprovalCheck/approvers/Approver/*') y,
         XMLTABLE('$a/Approver'
                  PASSING y.Approver as "a"
                  COLUMNS z_approved  VARCHAR2(8)   PATH 'Approver/approved',
                          z_user      VARCHAR2(30)  PATH 'Approver/user',
                          z_date      DATE          PATH 'Approver/date',
                          z_comment   VARCHAR2(100) PATH 'Approver/comment') z
    where entity_id = 7274716 and entity_key = 'com.comalatech.workflow.approvals'
    and   t.name = 'Reviewed'
    and   t.version = 13;
               PASSING t.text_val as "p"
    ERROR at line 4:
    ORA-00932: inconsistent datatypes: expected - got CLOB

    Further to the above, the query returns a single record okay,...
    SQL > l  
      1  with all_versions as (
      2    select c.title, y.y_name, y.y_version, z.z_approved, z.z_user, z.z_date z_date, z.z_comment,
      3           row_number() over( order by to_timestamp_tz(z_date, 'YYYY-MM-DD HH24:MI:SS.FF3 TZD') desc ) as rn
      4    from wiki.os_propertyentry t, wiki.content c,
      5         XMLTABLE('$p/ApprovalChecks/ApprovalCheck'
      6               PASSING xmltype(t.text_val) as "p"
      7               COLUMNS y_name       VARCHAR2(30) PATH 'name',
      8                    y_version       NUMBER       PATH 'version',
      9                    Approver       XMLTYPE      PATH 'approvers/Approver/*') y,
    10         XMLTABLE('$a'
    11               PASSING y.Approver as "a"
    12               COLUMNS z_approved  VARCHAR2(8)   PATH '/approved',
    13                    z_user      VARCHAR2(30)  PATH '/user',
    14                    z_date      VARCHAR2(30)  PATH '/date',
    15                    z_comment      VARCHAR2(100) PATH '/comment') z
    16    where c.contentid = t.entity_id
    17    and   c.spaceid = (select spaceid from wiki.spaces where spacename = 'Quality')
    18    and   entity_id = 7274716
    19    and entity_key = 'com.comalatech.workflow.approvals'
    20    )
    21  select title, y_name, y_version
    22  from all_versions
    23* where rn = 1
    SQL> /
    TITLE                           Y_NAME                          Y_VERSION
    Quality Audits (NIHI-5001)     Signoff                     17
    1 row selected.... but I want to now query on all records, not just one.
    When I comment out the clause (and entity_id = xxxxx) I now get an error. I should have got ~300 records,.... what do I need to do to make this work?
    SQL > 18
    18*   and   entity_id = 7274716
    SQL> > c /and/-- and
    18*   -- and     entity_id = 7274716
    SQL > l
      1  with all_versions as (
      2    select t.entity_id, c.title, y.y_name, y.y_version, z.z_approved, z.z_user, z.z_date z_date, z.z_comment,
      3           row_number() over( order by to_timestamp_tz(z_date, 'YYYY-MM-DD HH24:MI:SS.FF3 TZD') desc ) as rn
      4    from wiki.os_propertyentry t, wiki.content c,
      5         XMLTABLE('$p/ApprovalChecks/ApprovalCheck'
      6               PASSING xmltype(t.text_val) as "p"
      7               COLUMNS y_name       VARCHAR2(30) PATH 'name',
      8                    y_version       NUMBER       PATH 'version',
      9                    Approver       XMLTYPE      PATH 'approvers/Approver/*') y,
    10         XMLTABLE('$a'
    11               PASSING y.Approver as "a"
    12               COLUMNS z_approved  VARCHAR2(8)   PATH '/approved',
    13                    z_user      VARCHAR2(30)  PATH '/user',
    14                    z_date      VARCHAR2(30)  PATH '/date',
    15                    z_comment      VARCHAR2(100) PATH '/comment') z
    16    where c.contentid = t.entity_id
    17    and   c.spaceid = (select spaceid from wiki.spaces where spacename = 'Quality')
    18    -- and     entity_id = 7274716
    19    and entity_key = 'com.comalatech.workflow.approvals'
    20    )
    21  select entity_id, title, y_name, y_version
    22  from all_versions
    23* where rn = 1
    wikiprod: OPS$IT_DBA > /
              PASSING xmltype(t.text_val) as "p"
    ERROR at line 6:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00241: entity reference is not well formed
    Error at line 8
    ORA-06512: at "SYS.XMLTYPE", line 272
    ORA-06512: at line 1

  • Calling a stored procedure with a CLOB as input parameter

    Hello,
    I was unsuccessfully trying to call a stored procedure with a clob as input parameter from my C++ application using occi.
    Anyone got a working example to look at?
    I already checked the thread Invalid OCI handle when creating a Blob which didn't help.
    The problem seems to be that I don't have a lob locator to write my data (xml file) to. I tried creating a temporary clob using the sys.dbms_lob package which only resulted in a major headache on my part...
    I would appreciate any help.
    Kind regards
    Horst
    my environment:
    Visual Studio 2008, C++ application
    Oracle 11g

    To start using a blob you have to insert it into the database and then get it back. Sounds weird but that is how it is. Here is a very simple program to do this:
    #include<occi.h>
    #include <iostream>
    using namespace oracle::occi;
    using namespace std;
    int main()
      try
        Environment *env = Environment::createEnvironment(Environment::OBJECT);
        Connection *conn = env->createConnection("hr","hr","");
        string stmt1 = "insert into blob_tab values (:1) ";
        string stmt2 = "select col1 from blob_tab";
        Blob blob(conn);
        blob.setEmpty(conn);
        Statement *stmtObj = conn->createStatement(stmt1);
        stmtObj->setBlob(1,blob);
        stmtObj->executeUpdate();
        conn->commit();
        Blob blob1(conn);
        Statement *stmtObj2 = conn->createStatement(stmt2);
        ResultSet *rs = stmtObj2->executeQuery();
        while(rs->next())
         blob1 = rs->getBlob(1);
        string stmt3 = "begin my_proc(:1) ;end;";
        Statement *stmtObj3 =  conn->createStatement(stmt3);
        stmtObj3->setBlob(1,blob1);
        stmtObj3->executeUpdate();
      catch (SQLException e)
        cout << e.getMessage();
      /* The tables and procedure are primitive but ok for demo
        create table blob_tab(col1 blob);
        create or replace procedure my_proc(arg in blob)
        as
        begin
         -- just a putline here. you can do other more meaningful operations with the blob here
          dbms_output.put_line('hello');
       end;
    }Hope this helps.
    Thanks,
    Sumit

  • Query Approcal Procedure per line for SO

    Dear all expert,
    I would like to make query approval procedure that will tell user to ask approval every time they enter transaction that has gross margin < 0. This approval will work per line transaction. I mean if in line 1 has gross margin > 0 but in line 2, the gross margin is < 0, the approval procedures will run.
    Thanks for all your help

    Hi,
    AFAIK it's not possible to have query approvl on document lines, but only on document header or footer.
    Without using the SDK, I know no ways to achieve it.
    Regards,
    Eric

  • Query builder, procedural builder - Oracle 8.17

    I'm running Oracle 8.17 and I can't find query builder, procedural builder, report builder form builder and other builders. Where can I get these? I tried the universal installer and there are no options to install them.

    Hi Fraser,
    Thank you for responding.
    I think I fixed that problem,actually there was a spelling
    mistake in one of the parameter files.
    But now I get another error message, says:
    "ORA: 02068: following severe error from MSOLEDB
    ORA: 28511: lost RPC connection to heterogenous
    remote agent using
    SID = (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)
    (HOST=LOCAL_HOST)(PORT=1521)))(CONNECT_DATA=
    (SERVICE_NAME=<SERVICE_NAME>)))
    Do I have to configure the SQL Server network utilities?
    I pinged both the servers ,they talk to each other.
    But when I use tnsping ,the client machine (i.e.,the SQL Server
    machine)talks to server(Oracle machine) but the server doesn't
    talk to the client.
    I am definitely not doing something right.
    Asha.

  • Query xml data from a CLOB datatye

    All,
    I read in an oracle white paper that is is possible to query XML data from CLOB datatype using oracle text index using operators HASPATH() and INPATH(). I am not able to find any example on how to do this. Can someone please post a simple example here.
    Thank You very much!

    SCOTT@10gXE> CREATE TABLE your_table (id NUMBER, xml_data CLOB)
      2  /
    Table created.
    SCOTT@10gXE> INSERT INTO your_table (id, xml_data)
      2  SELECT t.deptno,
      3           DBMS_XMLGEN.GETXML
      4             ('SELECT d.dname,
      5                   CURSOR (SELECT e.ename, e.job
      6                        FROM   emp e
      7                        WHERE  e.deptno = d.deptno) emp_data
      8            FROM   dept d
      9            WHERE  d.deptno = ' || t.deptno)
    10  FROM   dept t
    11  /
    5 rows created.
    SCOTT@10gXE> COMMIT
      2  /
    Commit complete.
    SCOTT@10gXE> begin
      2    ctx_ddl.create_section_group('xmlpathgroup', 'PATH_SECTION_GROUP');
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SCOTT@10gXE> CREATE INDEX myindex
      2  ON your_table(xml_data)
      3  INDEXTYPE IS ctxsys.context
      4  PARAMETERS ('datastore ctxsys.default_datastore
      5              filter ctxsys.null_filter
      6              section group xmlpathgroup'
      7            )
      8  /
    Index created.
    SCOTT@10gXE> SELECT * FROM your_table
      2  WHERE  CONTAINS (xml_data, 'PERSONNEL INPATH (//DNAME)') > 0
      3  /
            ID XML_DATA
            50 <?xml version="1.0"?>
               <ROWSET>
                <ROW>
                 <DNAME>PERSONNEL</DNAME>
                 <EMP_DATA>
                 </EMP_DATA>
                </ROW>
               </ROWSET>
    SCOTT@10gXE> SELECT * FROM your_table
      2  WHERE  CONTAINS (xml_data, 'HASPATH (//DNAME="PERSONNEL")') > 0
      3  /
            ID XML_DATA
            50 <?xml version="1.0"?>
               <ROWSET>
                <ROW>
                 <DNAME>PERSONNEL</DNAME>
                 <EMP_DATA>
                 </EMP_DATA>
                </ROW>
               </ROWSET>
    SCOTT@10gXE> SELECT * FROM your_table
      2  WHERE  CONTAINS (xml_data, 'CLARK INPATH (//ENAME)') > 0
      3  /
            ID XML_DATA
            10 <?xml version="1.0"?>
               <ROWSET>
                <ROW>
                 <DNAME>ACCOUNTING</DNAME>
                 <EMP_DATA>
                  <EMP_DATA_ROW>
                   <ENAME>CLARK</ENAME>
                   <JOB>MANAGER</JOB>
                  </EMP_DATA_ROW>
                  <EMP_DATA_ROW>
                   <ENAME>KING</ENAME>
                   <JOB>PRESIDENT</JOB>
                  </EMP_DATA_ROW>
                  <EMP_DATA_ROW>
                   <ENAME>MILLER</ENAME>
                   <JOB>CLERK</JOB>
                  </EMP_DATA_ROW>
                 </EMP_DATA>
                </ROW>
               </ROWSET>
    SCOTT@10gXE> SELECT * FROM your_table
      2  WHERE  CONTAINS (xml_data, 'HASPATH (//ENAME="CLARK")') > 0
      3  /
            ID XML_DATA
            10 <?xml version="1.0"?>
               <ROWSET>
                <ROW>
                 <DNAME>ACCOUNTING</DNAME>
                 <EMP_DATA>
                  <EMP_DATA_ROW>
                   <ENAME>CLARK</ENAME>
                   <JOB>MANAGER</JOB>
                  </EMP_DATA_ROW>
                  <EMP_DATA_ROW>
                   <ENAME>KING</ENAME>
                   <JOB>PRESIDENT</JOB>
                  </EMP_DATA_ROW>
                  <EMP_DATA_ROW>
                   <ENAME>MILLER</ENAME>
                   <JOB>CLERK</JOB>
                  </EMP_DATA_ROW>
                 </EMP_DATA>
                </ROW>
               </ROWSET>
    SCOTT@10gXE>

  • Size limit on xmlType CLOB?

    I seem to be running into a limit on the size of the CLOB returned from a select into an XMLType. When it gets around 275K it doesn't return a value anymore - it does not return an error, just the .getclobval is empty. I am using the Select XMLAgg(XMLElement) Into XMLType method. Using 9.2 ORA DB running on UNIX. If anybody knows if there is actually a limit, it would be greatly appreciated. I know I can use the dbms_xmlgen method but I want to avoid that if possible.
    The full stored proc text:
    PROCEDURE GetISRNumber ( RetXML OUT CLOB ) IS
    xmlTypeRet xmlType;
    begin
    SELECT xmlagg(XMLELEMENT("Record", XMLELEMENT("JobNumber", ISR.ISR_NO)
    , XMLELEMENT( "address", isr.COMPL_ADDRESS)
    , XMLElement( "Street", isr.Street_Name1)
    , XMLElement( "CivicExtensionDFJOIK", isr.ALPHA_CIVIC)
    , XMLElement( "Created_Date", isr.created_date)
    )) AS "XMLReturned"
    INTO xmlTypeRet
    (Select ISR_NO, COMPL_ADDRESS, Street_Name1, ALPHA_CIVIC, Created_Date FROM ISR)
    RetXML := xmltyperet.getclobval();
    RetXML := '<Job>' || RetXML || '</Job>';
    EXCEPTION
    WHEN OTHERS THEN
    Case SQLCODE
    When -30625 Then
    RetXML := '<Job>No Records Found</Job>';
    Else
    Raise;
    END CASE;
    end GetISRNumber;

    This link will be usefull
    for this problem
    http://www.oracle.com/technology/sample_code/tech/java/codesnippet/xmldb/HowToLoadLargeXML.html

  • 275K Limit on xmlType CLOB?

    I seem to be running into a limit on the size of the CLOB returned from a select into an XMLType. When it gets around 275K it doesn't return a value anymore - it does not return an error, just the .getclobval is empty. I am using the Select XMLAgg(XMLElement) Into XMLType method. Using 9.2 ORA DB running on UNIX. If anybody knows if there is actually a limit, it would be greatly appreciated. I know I can use the dbms_xmlgen method but I want to avoid that if possible.
    The full stored proc text:
    PROCEDURE GetISRNumber ( RetXML OUT CLOB ) IS
    xmlTypeRet xmlType;
    begin
    SELECT xmlagg(XMLELEMENT("Record", XMLELEMENT("JobNumber", ISR.ISR_NO)
    , XMLELEMENT( "address", isr.COMPL_ADDRESS)
    , XMLElement( "Street", isr.Street_Name1)
    , XMLElement( "CivicExtensionDFJOIK", isr.ALPHA_CIVIC)
    , XMLElement( "Created_Date", isr.created_date)
    )) AS "XMLReturned"
    INTO xmlTypeRet
    FROM isr ISR ;
    RetXML := xmltyperet.getclobval();
    RetXML := '<Job>' || RetXML || '</Job>';
    EXCEPTION
    WHEN OTHERS THEN
    Case SQLCODE
    When -30625 Then
    RetXML := '<Job>No Records Found</Job>';
    Else
    Raise;
    END CASE;
    end GetISRNumber;

    Please post the question at
    PL/SQL XML Programming
    for quick response.

  • Query Column List convert to CLOB

    Hi,
    we need to print the data by using UTL_FILE from the dynamically constructing sql query with pivot column (It is having more than 1000 column).
    But this query contains 1008 columns but it throwing error maxmimum number of columns in a table or views 1000.
    Query
    Select col1,col2,col3,clo4,col5,col6,col7,col8 ,Pivot columns 1 to 1000 from tab1
    Each and every column data having more than 3500.
    Please share your idea ?
    1.is it possoble to concatenate all the columns and write into file using utl_file.
    2.How to convert the rows as clob column
    3.Each and every row should contains more than 32767.
    Regards,
    Sudhakar P.

    Sudhakar P wrote:
    Hi,
    we need to print the data by using UTL_FILE from the dynamically constructing sql query with pivot column (It is having more than 1000 column).
    But this query contains 1008 columns but it throwing error maxmimum number of columns in a table or views 1000.Can't overcome Oracle's internal limits.
    Each and every column data having more than 3500.More than 3500 what?
    1.is it possoble to concatenate all the columns and write into file using utl_file.Yes.
    2.How to convert the rows as clob columnUse built in LOB functionality, such as provided in the DBMS_LOB package for example.
    3.Each and every row should contains more than 32767.You would have to use CLOB's to store more than 4000 characters in SQL. 32767 is the limit in PL/SQL for VARCHAR2.
    If it's dynamic, then you're going to have to pretty much use the DBMS_SQL package to construct things (11g allows the use of CLOB with EXECUTE IMMEDIATE for dynamic statements but it's still not ideal to get the data back if you don't know the output structure).
    Here's an example from my standard library for writing out dynamic SQL output to a CSV file, which would probably be a good starting point...
    As sys user:
    CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
    GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
    /As myuser:
    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
                                         ,p_dir IN VARCHAR2
                                         ,p_header_file IN VARCHAR2
                                         ,p_data_file IN VARCHAR2 := NULL) IS
      v_finaltxt  VARCHAR2(4000);
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_fh        UTL_FILE.FILE_TYPE;
      v_samefile  BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
    BEGIN
      c := DBMS_SQL.OPEN_CURSOR;
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      d := DBMS_SQL.EXECUTE(c);
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
        END CASE;
      END LOOP;
      -- This part outputs the HEADER
      v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
      FOR j in 1..col_cnt
      LOOP
        v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
      END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
      UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      IF NOT v_samefile THEN
        UTL_FILE.FCLOSE(v_fh);
      END IF;
      -- This part outputs the DATA
      IF NOT v_samefile THEN
        v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
      END IF;
      LOOP
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        EXIT WHEN v_ret = 0;
        v_finaltxt := NULL;
        FOR j in 1..col_cnt
        LOOP
          CASE rec_tab(j).col_type
            WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                        v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
            WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                        v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                        v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
          ELSE
            v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
          END CASE;
        END LOOP;
      --  DBMS_OUTPUT.PUT_LINE(v_finaltxt);
        UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
      END LOOP;
      UTL_FILE.FCLOSE(v_fh);
      DBMS_SQL.CLOSE_CURSOR(c);
    END;This allows for the header row and the data to be written to seperate files if required.
    e.g.
    SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
    PL/SQL procedure successfully completed.Output.txt file contains:
    empno,ename,job,mgr,hiredate,sal,comm,deptno
    7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
    7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
    7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
    7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
    7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
    7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
    7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
    7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
    7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
    7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
    7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
    7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
    7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
    7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10The procedure allows for the header and data to go to seperate files if required. Just specifying the "header" filename will put the header and data in the one file.
    Adapt to output different datatypes and styles are required.

  • Help on how to query 11g table with XMLType column

    To all,
    We have this table:
    DESC MESSAGE
    Name Null Type
    MESSAGE_ID NOT NULL NUMBER(38)
    REQUEST_UU_ID NOT NULL VARCHAR2(50)
    MESSAGE_TYPE_CD NOT NULL CHAR(3 CHAR)
    EMPLOYEE_NUM NOT NULL VARCHAR2(8)
    SEQUENCE_NUM VARCHAR2(20)
    REVERSAL_SEQUENCE_NUM VARCHAR2(20)
    TRANSACTION_TS TIMESTAMP(6)
    MESSAGE_CONTENT_TXT NOT NULL XMLTYPE()
    CREATE_BY_NM NOT NULL VARCHAR2(50 CHAR)
    CREATE_BY_TS NOT NULL TIMESTAMP(6)
    LAST_UPDATE_BY_NM NOT NULL VARCHAR2(50 CHAR)
    LAST_UPDATE_BY_TS NOT NULL TIMESTAMP(6)
    Given we have multiple columns and one is XMLType how do I query to find rows in the db that match this XPath
    Here is a fragment of XML that is held in MESSAGE_CONTENT_TXT XMLType column:
    <?xml version="1.0" encoding="UTF-8"?>
    <cfg-env:Envelope xmlns="http://www.co.com/schemas/CFX/" xmlns:cfg-env="http://www.co.com/schemas/cfg-env/" xmlns:cfg-hdr="http://www.co.com/schemas/cfg-hdr/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.co.com/schemas/cfg-env/" >
         <cfg-env:Header>
              <cfg-hdr:MessageHeader xmlns:cfg-hdr="http://www.co.com/schemas/cfg-hdr/" xmlns:cfg-env="http://www.co.com/schemas/cfg-env/" xmlns="http://www.co.com/schemas/CFX/">
                   <cfg-hdr:Service>
                        <cfg-hdr:ServiceName>process</cfg-hdr:ServiceName>
                        <cfg-hdr:MessageType>Request</cfg-hdr:MessageType>
                        <cfg-hdr:ServiceVersion>1</cfg-hdr:ServiceVersion>
                   </cfg-hdr:Service>
                   <cfg-hdr:From>
                        <cfg-hdr:PartyId>13-175-8724</cfg-hdr:PartyId>
                        <cfg-hdr:CostCenter>2009065</cfg-hdr:CostCenter>
                        <cfg-hdr:System>
                             <cfg-hdr:Application>[email protected]</cfg-hdr:Application>
                             <cfg-hdr:Version>1.0</cfg-hdr:Version>
                             <cfg-hdr:Channel>TLR</cfg-hdr:Channel>
                        </cfg-hdr:System>
                        <cfg-hdr:OrigReplyToQMgr>QMBKRD01</cfg-hdr:OrigReplyToQMgr>
                        <cfg-hdr:OrigReplyToQ>Q1</cfg-hdr:OrigReplyToQ>
                   </cfg-hdr:From>
                   <cfg-hdr:UserSession>
                        <cfg-hdr:SignonRole>User</cfg-hdr:SignonRole>
                        <cfg-hdr:LogonId>R099999</cfg-hdr:LogonId>
    I'm trying to find rows in the database that are /Envelope/Header/MessageHeader/UserSession/LogonId/R099999.
    Thanks for the assistance. I'm new to XML DB. I appreciate the help.
    Eric

    Hi Eric,
    You can use XMLExists, like this :
    select *
    from message t
    where xmlexists(
          'declare namespace env = "http://www.co.com/schemas/cfg-env/"; (: :)
           declare namespace hdr = "http://www.co.com/schemas/cfg-hdr/"; (: :)
           /env:Envelope/env:Header/hdr:MessageHeader/hdr:UserSession[hdr:LogonId=$id]'
           passing t.message_content_txt
                 , 'R099999' as "id"
    );

  • Query to read XML from CLOB table column

    Hi
    I want an SQL to get the following information extract from a CLOB table column.
    MasterReport/sg:RptDef/sg:RptCell@RealDesc MasterReport/sg:RptDef/sg:RptCell@RealNum
    credits                              100
    debits                              100
    Sample XML data from table column is:
    <?xml version="1.0" encoding="UTF-8" ?>
    <MasterReport xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sg="http://www.oracle.com/fsg/2002-03-20/" xsi:schemaLocation="http://www.oracle.com/2002-03-20/fsg.xsd">
    <sg:LDGName>Vision Portugal</sg:LDGName>
    <sg:SOBName>Vision Portugal</sg:SOBName>
    <sg:DataAccessSetName>Vision Portugal</sg:DataAccessSetName>
    <sg:InternalReportName>Model 30 Report</sg:InternalReportName>
    <sg:CustomParam10 />
    <sg:RowContext RowId="r100001">
    <sg:RowName />
    <sg:RowLineItem>Litigation Credits- Total amount from previous period</sg:RowLineItem>
    <sg:RowDispUnit>1</sg:RowDispUnit>
    <sg:RowDispFormat />
    <sg:RowUnitOfMeasure>EUR</sg:RowUnitOfMeasure>
    <sg:RowLedgerCurrency>ANY</sg:RowLedgerCurrency>
    <sg:RowCurrencyType>T</sg:RowCurrencyType>
    <sg:RowChangeSign>0</sg:RowChangeSign>
    <sg:RowSeq>1.0000000000000</sg:RowSeq>
    </sg:RowContext>
    <sg:RowContext RowId="r100002">
    <sg:RowName />
    <sg:RowLineItem>Litigation credits- Taxed amounts from column2 for Previous period</sg:RowLineItem>
    <sg:RowDispUnit>1</sg:RowDispUnit>
    <sg:RowDispFormat />
    <sg:RowUnitOfMeasure>EUR</sg:RowUnitOfMeasure>
    <sg:RowLedgerCurrency>ANY</sg:RowLedgerCurrency>
    <sg:RowCurrencyType>T</sg:RowCurrencyType>
    <sg:RowChangeSign>0</sg:RowChangeSign>
    <sg:RowSeq>2.0000000000000</sg:RowSeq>
    </sg:RowContext>
    <sg:ColContext ColId="c1000">
    <sg:ColAmountType />
    <sg:ColPeriod />
    <sg:ColPerOffset />
    <sg:ColChangeSign />
    <sg:ColPosition />
    <sg:ColSeq />
    <sg:ColWidth>100</sg:ColWidth>
    </sg:ColContext>
    <sg:ColContext ColId="c1001">
    <sg:ColName>Total</sg:ColName>
    <sg:ColDescr />
    <sg:ColDispUnit>1</sg:ColDispUnit>
    <sg:ColUnitOfMeasure>EUR</sg:ColUnitOfMeasure>
    <sg:ColLedgerCurrency>ANY</sg:ColLedgerCurrency>
    <sg:ColCurrencyType>T</sg:ColCurrencyType>
    <sg:ColDispFormat>999999999.99</sg:ColDispFormat>
    <sg:ColAmountType>YTD-Actual</sg:ColAmountType>
    <sg:ColPerOffset>0</sg:ColPerOffset>
    <sg:ColAmntId>14</sg:ColAmntId>
    <sg:ColParamId>-1</sg:ColParamId>
    <sg:ColType>A</sg:ColType>
    <sg:ColStyle>B</sg:ColStyle>
    <sg:ColPeriod>10-08</sg:ColPeriod>
    <sg:ColPeriodYear>2008</sg:ColPeriodYear>
    <sg:ColPeriodNum>11</sg:ColPeriodNum>
    <sg:ColPeriodStart>2008-10-01T00:00:00</sg:ColPeriodStart>
    <sg:ColPeriodEnd>2008-10-31T00:00:00</sg:ColPeriodEnd>
    <sg:ColChangeSign>0</sg:ColChangeSign>
    <sg:ColHeadLine1>Totals</sg:ColHeadLine1>
    <sg:ColHeadLine2 />
    <sg:ColHeadLine3 />
    <sg:ColHeadLine4 />
    <sg:ColHeadLine5 />
    <sg:ColHeadLine6 />
    <sg:ColHeadLine7 />
    <sg:ColHeadLine8 />
    <sg:ColHeadLine9 />
    <sg:ColPosition>99</sg:ColPosition>
    <sg:ColSeq>1.0000000000000</sg:ColSeq>
    <sg:ColWidth>14</sg:ColWidth>
    </sg:ColContext>
    <sg:RptDef RptId="p1001" RptDetName="Ledger=Vision PT (Vision Portugal)" RptPESegm="" RptPEVal="" RptTabLabel="Output 1 (Vision PT)">
    <sg:RptLine RptCnt="p1001" RowCnt="r100001" LineRowSeq="1.0000000000000" LinCnt="l100001">
    <sg:RptCell ColCnt="c1000" RealDesc="debits">debits</sg:RptCell>
    <sg:RptCell ColCnt="c1001" RealNum="100.000000">100.00</sg:RptCell>
    </sg:RptLine>
    <sg:RptLine RptCnt="p1001" RowCnt="r100002" LineRowSeq="2.0000000000000" LinCnt="l100002">
    <sg:RptCell ColCnt="c1000" RealDesc="creditsd">credits</sg:RptCell>
    <sg:RptCell ColCnt="c1001" RealNum="100.000000">100.00</sg:RptCell>
    </sg:RptLine>
    </sg:RptDef>
    <sg:TabCount>1</sg:TabCount>
    </MasterReport>
    Please help me.
    Regards
    Giri
    Edited by: user576087 on Mar 18, 2012 11:54 PM

    I'm not sure if you want the values from the attribute or the element, but this should give you a good start :
    SQL> alter session set nls_numeric_characters = ".,";
    Session altered
    SQL>
    SQL> select x.*
      2  from my_table t
      3     , xmltable(
      4         xmlnamespaces('http://www.oracle.com/fsg/2002-03-20/' as "sg")
      5       , '/MasterReport/sg:RptDef/sg:RptLine'
      6         passing xmltype(t.xmldoc)
      7         columns type    varchar2(30) path 'sg:RptCell[1]'
      8               , amount  number       path 'sg:RptCell[2]'
      9       ) x
    10  ;
    TYPE                               AMOUNT
    debits                                100
    credits                               100

  • SAP Query creation procedure

    Hi,
    Can any one send me complete procedure for creation of query in SQ03. Please give me step by step procedure
    Thanks,
    Regards,
    Mukul

    hi,
    in sq02 define the infoset. here u define the tables and the join relation between them. generate the infoset. in sq03 create user grps (if not already existing) and then assign the infosets to them. assign user ids to the the user grps.   in sq01 create the query in the infoset and define the list and selection fields. make sure u check the query area in which the infodset and the query is created (global or client sprcific).
    saurabh

  • To connect a datablock to a query - stored procedure: problem

    I have the following table...
    CREATE TABLE I_TIPOLOGIA (
    CODICE NUMBER(6),
    DESCRIZIONE VARCHAR2(100),
    CONSTRAINT I_TIPOLOGIA_PK PRIMARY KEY (CODICE) );
    and the following package to connect a datablock to
    previous table with a stored procedure...
    CREATE or REPLACE PACKAGE DATABANKER_TIPOLOGIE AS
    TYPE TipTableOfRec IS TABLE OF I_TIPOLOGIA%ROWTYPE;
    PROCEDURE leggi(resultset IN OUT TipTableOfRec);
    END DATABANKER_TIPOLOGIE;
    CREATE or REPLACE PACKAGE BODY DATABANKER_TIPOLOGIE AS
    PROCEDURE leggi(resultset IN OUT TipTableOfRec) AS
    BEGIN
    SELECT * BULK COLLECT INTO resultset
    FROM I_TIPOLOGIA;
    END leggi;
    END DATABANKER_TIPOLOGIE;
    When I compile the form I receive in QUERY-PROCEDURE trigger
    en error 306: "number or type of arguments are wrong in POPULATE_BLOCK"
    I post the trigger auto generated by Forms Builder 6i...
    DECLARE
    bk_data DATABANKER_TIPOLOGIE.TIPTABLEOFREC;
    BEGIN
    DATABANKER_TIPOLOGIE.leggi3(bk_data);
    PLSQL_TABLE.POPULATE_BLOCK(bk_data, 'BLOCCO50'); -- <- error here
    END;
    How can I solve this problem? Maybe there is a bug?
    P.S. I'm using Oracle Database 9i

    CREATE or REPLACE PACKAGE DATABANKER_TIPOLOGIE AS
    TYPE TipTableOfRec IS TABLE OF I_TIPOLOGIA%ROWTYPE;
    PROCEDURE leggi(resultset IN OUT TipTableOfRec);
    END DATABANKER_TIPOLOGIE;I have solved with this replacement 1) -> 2)
    1) TYPE TipTableOfRec IS TABLE OF I_TIPOLOGIA%ROWTYPE;
    2) TYPE TipTableOfRec IS TABLE OF I_TIPOLOGIA%ROWTYPE
    INDEX BY BINARY_INTEGER;
    with 2) now works.
    Now I have stored-procedures for query, insert, delete
    and update.
    I have some problems with delete and update of the records
    because it seems that they are locked.
    I think that it is due to the absence of lock
    stored-procedure... there's someone that can help me with
    the lock SP implementation?

  • Update query in procedure

    I have 2 tables aas below.
    create table main_data(id number,all_set_flag char(1),set_time timestamp)
    create table sub_data(id number,set_time timestamp);
    insert into main_data values(1,'','');
    insert into main_data values(1,'','');
    insert into main_data values(1,'','');
    insert into main_data values(1,'','');
    insert into main_data values(2,'Y','');
    insert into main_data values(2,'Y','');
    insert into main_data values(2,'Y','');
    My requirement is 1)For a particular id if all the all_set_flag is 'Y' then I need to insert the distinct id record and set_time as systimestamp in sub_data table
    2)Afer inserting into subdata for that particular id I need to update back in main_data set_time same as set_time in sub_data.
    a)For the part -1 I wrote an insert statement like this.For part-2 how can I update it bk?.
    b)I am going to use the below query in a procedure.Is there any better way to achieve this than below approach.Please note that my main_data have more columns(200 columns)
    and there are millions of records.10 million atleast.Please suggest.
    insert into sub_data(id,set_time)
    (select
    distinct
    id,
    systimestamp
    from
    select
    id,
    sum(case when all_set_flag = 'Y' then 1 else 0 end) over (partition by id) as match_cnt,
    count(*) over (partition by id) as total_count
    from main_data where not exists (Select null from sub_data where sub_data.id = main_data.id
    where match_cnt = total_count);
    select * from sub_data

    I am using a PL/SQL Collection type and doing it. Was think of doing it in plain SQL but combaining the Insert and Update i guess needs some PL/SQL.
    Here is what i did
    declare
      type main_data_id is table of main_data.id%type;
      type main_data_tm is table of main_data.set_time%type;
      lMainDataId main_data_id;
      lmainDataTm main_data_tm;
    begin
      select distinct id, systimestamp
      bulk collect into lMainDataId, lMainDataTm
        from (
              select a.* , count(*) over(partition by id) id_cnt, count(decode(all_set_flag, 'Y',1,null)) over(partition by id) flag_cnt
                from main_data a
       where id_cnt = flag_cnt;
      forall i in 1..lMainDataId.count
        insert into sub_data(id, set_time) values (lMainDataId(i), lMainDataTm(i));
      forall i in 1..lMainDataId.count
        update main_data set set_time = lMainDataTm(i) where id = lMainDataId(i);
      commit;
    end;
    /Waiting to see if someone has a better approach to it :)
    Note: I have not used LIMIT clause in BULK COLLECT because i dont have idea of the volume of data involved. If there is large volume of data then you need to consider using it.

Maybe you are looking for