Passing PL/SQL varchar2 variable to XML Query

Hi guys,
i'm having trouble passing a pl/sql varchar2 variable to an XMLQuery.
This is the relevant part of my code:
DECLARE
   lo_result   XMLTYPE;         --contains the XML which is being parsed below
   lo_return   XMLTYPE;             -- for the XML result returned by XMLQuery
   lo_start    VARCHAR2 (100) DEFAULT 'Toronto'; -- a PL/SQL varchar2 variable
   lo_end      VARCHAR2 (100) DEFAULT 'Ottawa';  -- a PL/SQL varchar2 variable
BEGIN
   SELECT XMLQUERY (
             'for $i in //leg[start_address[text()[contains(.,$lo_start)]] and end_address[text()[contains(.,$lo_end)]]]/distance/value/text() return ($i)'
             PASSING lo_result, lo_start AS "lo_start", lo_end AS "lo_end"
             RETURNING CONTENT)
     INTO lo_return
     FROM DUAL;
END;The XPath expression is correct but it doesn't seem to accept my variables since lo_return is empty.
I think the variables should be of type Xmltype but the compiler won't let me convert them because they do not contain any XML tags .
Hope anyone can help.
Thanks,
Martina

may be i missed anything but
>
<start_address>Toronto, Ontario, Kanada</start_address>
<end_address>Huntsville, Alabama, Vereinigte Staaten</end_address>
>
and
>
lo_start VARCHAR2 (100) DEFAULT 'Toronto'; -- a PL/SQL varchar2 variable
lo_end VARCHAR2 (100) DEFAULT 'Ottawa'; -- a PL/SQL varchar2 variable
>
so
SQL> SELECT XMLQUERY (
  2              'for $i in //leg[start_address[text()[contains(.,$lo_start)]] and end_address[text()[contains(.,$lo_end)]]]/distance/value/text() return ($i)'
  3               PASSING
  4               xmltype('<DirectionsResponse>
  5    <status>OK</status>
  6    <route>
  7      <summary>I-75 N</summary>
  8      <leg>
  9        <duration>
10          <value>48220</value>
11          <text>13 Stunden, 24 Minuten</text>
12        </duration>
13        <distance>
14          <value>1404935</value>
15          <text>1.405 km</text>
16        </distance>
17        <start_location>
18          <lat>43.6533100</lat>
19          <lng>-79.3827700</lng>
20        </start_location>
21        <end_location>
22          <lat>34.7303300</lat>
23          <lng>-86.5860700</lng>
24        </end_location>
25        <start_address>Toronto, Ontario, Kanada</start_address>
26        <end_address>Huntsville, Alabama, Vereinigte Staaten</end_address>
27      </leg>
28    </route>
29  </DirectionsResponse>'),
30               'Toronto' AS "lo_start", 'Ottawa' AS "lo_end"
31               RETURNING CONTENT)
32       FROM DUAL;
XMLQUERY('FOR$IIN//LEG[START_A
SQL>
SQL>
SQL>
SQL> SELECT XMLQUERY (
  2              'for $i in //leg[start_address[text()[contains(.,$lo_start)]] and end_address[text()[contains(.,$lo_end)]]]/distance/value/text() return ($i)'
  3               PASSING
  4               xmltype('<DirectionsResponse>
  5    <status>OK</status>
  6    <route>
  7      <summary>I-75 N</summary>
  8      <leg>
  9        <duration>
10          <value>48220</value>
11          <text>13 Stunden, 24 Minuten</text>
12        </duration>
13        <distance>
14          <value>1404935</value>
15          <text>1.405 km</text>
16        </distance>
17        <start_location>
18          <lat>43.6533100</lat>
19          <lng>-79.3827700</lng>
20        </start_location>
21        <end_location>
22          <lat>34.7303300</lat>
23          <lng>-86.5860700</lng>
24        </end_location>
25        <start_address>Toronto, Ontario, Kanada</start_address>
26        <end_address>Huntsville, Alabama, Vereinigte Staaten</end_address>
27      </leg>
28    </route>
29  </DirectionsResponse>'),
30               'Toronto' AS "lo_start", /*'Ottawa'*/'Huntsville' AS "lo_end"
31               RETURNING CONTENT)
32       FROM DUAL;
XMLQUERY('FOR$IIN//LEG[START_A
1404935
SQL>

Similar Messages

  • Sql:variable and XML query performance

    Can someone help with sql:variable() in xml queries?  It seems that when I attempt to reference variables with the sql:variable(...) function in an xpath function (exist or nodes) it comes up with a totally different query plan, possibly ignoring
    my secondary indices like the ones for VALUE, PATH.
    But if I replace sql:variable("@p_ObjectIdentifierForReference") with the literal (ie. "ord/p/ord0616.p") then it uses secondary indices more consistently.
    Below you will see an unsuccessful attempt to get the query to "OPTIMIZE FOR" a specific literal value of @p_ObjectIdentifierForReference.  But this doesn't give work.  It doesn't give me a plan using the secondary index I expect.
    Ideally there would be a way to get the sql:variable(...) function to give the same query plan as a literal. Not sure why that isn't the default behavior.
    DECLARE
    @p_ObjectIdentifierForReference
    varchar(500);
    SET
    @p_ObjectIdentifierForReference
    = 'ord/p/ord0616.p';
    WITH
    XMLNAMESPACES ('uri:schemas-progress-com:XREFD:0004'
    as D)
    SELECT  
    XREF_FileDataReference.XREF_FileData     
    AS XrefFileData,
    InnerRowNode.value('/D:Reference[1]/D:File-num[1]',
    'int') 
    AS FileNumber,
    InnerRowNode.value('/D:Reference[1]/D:Line-num[1]',
    'int') 
    AS LineNumber
    FROM
    (SELECT
    XREF.XREF_FileData.XREF_FileData,
    XREF.XREF_FileData.XREF_FileEntry,
    InnerRow.query('.')
    AS InnerRowNode
     FROM
    XREF.XREF_FileData
    OUTER APPLY
    DataXref.nodes('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference")
    and @Reference-type = "RUN"]')
    as T(InnerRow)                                                           
    WHERE    DataXref.exist('/D:Cross-reference/D:Source/D:Reference[@Object-identifier
    = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]')
    = 1) 
    AS XREF_FileDataReference
     INNER
    JOIN  XREF.XREF_MemberBuilt  
    ON XREF_MemberBuilt.XREF_FileData  
    = XREF_FileDataReference.XREF_FileData
     INNER
    JOIN  XREF.XREF_FileEntry 
    ON XREF_FileEntry.XREF_FileEntry
    = XREF_FileDataReference.XREF_FileEntry 
    WHERE
    XREF_MemberBuilt.XREF_ProjectBuilt
    = 69
    OPTION(RECOMPILE,
    OPTIMIZE FOR (@p_ObjectIdentifierForReference
    = 'ord/p/ord0616.p')

    I tried to create a "repro" of your query so we can work on it and try and improve it, but I got the best results by just adding text() and [1] to it, eg
    SELECT
    XREF_FileDataReference.XREF_FileData AS XrefFileData,
    InnerRowNode.value('(/D:Reference/D:File-num/text())[1]', 'int') AS FileNumber,
    InnerRowNode.value('(/D:Reference/D:Line-num/text())[1]', 'int') AS LineNumber
    FROM (
    In my main repro, even with a large piece of xml with 100,000 elements, there still wasn't much difference between the queries:
    USE tempdb
    GO
    IF NOT EXISTS ( SELECT * FROM sys.schemas WHERE name = 'XREF' )
    EXEC( 'CREATE SCHEMA XREF' )
    GO
    IF OBJECT_ID('XREF.XREF_FileData') IS NOT NULL DROP TABLE XREF.XREF_FileData
    CREATE TABLE XREF.XREF_FileData
    rowId INT IDENTITY,
    DataXref XML,
    XREF_FileData INT,
    XREF_FileEntry INT,
    CONSTRAINT PK_XREF_FileData PRIMARY KEY ( rowId )
    GO
    IF OBJECT_ID('XREF.XREF_MemberBuilt') IS NOT NULL DROP TABLE XREF.XREF_MemberBuilt
    CREATE TABLE XREF.XREF_MemberBuilt
    XREF_ProjectBuilt INT,
    XREF_FileData INT
    GO
    IF OBJECT_ID('XREF.XREF_FileEntry') IS NOT NULL DROP TABLE XREF.XREF_FileEntry
    CREATE TABLE XREF.XREF_FileEntry
    XREF_FileEntry INT
    GO
    -- Create larger piece of xml for repro
    ;WITH XMLNAMESPACES ( DEFAULT 'uri:schemas-progress-com:XREFD:0004' ), cte AS (
    SELECT TOP 100000 ROW_NUMBER() OVER ( ORDER BY ( SELECT 1 ) ) rn
    FROM master.sys.columns c1
    CROSS JOIN master.sys.columns c2
    CROSS JOIN master.sys.columns c3
    INSERT INTO XREF.XREF_FileData ( DataXref, XREF_FileData, XREF_FileEntry )
    SELECT
    SELECT
    CASE rn WHEN 9999 THEN 'ord/p/ord0616.p' ELSE CAST( rn AS VARCHAR(20) ) END AS "@Object-identifier",
    'RUN' AS "@Reference-type",
    SELECT
    rn AS "File-num",
    rn * 10 AS "Line-num"
    FOR XML PATH(''), TYPE
    ) AS "*"
    FROM cte
    FOR XML PATH('Reference'), ROOT('Source'), TYPE
    ).query('<Cross-reference xmlns="uri:schemas-progress-com:XREFD:0004">{.}</Cross-reference>'), 1, 100
    INSERT INTO XREF.XREF_FileEntry ( XREF_FileEntry )
    VALUES ( 100 )
    INSERT INTO XREF.XREF_MemberBuilt ( XREF_ProjectBuilt, XREF_FileData )
    VALUES ( 69, 1 )
    GO
    --SELECT * FROM XREF.XREF_FileData
    --SELECT * FROM XREF.XREF_FileEntry
    --SELECT * FROM XREF.XREF_MemberBuilt
    --GO
    -- Add primary XML index
    CREATE PRIMARY XML INDEX xidx_XREF_FileData ON XREF.XREF_FileData (DataXref)
    GO
    -- Add value, property and path xml indexes
    CREATE XML INDEX xvalidx_XREF_FileData ON XREF.XREF_FileData (DataXref)
    USING XML INDEX xidx_XREF_FileData FOR VALUE
    CREATE XML INDEX xpthidx_XREF_FileData ON XREF.XREF_FileData (DataXref)
    USING XML INDEX xidx_XREF_FileData FOR PATH
    CREATE XML INDEX xprpidx_XREF_FileData ON XREF.XREF_FileData (DataXref)
    USING XML INDEX xidx_XREF_FileData FOR PROPERTY
    GO
    :exit
    DBCC DROPCLEANBUFFERS
    DBCC FREEPROCCACHE
    GO
    DECLARE @p_ObjectIdentifierForReference varchar(500);
    SET @p_ObjectIdentifierForReference = 'ord/p/ord0616.p';
    ;WITH XMLNAMESPACES ('uri:schemas-progress-com:XREFD:0004' as D)
    SELECT
    XREF_FileDataReference.XREF_FileData AS XrefFileData,
    InnerRowNode.value('/D:Reference[1]/D:File-num[1]', 'int') AS FileNumber,
    InnerRowNode.value('/D:Reference[1]/D:Line-num[1]', 'int') AS LineNumber
    FROM (
    SELECT
    XREF.XREF_FileData.XREF_FileData,
    XREF.XREF_FileData.XREF_FileEntry,
    InnerRow.query('.') AS InnerRowNode
    FROM XREF.XREF_FileData
    OUTER APPLY DataXref.nodes('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]') as T(InnerRow)
    WHERE DataXref.exist('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]') = 1
    ) AS XREF_FileDataReference
    INNER JOIN XREF.XREF_MemberBuilt ON XREF_MemberBuilt.XREF_FileData = XREF_FileDataReference.XREF_FileData
    INNER JOIN XREF.XREF_FileEntry ON XREF_FileEntry.XREF_FileEntry = XREF_FileDataReference.XREF_FileEntry
    WHERE XREF_MemberBuilt.XREF_ProjectBuilt = 69
    OPTION( RECOMPILE, OPTIMIZE FOR (@p_ObjectIdentifierForReference = 'ord/p/ord0616.p') )
    GO
    DBCC DROPCLEANBUFFERS
    DBCC FREEPROCCACHE
    GO
    DECLARE @p_ObjectIdentifierForReference varchar(500);
    SET @p_ObjectIdentifierForReference = 'ord/p/ord0616.p';
    ;WITH XMLNAMESPACES ('uri:schemas-progress-com:XREFD:0004' as D)
    SELECT
    XREF_FileDataReference.XREF_FileData AS XrefFileData,
    InnerRowNode.value('(/D:Reference/D:File-num/text())[1]', 'int') AS FileNumber,
    InnerRowNode.value('(/D:Reference/D:Line-num/text())[1]', 'int') AS LineNumber
    FROM (
    SELECT
    XREF.XREF_FileData.XREF_FileData,
    XREF.XREF_FileData.XREF_FileEntry,
    InnerRow.query('.') AS InnerRowNode
    FROM XREF.XREF_FileData
    OUTER APPLY DataXref.nodes('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]') as T(InnerRow)
    WHERE DataXref.exist('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]') = 1
    ) AS XREF_FileDataReference
    INNER JOIN XREF.XREF_MemberBuilt ON XREF_MemberBuilt.XREF_FileData = XREF_FileDataReference.XREF_FileData
    INNER JOIN XREF.XREF_FileEntry ON XREF_FileEntry.XREF_FileEntry = XREF_FileDataReference.XREF_FileEntry
    WHERE XREF_MemberBuilt.XREF_ProjectBuilt = 69
    OPTION( RECOMPILE, OPTIMIZE FOR (@p_ObjectIdentifierForReference = 'ord/p/ord0616.p') )
    GO
    So I guess I'm saying I cannot reproduce your problem on SQL 2008 R2 or SQL 2012.  Does anything about this repro stand out as different from your situation?
    Looking at your query I would say you might consider the following:
    are you really seeing big differences in query duration?
    pretty much ignore estimated plan costs for xml queries
    consider breaking it up; eg carve off the xml then do the joins?  If poor cardinality estimation is part of the problem this might help
    Understand what PATH, PROPERTY and VALUE are for, then only create the ones you need
    do you really have the range of queries that requires all three?
    this is still a great article on xml indexes:
    http://technet.microsoft.com/en-us/library/ms191497.aspx
    What's performance like with the primary xml index only?
    If performance is that important, consider materialising the columns permanently
    I think the buffer_descriptors stuff is a distraction - mostly your cache is warm right?
    plan forcing could be a last resort
    Selective XML indexes in SQL 2012 onwards are great : )  much less storage required for example but much more specific

  • Pass PL/SQL Record variable to Stored procedure in Java

    Can some one please give me a code snippet for passing a Record Type variable returned by Stored Procedure. Following is the scenario.
    A record type variable REC_VAR is made of three columns of a table as follows
    EmpNo Number, Empname Varchar2(50), Zip_Code Varchar2(5).
    I am populating this variable in Java code and passing it to Stored Procedure.
    Can I referance Record Type variable in a Oracle package from Java code.
    How would I define these variables as per table’s column type and pass to SP in a java program.
    Thanks,

    58838,
    The following entry -- from the Ask Tom Web site may be helpful (assuming you haven't already seen it):
    how to access variable
    If it doesn't help, you can always search the site.
    Good Luck,
    Avi.

  • JDBC truncates plsql varchar2 variable to 4000

    I have recently upgraded classes12.jar and ojdbc14.jar used in our app to 10gR2 versions. However all pl/sql VARCHAR2 variables >4000 characters retrieved via a package are now truncated to 400 characters.
    I am using the database package to generate a query on the fly which I then pass back to the calling java for it to execute.
    The VARCHAR2 variables are PL/SQL varaiables only - nothing is being written to the database (hence the 4000 character limit shouldn't apply)

    Johnny98 wrote:
    I'm trying to pass a JSON string into a stored procedure that has a single VARCHAR2 variable.Usually JSON is output from a stored proc (as part of generating dynamic web content or responding to Ajax calls). Strange to see it being passed as input.. and parsed?
    The error you get is from the Save_JSON() procedure itself. The error stack (that you did not post), will include the call stack, unit code names, and source code line numbers. This will pinpoint just where the exception was raised.
    I asked, "+parsed?+" - as that would explain the error. A bug in parsing text into structured data typically results in a "+ORA-06502: PL/SQL: numeric or value error+".
    Also, the actual exception text you posted says:
    ORA-20001: ORA-06502: PL/SQL: numeric or value error
    And this points to yet another fubar exception handler implementation.
    The exception handler very likely looks as follows:
    exception when OTHERS then
      raise_application_error( -20001, SQLERRM(SQLCODE) );
    end;Pardon my blunt response, but this is idiotic. Exception handlers should NOT change a meaningful exception (like -6502) into a generic catchall error (like -20001). NOT IN ANY LANGUAGE. NOT IN PL/SQL. This is not how robust and well designed software is engineered.

  • FINS Industry XML Query Service"?

    Hi
    I am reading an XML using EAI Read From File - Read EAI Message.
    Now I want to retrieve one particular Property from it.
    Can I pass this hierarchy to "FINS Industry XML Query Service"? If so how?
    (I cant use PRM ANI Utility Service since I have multiple IC Instances in it. )
    Thanks

    The confusion was if the BS needs the input as XML Hier, or will a Siebel msg be fine.
    I converted the siebel msg to XML Heir and it worked fine.
    The req was to retrieve the property from multiple instances, and for me it worked since I needed only the first intance.If you need instances other than first , I think the only resort is scripting.
    Thanks for sharing the blog.

  • Passing Pl/Sql variables into shell variables.

    I have written a file that ftp information from one pc to another in unix.
    All you have to do is supply a user_name/password and machine name to which ftp program will connect to.
    All connection information like user_id,password, machine name are stored in an oracle table FTP_TBL.
    It has the following fields:
    FTP_TBL
    ================
    USER_ID      NOT NULL VARCHAR2(100);
    USR_PASSWD      NOT NULL VARCHAR2(50);
    TO_MACHINE     NOT NULL VARCHAR2(50);
    I have called a pl/sql script in unix shell.
    This script selects all the connection information from FTP_TBL and populates the pl/sql variables with the
    information.
    Now i want the pl/sql variables like V_TO_MACHINE,V_USR_ID,V_USR_PASSWD to be passed on to unix variables
    To_MACHINE, USR_ID AND USR_PASSWD.
    How can i do this?
    ============================================================================================================
    sqlplus -s <<+++ >> $LOG_FILE
    $USER/$PASSWD
    set serverout on SIZE 1000000
    DECLARE
    V_TO_MACHINE VARCHAR2(100);
    V_USR_ID VARCHAR2(50);
    V_USR_PASSWD VARCHAR2(50);
    BEGIN
         BEGIN
              SELECT TO_MACHINE, USER_ID, USR_PASSWD
              INTO V_TO_MACHINE,V_USR_ID,V_USR_PASSWD
              FROM FTP_TBL;
         EXCEPTION
              when others then
              dbms_output.put_line('ERROR|SQLPLUS|'||ERROR||'|'||sqlcode||'|Failed during selecting configuration information.'||sqlerrm );
         END;
    END;
    +++
    #======================== VARIABLES =====================
    TO_MACHINE=$1
    USR_ID=$2
    USR_PASSWD=$3
    #========================== MAIN ========================
    ftp -vnd $TO_MACHINE << ++ 1>>$STA_LOG_FILE 2>&1
    user $USR_ID $USR_PASSWD
    prompt off
    get $OR_DATA_DIR/ASC.STADATA $HOME_DIR/ASC.STADATA
    bye
    ++
    # testing the exit status of FTP
    egrep "Transfer complete" $STA_LOG_FILE >/dev/null
    if [ $? = 0 ]
    then
    echo >> $STA_LOG_FILE
    echo "FTP Successfully Done" >> $STA_LOG_FILE
    else
    echo >> $STA_LOG_FILE
    echo "FTP UnSuccessfull" >> $STA_LOG_FILE
    exit 1
    fi

    Here an example of how to pass variables to the shell script :
    TEST@db102 SQL> select ename, job, dname from emp,dept
      2  where empno = 7902
      3  and emp.deptno = dept.deptno;
    ENAME      JOB       DNAME
    FORD       ANALYST   RESEARCH
    TEST@db102 SQL> exit
    Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
    With the Partitioning, OLAP and Data Mining options
    [ora102 work db102]$ cat disp_var.sh
    set `sqlplus -s test/test << EOF
    set pages 0
    select ename, job, dname from emp,dept
    where empno = 7902
    and emp.deptno = dept.deptno;
    exit
    EOF`
    echo $1 $2 $3
    [ora102 work db102]$ ./disp_var.sh
    FORD ANALYST RESEARCH
    [ora102 work db102]$                                                  

  • Japanese characters alone are not passing correctly (passing like ??? or some unreadable characters) to Adobe application when we create input variable as XML data type. The same solution works fine if we change input variable data type to document type a

    Dear Team,
    Japanese characters alone are not passing correctly (passing like ??? or some unreadable characters) to Adobe application when we create input variable as XML data type. The same solution works fine if we change input variable data type to document type. Could you please do needful. Thank you

    Hello,
    most recent patches for IGS and kernel installed. Now it works.

  • How to bind local variables in complex query in PL/SQL

    Hi
    I have long complex query with local varibales; when I run in Dynamic SQL I get an error. Not sure which is the easiest way to bind local variables.
    L_QUERY := q'[select m.segment1 col1,
          '1' col2,
          '13' col3,
          l.operand col4,
          0 col5,
           'Y' col8,
          'N' col9,
          'N' col10,
       decode(h.name,'09_UKOR_*','EOS Credit','10_UKOR_*','TopUp','11_UKOR_*','Main') col18
    from qp_list_headers_v h,
          qp_list_lines_v l,
          mtl_system_items m
    where h.name in ('09_UKOR_*','10_UKOR_*','11_UKOR_*')
    and h.list_header_id = l.list_header_id
    and m.inventory_item_id = l.product_attr_value
    and m.organization_id  = 84
    UNION all
    SELECT qs.PRODUCT_ATTR_VALUE col1,
           hca.account_number col2,
           decode (su.site_use_code,'BILL_TO','21','SHIP_TO','18') col3,
           0 col4,
           qs.operand col5,
           null col6,
           null col7,
           'N' col8,
           'Y' col9,
           'N' col10,     
    --Local variables
          (case when (trunc(nvl(qq.start_date_active,sysdate)) between l_cur_year_from  and l_cur_year_to) and  
                      ( trunc(nvl(qq.end_date_active,l_cur_year_to)) >= trunc(l_cur_year_to) )  then    'TopUp'
                when (trunc(qq.start_date_active) between l_next_year_from  and l_next_year_to) and  
                      ( trunc(nvl(qq.end_date_active,l_next_year_to)) >= l_next_year_to)  then   'Main'              
                when (trunc(qq.start_date_active) between l_last_year_from  and l_last_year_to) and  
                      ( trunc(nvl(qq.end_date_active,l_last_year_to)) >= l_last_year_to )  then  'EOS Return'
           end )col18,
    --Local variables
           (case   when (trunc(qq.start_date_active) between l_next_year_from  and l_next_year_to) and  
                      ( trunc(nvl(qq.end_date_active,l_next_year_to)) >= l_cur_year_to )  then   'N'
              else
                    'Y'  end ) col21
       FROM qp.qp_list_headers_b qlhb,
            qp.qp_list_headers_tl qlht,
            qp.qp_qualifiers qq,
            qp_modifier_summary_v qs,
            hz_cust_site_uses_all su,
            hz_cust_acct_sites_all  sa,
            hz_cust_accounts hca
    WHERE 1=1
          and qlhb.LIST_TYPE_CODE       = 'DLT'
          and nvl(qlhb.active_flag,'Y') = 'Y'
          and qlhb.list_header_id       = qlht.list_header_id
          AND qq.list_header_id         = qlhb.list_header_id
          and qq.list_type_code         = qlhb.LIST_TYPE_CODE
          and qq.QUALIFIER_CONTEXT      = 'CUSTOMER'
          and qs.list_header_id         = qlhb.list_header_id
          and qs.LIST_LINE_TYPE_CODE    = 'DIS'
          and su.site_use_id            = qq.qualifier_attr_value --1064
          AND  su.cust_acct_site_id     = sa.cust_acct_site_id
          AND  sa.cust_account_id       = hca.cust_account_id ]';
    --call Dynamic SQL function
    l_cursor := DBMS_SQL.OPEN_CURSOR;
    DBMS_SQL.PARSE(l_cursor, p_QUERY , DBMS_SQL.NATIVE);
    l_rows := DBMS_SQL.EXECUTE(l_cursor);
    Any help will be much appreciated.
    iI guess I should use DBMS_SQL.BIND_VARIABLE to bind all variables seperately so not to mess with query

    1) What is the error you get?
    2) If you use bind variables inside a query, you should prefix them with colons, so use :l_cur_year_from etc.
    3) Why are you using dbms_sql instead of native dynamic sql and/or ref-cursors?
    Toon

  • How to tune the performance of Oracle SQL/XML query?

    Hi all,
    I am running Oracle 9i and like to run the following Oracle SQL/XML query. It takes about 3+ hour and still not finish. If I get rid all the XML stuffs it only take minutes to run. Does anybody know how to what's the reason of this slow and how to tune it?
    SELECT XMLElement("CUSTOMER",
    XMLForest(C_CUSTKEY "C_CUSTKEY", C_NAME "C_NAME", C_ADDRESS "C_ADDRESS", C_PHONE "C_PHONE", C_MKTSEGMENT "C_MKTSEGMENT", C_COMMENT "C_COMMENT"),
    (SELECT XMLAgg(XMLElement("ORDERS",
    XMLForest(O_ORDERKEY "O_ORDERKEY", O_CUSTKEY "O_CUSTKEY", O_ORDERSTATUS "O_ORDERSTATUS", O_ORDERPRIORITY "O_ORDERPRIORITY", O_CLERK "O_CLERK", O_COMMENT "O_COMMENT"),
    (SELECT XMLAgg(XMLElement("LINEITEM",
    XMLForest(L_ORDERKEY "L_ORDERKEY", L_RETURNFLAG "L_RETURNFLAG", L_LINESTATUS "L_LINESTATUS", L_SHIPINSTRUCT "L_SHIPINSTRUCT", L_SHIPMODE "L_SHIPMODE", L_COMMENT "L_COMMENT")
    FROM LINEITEM
    WHERE LINEITEM.L_ORDERKEY = ORDERS.O_ORDERKEY)
    FROM ORDERS
    WHERE ORDERS.O_CUSTKEY = CUSTOMER.C_CUSTKEY)
    FROM CUSTOMER ;
    Thanks very much in advance for your time,
    Jinghao Liu

    ajallen wrote:
    Why not something more like
    SELECT *
    FROM fact1 l,
    FULL OUTER JOIN fact1 d
    ON l.company = d.company
    AND l.transactiontypeid = 1
    AND d.transactiontypeid = 2;
    Because this is not an equivalent of the original query.
    drop table t1 cascade constraints purge;
    drop table t2 cascade constraints purge;
    create table t1 as select rownum t1_id from dual connect by level <= 5;
    create table t2 as select rownum+2 t2_id from dual connect by level <= 5;
    select * from (select * from t1 where t1_id > 2) t1 full outer join t2 on (t1_id = t2_id);
    select * from t1 full outer join t2 on (t1_id = t2_id and t1_id > 2);
         T1_ID      T2_ID
             3          3
             4          4
             5          5
                        6
                        7
         T1_ID      T2_ID
             1
             2
             3          3
             4          4
             5          5
                        6
                        7

  • How to perf tune Oracle SQL/XML query?

    Hi all,
    I am using Oracle 9i and like to run the following Oracle SQL/XML query. It takes about 3+ hour and still not finish. If I get rid all the XML stuffs it only take minutes to run. Does anybody know how to what's the reason of this slow and how to tune it?
    SELECT XMLElement("CUSTOMER",
    XMLForest(C_CUSTKEY "C_CUSTKEY", C_NAME "C_NAME", C_ADDRESS "C_ADDRESS", C_PHONE "C_PHONE", C_MKTSEGMENT "C_MKTSEGMENT", C_COMMENT "C_COMMENT"),
    (SELECT XMLAgg(XMLElement("ORDERS",
    XMLForest(O_ORDERKEY "O_ORDERKEY", O_CUSTKEY "O_CUSTKEY", O_ORDERSTATUS "O_ORDERSTATUS", O_ORDERPRIORITY "O_ORDERPRIORITY", O_CLERK "O_CLERK", O_COMMENT "O_COMMENT"),
    (SELECT XMLAgg(XMLElement("LINEITEM",
    XMLForest(L_ORDERKEY "L_ORDERKEY", L_RETURNFLAG "L_RETURNFLAG", L_LINESTATUS "L_LINESTATUS", L_SHIPINSTRUCT "L_SHIPINSTRUCT", L_SHIPMODE "L_SHIPMODE", L_COMMENT "L_COMMENT")
    FROM LINEITEM
    WHERE LINEITEM.L_ORDERKEY = ORDERS.O_ORDERKEY)
    FROM ORDERS
    WHERE ORDERS.O_CUSTKEY = CUSTOMER.C_CUSTKEY)
    FROM CUSTOMER ;
    Thanks very much in advance for your time,
    Jinghao Liu

    Please post this message at:
    Forums Home » Oracle Technology Network (OTN) » Products » Database » XML DB

  • HOWTO: Writing Out XML Query Results of Any Size in Java with XML SQL Utility

    A customer mailed me asking for an example of how to use our XML SQL Utility to write out query results for tons of query result rows.
    With tons of data, the getXMLDOM() and getXMLString() methods are not really appropriate due to the size.
    The XML SQL Utility offers a getXMLSAX() method that streams SAX2 events to report the data being queried. This is the approach we can use to handle data of any size.
    It dawned on me today that by putting together the XML SQL Utilities getXMLSAX() routine, and the oracle.xml.parser.v2.XSLSAXPrintDriver SAX2 ContentHandler, we can effectively stream out data of any length to an appropriate writer.
    Here's a code example to get the point across:
    package test;
    import java.io.BufferedOutputStream;
    import java.io.PrintWriter;
    import java.sql.Connection;
    import java.sql.Driver;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.Properties;
    import javax.xml.transform.OutputKeys;
    import oracle.jdbc.OracleDriver;
    import oracle.xml.parser.v2.XSLException;
    import oracle.xml.parser.v2.XSLOutput;
    import oracle.xml.parser.v2.XSLSAXPrintDriver;
    import oracle.xml.sql.query.OracleXMLQuery;
    public class Example  {
      private static final String QUERY = "select * from emp";
      public static void main(String[] args) throws Throwable  {
          Connection conn = getConnection();
          OracleXMLQuery q = new OracleXMLQuery(getConnection(),QUERY);
          // Any printwriter will do. Here's we're output to standard out.
          PrintWriter output = new PrintWriter(new BufferedOutputStream(System.out));
          // This is a SAX2 Content Handler used by the Oracle XSLT Engine
          // to serialize a stream of sax2 events as an XML document
          // We'll use it to serialize the sax2 events from the XML SQL Utility
          // out as an XML document.
          XSLSAXPrintDriver ch = new XSLSAXPrintDriver(output, outputOptions());  
          // This asks XML SQL Utility to fire sax events for the data
          // being fetched instead of creating DOM nodes or returning text.
          // By using the XSLSAXPrintDriver content handler, these events
          // get handled by writing them directly to the output stream
          q.getXMLSAX(ch);
          ch.flush();
          q.close();
          conn.close();     
      private static XSLOutput outputOptions() throws XSLException {
        XSLOutput x = new XSLOutput();
        Properties props = new Properties();
        props.put(OutputKeys.METHOD,"xml");
        props.put(OutputKeys.INDENT,"yes");  // Set to "no" for non-indented
        x.setProps(props);
        return x;
      public static Connection getConnection() throws SQLException {
        String username = "scott";
        String password = "tiger";
        String thinConn = "jdbc:oracle:thin:@localhost:1521:ORCL";
        Driver d = new OracleDriver();
        return DriverManager.getConnection(thinConn,username,password);
    }

    Hi Uber,
    This is a known issue that error occurs when running report "Count of instances of specific software registered with Add or Remove Programs" due to non-printable characters for XML. Based on internal research, the hotfix for this issue will be
    included in the System Center 2012 Configuration Manager Service Pack 1.
    As a workaround, you can remove the nonprintable character populated into the report parameter by referring to the following KB article:
    http://support.microsoft.com/KB/914159
    Hope this helps.
    Regards,
    Mike Yin
    Mike Yin
    TechNet Community Support

  • Passing file location as URL parameter for xml query

    Hi all,
    A quick question regarding using a parameter to set the source URL in an XML query template.
    When assigning the URL, the static text works perfectly eg:
    //<servername>/<folder>/samplefile.xml . The xml is returned as required.
    However, we wish to call this from a BLS txn and set the source URL dynamically.
    To test this we assigned //<servername>/<folder>/samplefile.xml to Parameter no 1 and insert [Param.1] in the source URL field. No luck.
    Any suggestions?
    Cheers
    Mark

    Mark,
    In BLS, the double slashes (escaping the single /) are only necessary if you are building the full http url string in the link editor.
    If your XMLQuery template is something like http://localhost/Folder/Subfolder/[Param.1] then put in a default param value in the query template and make sure the query test works.  Then configure (or reconfigure) this in your BLS transaction and generate the sample results.  All you should have to do in BLS then is to assign your Transaction or Local property to the Param.1 link in your XMLQuery action block.  All of the dynamic replacement and subsequent xml file retrieval should then be done by the XMLQuery itself.
    If you can keep the majority of the URL in the XMLQuery itself and then just dynamically pass it the Param.1 piece it will be very easy to test and configure (also use localhost if the file lives on the xMII web server), but if you have to build the string external in BLS I would recommend using a combination of the expression editor and a Local property.  If the Local string property contains the base of http://localhost/Folder/Subfolder/ (no quotes or character escaping needed for the default value of a string property) then just assign something like the following to your Param.1 property of the XMLQuery:  Local.URLBase & "filename.xml" (a simple evaluate will confirm your efforts).
    Regards,
    Jeremy

  • Passing entire SQL query to BIP server from Forms

    Hi
    I want to pass the entire SQL statement or only a WHERE clause dynamically constructed on Forms side to BI Publisher server at runtime.
    I have come across this article:
    http://blogs.oracle.com/BIDeveloper/2009/12/dynamic_sql_query_in_data_template.html
    It mentions about using pwhereclause which could be constructed dynamically.
    Is it possible to pass the entire SELECT statement and has anyone done this before? May I have some tips on this?
    Thanks and kind regards,
    Aparna

    My requirement is as follows:
    1) I have a customised application which contains the definition of the report (report id, report name, the screen id on which the report is to appear as a record in the list and so on). This is where I would like to record the SQL statement which will be used to retrieve data for the report.
    2) Once I launch the report from my application, it will pass SQL statement and other data (template, format, output file name, path where the output file will be saved, URL from which the output file will be launched after saving).
    Thus, on BI Publisher server side, I shall only create a report, and will create a data template that will reference the SQL query that has been passed from application. I don't want to even specify parameters in Bi Publisher and want to specify them only in the application.
    Is this possible?
    Currently, I'm using a web service called 'PublicReportService' of BI Publisher to pass template, format, output file name, report path etc.). However, I am not sure how to pass an SQL query from Oracle Forms via this web service to BI Publisher.
    Can someone please guide me?
    Thanks and kind regards,
    Aparna

  • How to invoke PL/SQL Table parameter in the query string?

    Hello,
    I've met a problem invoking PL/SQL Table parameter in the query string, in OWS 3.0.
    What I'm going to do is, to invoke a stored procedure to generate a web page using PL/SQL Web Toolkit 2.0, like: "http://.../owa/test_proc".
    But there is a IN parameter for this procedure, and it's a PL/SQL Table variable. So I can't invoke the procedure sucessfully just using "http://.../owa/test_proc?v_plsql=i_plsql".
    Did someone have met this kind of problem or have the answer to it? Thanks so much for your help.

    When using procedures with pl/sql-tables as parameter they should be overloaded, e.g.:
    procedure my_procedure (my_var in varchar2)...
    and
    procedure my_procedure (my_var in owa_util.ident_arr)
    the procedure then can be called with:
    http://..../my_procedure?my_var=Scott, which invokes the version with the varchar2 parameter, or
    http://..../my_procedure?my_var=Scott&my_var=Miller......
    which invokes the version with the pl/sql-Table
    Another solution might be the use of flexible parameters, passing pairs of parameter_name, parameter_value to your procedure. Your procedure looks like:
    procedure my_procedure (name_array IN owa.vc_arr, value_array IN owa.vc_arr)..
    and is invoked (note the ! )
    http://..../!my_procedure?ename=Scott&sal=200&job=clerk.....
    looping through the pl/sql tables will retrieve values of ename, sal and job for name_array and Scott, 200 and clerk for value_array
    Hth
    null

  • Cooresponding Lists Names/Values XML Query

    Let's say there is an XML Schema that has
    <element name="mt" minOccurs="0" maxOccurs="unbounded">
    <element name="r" minOccurs="0" maxOccurs="unbounded">
    And for each measurement type (mt), you have a cooresponding measurement value (r). There are additional elements between these two lists. The actual XML data would look similiar to
    <mi>
         <mts>20061117100000-0800</mts>
         <gp>900</gp>
         <mt>MeasurementType1</mt>
         <mt>MeasurementType2</mt>
         <mt>MeasurementType3</mt>
         <mt>MeasurementType4</mt>
         <mt>MeasurementType5</mt>
         <mt>MeasurementType6</mt>
         <mt>MeasurementType7</mt>
         <mv>
              <moid>Identifier</moid>
              <r>58</r>
              <r>62</r>
              <r>43</r>
              <r>45</r>
              <r>43</r>
              <r>14</r>
              <r>29</r>
              <sf>FALSE</sf>
         </mv>
    </mi>
    The first occurance of mt corresponds to the first occurance of r, the second cooresponds to the second, et cetra.
    The MI element can repeat hundreds of times and there can be many measurementTypes. Now, I'm trying to figure out how I can create an XML query to efficiently handle this. The problem is that the <r> value is within the complexType <mv> and that is on the same level as <mt>. The XML Query would cause a cartesian product if I were to use something like ...
    select
    extractValue(value(xmldata), '/mi/mts') measurement_time_stamp,
    extractValue(value(xmldata), '/mi/gp') granularity_period,
    extractValue(value(mt), '/mt') measurement_type,
    extractValue(value(mv), '/mv/moid') measured_obj_id,
    extractValue(value(r), '/r') measurement_value,
    from xmltable
    , TABLE(XMLSequence(Extract(value(xmltable), '/mi/mv'))) mv
    , TABLE(XMLSequence(Extract(value(mi), '/mi/mt'))) mt
    , TABLE(XMLSequence(Extract(value(mi), '/mv/r'))) r
    This obviously wouldn't work. I could go and store all the types and values into a column using
    select
    replace(replace(replace(extract(value(mi), '/mi/mt').getStringVal(), '</mt><mt>', ';'), '<mt>'), '</mt>') measurement_type,
    extractValue(value(mv), '/mv/moid') measured_obj_id,
    replace(replace(replace(extract(value(mv), '/mv/r').getStringVal(), '</r><r>', ';'), '<r>'), '</r>') measurement_value
    from xmltable
    TABLE(XMLSequence(Extract(value(xmldata), '/md/mi'))) mi
    , TABLE(XMLSequence(Extract(value(mi), '/mi/mv'))) mv
    But this wouldn't work once the XML grew over 4000 bytes. So I need a way to extract this data maintaining the correct integrity (avoiding cartesians).
    One idea is a pipelined table function but I have concerns about scalability with that method. Is there a way to accomplish this optimally? I have solutions for this but none of them is going to deliver the scalability I am seeking.
    I expect the method chosen will probably need to handle a few hundred thousand files per day.
    Thanks,

    VJ
    I'd not seen your XML schema when I worked the original example, so I reverse engineered it from the instance. Unfortunately when I work with your schema, which contains more levels of nested I can't get it to optimize properly
    Here's what should work in theory
    SQL> set echo on
    SQL> spool testcase.log
    SQL> --
    SQL> connect sys/ as sysdba
    Enter password:
    Connected.
    SQL> set define on
    SQL> --
    SQL> define USERNAME = OTNTEST
    SQL> --
    SQL> def PASSWORD = OTNTEST
    SQL> --
    SQL> def USER_TABLESPACE = USERS
    SQL> --
    SQL> def TEMP_TABLESPACE = TEMP
    SQL> --
    SQL> def LOCAL_FILESYSTEM = 'C:\xdb\otn\457595'
    SQL> --
    SQL> drop user &USERNAME cascade
      2  /
    old   1: drop user &USERNAME cascade
    new   1: drop user OTNTEST cascade
    User dropped.
    SQL> grant connect, resource to &USERNAME identified by &PASSWORD
      2  /
    old   1: grant connect, resource to &USERNAME identified by &PASSWORD
    new   1: grant connect, resource to OTNTEST identified by OTNTEST
    Grant succeeded.
    SQL> grant create any directory, drop any directory to &USERNAME
      2  /
    old   1: grant create any directory, drop any directory to &USERNAME
    new   1: grant create any directory, drop any directory to OTNTEST
    Grant succeeded.
    SQL> grant alter session, create view to &USERNAME
      2  /
    old   1: grant alter session, create view to &USERNAME
    new   1: grant alter session, create view to OTNTEST
    Grant succeeded.
    SQL> alter user &USERNAME default tablespace &USER_TABLESPACE temporary tablespace &TEMP_TABLESPACE
      2  /
    old   1: alter user &USERNAME default tablespace &USER_TABLESPACE temporary tablespace &TEMP_TABLESPACE
    new   1: alter user OTNTEST default tablespace USERS temporary tablespace TEMP
    User altered.
    SQL> connect &USERNAME/&PASSWORD
    Connected.
    SQL> --
    SQL> alter session set events ='19027 trace name context forever, level 0x800'
      2  /
    Session altered.
    SQL> var schemaURL varchar2(256)
    SQL> var schemaPath varchar2(256)
    SQL> --
    SQL> create or replace directory XMLDIR as '&LOCAL_FILESYSTEM'
      2  /
    old   1: create or replace directory XMLDIR as '&LOCAL_FILESYSTEM'
    new   1: create or replace directory XMLDIR as 'C:\xdb\otn\457595'
    Directory created.
    SQL> begin
      2    :schemaURL := 'testcase.xsd';
      3    :schemaPath := '/public/testcase.xsd';
      4  end;
      5  /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> declare
      2    res boolean;
      3    xmlSchema xmlType := xmlType(
      4  '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
      5  <!--W3C Schema generated by XMLSpy v2007 (http://www.altova.com)-->
      6  <!--Please add namespace attributes, a targetNamespace attribute and import elements according to your requirements-->
      7  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xdb="http://xmlns.oracle.com/xdb" elementFormDefault="qualified" attributeFormDefaul
    t="unqualified" xdb:storeVarrayAsTable="true">
      8     <xs:import namespace="http://www.w3.org/XML/1998/namespace"/>
      9     <xs:element name="mdc" xdb:defaultTable="MDC_TABLE">
    10             <xs:complexType xdb:SQLType="MDC_TYPE" xdb:maintainDOM="false">
    11                     <xs:sequence>
    12                             <xs:element ref="mfh"/>
    13                             <xs:element ref="md" minOccurs="0" maxOccurs="unbounded"/>
    14                             <xs:element ref="mff"/>
    15                     </xs:sequence>
    16             </xs:complexType>
    17     </xs:element>
    18     <xs:element name="mfh" xdb:defaultTable="">
    19             <xs:complexType xdb:SQLType="MFH_TYPE" xdb:maintainDOM="false">
    20                     <xs:sequence>
    21                             <xs:element ref="ffv"/>
    22                             <xs:element ref="sn"/>
    23                             <xs:element ref="st"/>
    24                             <xs:element ref="vn"/>
    25                             <xs:element ref="cbt"/>
    26                     </xs:sequence>
    27             </xs:complexType>
    28     </xs:element>
    29     <xs:element name="md" xdb:defaultTable="" >
    30             <xs:complexType  xdb:SQLType="MD_TYPE" xdb:maintainDOM="false">
    31                     <xs:sequence>
    32                             <xs:element ref="neid"/>
    33                             <xs:element ref="mi" minOccurs="0" maxOccurs="unbounded" />
    34                     </xs:sequence>
    35             </xs:complexType>
    36     </xs:element>
    37     <xs:element name="neid" xdb:defaultTable="" >
    38             <xs:complexType xdb:SQLType="NEID_TYPE" xdb:maintainDOM="false">
    39                     <xs:sequence>
    40                             <xs:element ref="neun"/>
    41                             <xs:element ref="nedn"/>
    42                     </xs:sequence>
    43             </xs:complexType>
    44     </xs:element>
    45     <xs:element name="mi" xdb:defaultTable="" >
    46             <xs:complexType xdb:SQLType="MI_TYPE" xdb:maintainDOM="false">
    47                     <xs:sequence>
    48                             <xs:element ref="mts"/>
    49                             <xs:element ref="gp"/>
    50                             <xs:element ref="mt" minOccurs="0" maxOccurs="unbounded"/>
    51                             <xs:element ref="mv" minOccurs="0" maxOccurs="unbounded" />
    52                     </xs:sequence>
    53             </xs:complexType>
    54     </xs:element>
    55     <xs:element name="mv" xdb:defaultTable="" >
    56             <xs:complexType xdb:SQLType="MV_TYPE" xdb:maintainDOM="false">
    57                     <xs:sequence>
    58                             <xs:element ref="moid"/>
    59                             <xs:element ref="r" minOccurs="0" maxOccurs="unbounded"/>
    60                             <xs:element ref="sf" minOccurs="0"/>
    61                     </xs:sequence>
    62             </xs:complexType>
    63     </xs:element>
    64     <xs:element name="mff" xdb:defaultTable="" >
    65             <xs:complexType xdb:maintainDOM="false">
    66                     <xs:sequence>
    67                             <xs:element ref="ts"/>
    68                     </xs:sequence>
    69             </xs:complexType>
    70     </xs:element>
    71     <xs:element name="ts" type="xs:string"/>
    72     <xs:element name="sf" type="xs:string"/>
    73     <xs:element name="r">
    74             <xs:complexType xdb:SQLType="R_TYTPE" xdb:maintainDOM="false">
    75                     <xs:simpleContent>
    76                             <xs:extension base="xs:string">
    77                                     <xs:attribute ref="dummy" use="prohibited"/>
    78                             </xs:extension>
    79                     </xs:simpleContent>
    80             </xs:complexType>
    81     </xs:element>
    82     <xs:attribute name="dummy" type="xs:boolean"/>
    83     <xs:element name="mt">
    84             <xs:complexType xdb:SQLType="MT_TYTPE" xdb:maintainDOM="false">
    85                     <xs:simpleContent>
    86                             <xs:extension base="xs:string">
    87                                     <xs:attribute ref="dummy" use="prohibited"/>
    88                             </xs:extension>
    89                     </xs:simpleContent>
    90             </xs:complexType>
    91     </xs:element>
    92     <xs:element name="moid" type="xs:string"/>
    93     <xs:element name="gp" type="xs:string"/>
    94     <xs:element name="mts" type="xs:string"/>
    95     <xs:element name="nedn" type="xs:string"/>
    96     <xs:element name="neun" type="xs:string"/>
    97     <xs:element name="cbt" type="xs:string"/>
    98     <xs:element name="vn" type="xs:string"/>
    99     <xs:element name="st" type="xs:string"/>
    100     <xs:element name="sn" type="xs:string"/>
    101     <xs:element name="ffv" type="xs:string"/>
    102  </xs:schema>');
    103  begin
    104    if (dbms_xdb.existsResource(:schemaPath)) then
    105      dbms_xdb.deleteResource(:schemaPath);
    106    end if;
    107    res := dbms_xdb.createResource(:schemaPath,xmlSchema);
    108  end;
    109  /
    PL/SQL procedure successfully completed.
    SQL> begin
      2    dbms_xmlschema.registerSchema
      3    (
      4      :schemaURL,
      5      xdbURIType(:schemaPath).getClob(),
      6      TRUE,TRUE,FALSE,TRUE
      7    );
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    SQL> declare
      2    nested_table_name varchar2(256);
      3    iot_index_name varchar2(256);
      4  begin
      5    select table_name
      6      into nested_table_name
      7      from user_nested_tables
      8     where parent_table_column = '"XMLDATA"."md"'
      9       and parent_table_name = 'MDC_TABLE';
    10
    11    execute immediate 'rename "'|| nested_table_name ||'" to MD_TABLE';
    12
    13    select index_name
    14      into iot_index_name
    15      from user_indexes
    16     where table_name = 'MD_TABLE' and index_type = 'IOT - TOP';
    17
    18    execute immediate 'alter index "'|| iot_index_name ||'" rename to MD_IOT';
    19
    20    select table_name
    21      into nested_table_name
    22      from user_nested_tables
    23     where parent_table_column = 'mi'
    24       and parent_table_name = 'MD_TABLE';
    25
    26    execute immediate 'rename "'|| nested_table_name ||'" to MI_TABLE';
    27
    28    select index_name
    29      into iot_index_name
    30      from user_indexes
    31     where table_name = 'MI_TABLE' and index_type = 'IOT - TOP';
    32
    33    execute immediate 'alter index "'|| iot_index_name ||'" rename to MI_IOT';
    34
    35    select table_name
    36      into nested_table_name
    37      from user_nested_tables
    38     where parent_table_column = 'mt'
    39       and parent_table_name = 'MI_TABLE';
    40
    41    execute immediate 'rename "'|| nested_table_name ||'" to MT_TABLE';
    42
    43    select index_name
    44      into iot_index_name
    45      from user_indexes
    46     where table_name = 'MT_TABLE' and index_type = 'IOT - TOP';
    47
    48    execute immediate 'alter index "'|| iot_index_name ||'" rename to MT_IOT';
    49
    50    select table_name
    51      into nested_table_name
    52      from user_nested_tables
    53     where parent_table_column = 'mv'
    54       and parent_table_name = 'MI_TABLE';
    55
    56    execute immediate 'rename "'|| nested_table_name ||'" to MV_TABLE';
    57
    58    select index_name
    59      into iot_index_name
    60      from user_indexes
    61     where table_name = 'MV_TABLE' and index_type = 'IOT - TOP';
    62
    63    execute immediate 'alter index "'|| iot_index_name ||'" rename to MV_IOT';
    64
    65    select table_name
    66      into nested_table_name
    67      from user_nested_tables
    68     where parent_table_column = 'r'
    69       and parent_table_name = 'MV_TABLE';
    70
    71    execute immediate 'rename "'|| nested_table_name ||'" to R_TABLE';
    72
    73    select index_name
    74      into iot_index_name
    75      from user_indexes
    76     where table_name = 'R_TABLE' and index_type = 'IOT - TOP';
    77
    78    execute immediate 'alter index "'|| iot_index_name ||'" rename to R_IOT';
    79  end;
    80  /
    PL/SQL procedure successfully completed.
    SQL> desc MDC_TABLE
    Name                                                                                Null?    Type
    TABLE of SYS.XMLTYPE(XMLSchema "testcase.xsd" Element "mdc") STORAGE Object-relational TYPE "MDC_TYPE"
    SQL> --
    SQL> desc MD_TABLE
    Name                                                                                Null?    Type
    neid                                                                                         NEID_TYPE
    mi                                                                                           mi9495_COLL
    SQL> --
    SQL> desc MI_TABLE
    Name                                                                                Null?    Type
    mts                                                                                          VARCHAR2(4000 CHAR)
    gp                                                                                           VARCHAR2(4000 CHAR)
    mt                                                                                           mt9493_COLL
    mv                                                                                           mv9494_COLL
    SQL> --
    SQL> desc MT_TABLE
    Name                                                                                Null?    Type
    SYS_XDBBODY$                                                                                 VARCHAR2(4000 CHAR)
    dummy                                                                                        RAW(1)
    SQL> --
    SQL> desc MV_TABLE
    Name                                                                                Null?    Type
    moid                                                                                         VARCHAR2(4000 CHAR)
    r                                                                                            r9492_COLL
    sf                                                                                           VARCHAR2(4000 CHAR)
    SQL> --
    SQL> desc R_TABLE
    Name                                                                                Null?    Type
    SYS_XDBBODY$                                                                                 VARCHAR2(4000 CHAR)
    dummy                                                                                        RAW(1)
    SQL> --
    SQL> set autotrace on explain
    SQL> set lines 150 pages 100
    SQL> --
    SQL> var XMLTEXT varchar2(4000)
    SQL> --
    SQL> begin
      2    :xmlText :=
      3  '<mdc>
      4     <mfh>
      5             <ffv/>
      6             <sn/>
      7             <st/>
      8             <vn/>
      9             <cbt/>
    10     </mfh>
    11     <md>
    12             <neid>
    13                     <neun/>
    14                     <nedn/>
    15             </neid>
    16             <mi>
    17                     <mts>20061117100000-0800</mts>
    18                     <gp>900</gp>
    19                     <mt>MeasurementType1</mt>
    20                     <mt>MeasurementType2</mt>
    21                     <mt>MeasurementType3</mt>
    22                     <mt>MeasurementType4</mt>
    23                     <mt>MeasurementType5</mt>
    24                     <mt>MeasurementType6</mt>
    25                     <mt>MeasurementType7</mt>
    26                     <mv>
    27                             <moid>Identifier</moid>
    28                             <r>58</r>
    29                             <r>62</r>
    30                             <r>43</r>
    31                             <r>45</r>
    32                             <r>43</r>
    33                             <r>14</r>
    34                             <r>29</r>
    35                             <sf>FALSE</sf>
    36                     </mv>
    37             </mi>
    38     </md>
    39     <mff>
    40             <ts/>
    41     </mff>
    42  </mdc>';
    43  end;
    44  /
    PL/SQL procedure successfully completed.
    SQL> insert into MDC_TABLE values ( xmltype ( :xmltext ))
      2  /
    1 row created.
    Execution Plan
    Plan hash value: 1621636734
    | Id  | Operation                | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | INSERT STATEMENT         |           |     1 |   100 |     1   (0)| 00:00:01 |
    |   1 |  LOAD TABLE CONVENTIONAL | MDC_TABLE |       |       |            |          |
    SQL> commit
      2  /
    Commit complete.
    SQL> select MT_INDEX, MT_VALUE, R_VALUE
      2    from MDC_TABLE,
      3         xmlTable
      4         (
      5           '/mdc/md/mi'
      6           passing object_value
      7           columns
      8           XML xmltype path '.'
      9         ) MI,
    10         xmlTable
    11         (
    12           '/mi/mt'
    13           passing MI.XML
    14           columns
    15           MT_INDEX for ordinality,
    16           MT_VALUE varchar2(32) path 'text()'
    17         ) MT,
    18         xmlTable
    19         (
    20           '/mi/mv/r'
    21           passing MI.XML
    22           columns
    23           R_INDEX for ordinality,
    24           R_VALUE varchar2(32) path 'text()'
    25         ) R
    26   where MT_INDEX = R_INDEX
    27  /
      MT_INDEX MT_VALUE                         R_VALUE
             1 MeasurementType1                 58
             2 MeasurementType2                 62
             3 MeasurementType3                 43
             4 MeasurementType4                 45
             5 MeasurementType5                 43
             6 MeasurementType6                 14
             7 MeasurementType7                 29
    7 rows selected.
    Execution Plan
    Plan hash value: 2832518671
    | Id  | Operation                             | Name                   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                      |                        |  5449M|    19T|  1616M  (1)|999:59:59 |
    |   1 |  NESTED LOOPS                         |                        |  5449M|    19T|  1616M  (1)|999:59:59 |
    |   2 |   NESTED LOOPS                        |                        |    66M|   237G|   197K  (1)| 00:39:36 |
    |   3 |    NESTED LOOPS                       |                        |  8168 |    29M|    27   (0)| 00:00:01 |
    |*  4 |     TABLE ACCESS FULL                 | MDC_TABLE              |     1 |  3788 |     3   (0)| 00:00:01 |
    |   5 |     COLLECTION ITERATOR PICKLER FETCH | XMLSEQUENCEFROMXMLTYPE |       |       |            |          |
    |   6 |    VIEW                               |                        |  8168 |   247K|    24   (0)| 00:00:01 |
    |   7 |     COUNT                             |                        |       |       |            |          |
    |   8 |      COLLECTION ITERATOR PICKLER FETCH| XMLSEQUENCEFROMXMLTYPE |       |       |            |          |
    |*  9 |   VIEW                                |                        |    82 |  2542 |    24   (0)| 00:00:01 |
    |  10 |    COUNT                              |                        |       |       |            |          |
    |  11 |     COLLECTION ITERATOR PICKLER FETCH | XMLSEQUENCEFROMXMLTYPE |       |       |            |          |
    Predicate Information (identified by operation id):
       4 - filter(SYS_CHECKACL("ACLOID","OWNERID",xmltype('<privilege
                  xmlns="http://xmlns.oracle.com/xdb/acl.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://xmlns.oracle.com/xdb/acl.xsd http://xmlns.oracle.com/xdb/acl.xsd
                  DAV:http://xmlns.oracle.com/xdb/dav.xsd"><read-properties/><read-contents/></privilege>'))=1)
       9 - filter("MT_INDEX"="R_INDEX")
    Note
       - dynamic sampling used for this statement
    SQL>As you can see the re-write is not working out in this case. I'll ask development to take a look at it and see if they can solve it. I think it's similar to another bug I've filed...
    WRT to your question about transforming. One easy transformation would be to number the nodes.. Eg use XSTL to add an index number to each MT node and each R node and then join on that value.

Maybe you are looking for

  • Changing iTunes account on iphone

    I purchased a used iphone and did a restore to factory settings but when I still connect to the app store it brings up the previous owner's email address. I put the correct account in iTunes on the computer and synced. New apps were added on the sync

  • How do I revert to an older IE 10 build?

    A user is asking me to revert his IE 10 to 10.0.9200.16750, would there be a way to do that? i.e by uninstalling some updates or even better as I already tried to remove IE 10 completely to install an older build I found, to then apply updates up to

  • MDP to HDMI - how?

    MiniDisplayPort-Hdmi-adapters are female, aswell as the Hdmi-In at my TV. How does that work? Can I use a male-male-cable? Thank you for solving my (probably easy) problem.

  • Can an iphone with a case fit in the michael kors wallet clutch?

    can an iphone with a case fit in the michael kors wallet clutch? I was thinking of getting it but I do not want to take my pittsburgh penguins case off just so it can fit inside of it.

  • Cash sales and rush order --immediate delivery problem

    Hi all, Need some help! Well this is a very basic questions and could not get answers quite well from anywhere. In CASH SALES & RUSH ORDER ...i am not getting "immediate delivery" during saving. This is happening to me for the first time ...........