SUM on XMLTable Column Causes Parallel Query to Not Work

I have the following query that creates an XMLTable out of an xml document and is then used to aggregate data from the document.
My problem is that when I try to SUM the XMLTable return column I am unable to use Parallel processing, yet when I remove the SUM from the return column Parallel processing works as expected. Can anyone shed some light on what the problem may be?
One note: I am applying a larger query than the following to hundreds of millions of records so parallel processing is definitely desired/needed.
The Query:
SELECT     /*+ full(n) parallel(n,8) */
     x451s30 as "XYZ"
     --SUM(x451s30) as "XYZ"
FROM NADS n,
     metas met,
     XMLTable(XMLNAMESPACES('http://fbi.gov/cjis/N-DEx' as "p1"),
          '/*' PASSING n.DATA_INTERNAL
          COLUMNS
               x451s30 NUMBER PATH 'count(/p1:DataItem/Person[Role = "Arrest Subject"]/Name/LastName)') T7
WHERE STATUS_ID=1
AND NAT_SOURCE_ID=0
AND OWNING_ORI like 'ABC123'
and n.id=met.nads_id and met.type_id=1 and met.val='Arrest Report';
Explain Plan without SUM
PLAN_TABLE_OUTPUT
Plan hash value: 2296199318
| Id | Operation               | Name               | Rows | Bytes | Cost (%CPU)| Time     | Pstart| Pstop | TQ |IN-OUT| PQ Distrib |
| 0 | SELECT STATEMENT          |               | 1 | 130 | 3713 (0)| 00:00:45 |     |     |     |     |     |
| 1 | SORT AGGREGATE           |               | 1 | 2 |     |      |     |     |     |     |     |
| 2 | XPATH EVALUATION          |               |     |     |     |      |     |     |     |     |     |
| 3 | PX COORDINATOR           |               |     |     |     |      |     |     |     |     |     |
| 4 | PX SEND QC (RANDOM)          | :TQ10000          | 1 | 130 | 3713 (0)| 00:00:45 |     |     | Q1,00 | P->S | QC (RAND) |
| 5 | NESTED LOOPS           |               | 1 | 130 | 3713 (0)| 00:00:45 |     |     | Q1,00 | PCWP |     |
| 6 | NESTED LOOPS          |               | 1 | 128 | 3683 (0)| 00:00:45 |     |     | Q1,00 | PCWP |     |
| 7 | PX BLOCK ITERATOR          |               | 1 | 108 | 3683 (0)| 00:00:45 | 1 | 63 | Q1,00 | PCWC |     |
|* 8 | TABLE ACCESS FULL      | NADS               | 1 | 108 | 3683 (0)| 00:00:45 | 1 | 63 | Q1,00 | PCWP |     |
|* 9 | TABLE ACCESS BY INDEX ROWID| METAS           | 1 | 20 | 2 (0)| 00:00:01 |     |     | Q1,00 | PCWP |     |
|* 10 | INDEX UNIQUE SCAN      | MET_NADS_ID_TYPE_ID_UK | 1 |     | 1 (0)| 00:00:01 |     |     | Q1,00 | PCWP |     |
| 11 | XPATH EVALUATION          |               |     |     |     |      |     |     | Q1,00 | PCWP |     |
Predicate Information (identified by operation id):
8 - filter("OWNING_ORI"='ABC123' AND "NAT_SOURCE_ID"=0 AND "STATUS_ID"=1)
9 - filter("MET"."VAL"='Arrest Report')
10 - access("N"."ID"="MET"."NADS_ID" AND "MET"."TYPE_ID"=1)
Note
- dynamic sampling used for this statement (level=4)
29 rows selected.
Expalin Plan with SUM
PLAN_TABLE_OUTPUT
Plan hash value: 1527372262
| Id | Operation               | Name               | Rows | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
| 0 | SELECT STATEMENT          |               | 1 | 130 | 3713 (0)| 00:00:45 |     |     |
| 1 | SORT AGGREGATE           |               | 1 | 2 |     |      |     |     |
| 2 | XPATH EVALUATION          |               |     |     |     |      |     |     |
| 3 | SORT AGGREGATE           |               | 1 | 130 |     |      |     |     |
| 4 | SORT AGGREGATE          |               | 1 | 130 |     |      |     |     |
| 5 | NESTED LOOPS           |               | 1 | 130 | 3713 (0)| 00:00:45 |     |     |
| 6 | NESTED LOOPS          |               | 1 | 128 | 3683 (0)| 00:00:45 |     |     |
| 7 | PARTITION LIST ALL      |               | 1 | 108 | 3683 (0)| 00:00:45 | 1 | 63 |
|* 8 | TABLE ACCESS FULL      | NADS               | 1 | 108 | 3683 (0)| 00:00:45 | 1 | 63 |
|* 9 | TABLE ACCESS BY INDEX ROWID| METAS           | 1 | 20 | 2 (0)| 00:00:01 |     |     |
|* 10 | INDEX UNIQUE SCAN      | MET_NADS_ID_TYPE_ID_UK | 1 |     | 1 (0)| 00:00:01 |     |     |
| 11 | XPATH EVALUATION          |               |     |     |     |      |     |     |
Predicate Information (identified by operation id):
8 - filter("OWNING_ORI"='ABC123' AND "NAT_SOURCE_ID"=0 AND "STATUS_ID"=1)
9 - filter("MET"."VAL"='Arrest Report')
10 - access("N"."ID"="MET"."NADS_ID" AND "MET"."TYPE_ID"=1)
Note
- dynamic sampling used for this statement (level=4)
29 rows selected.
Edited by: drad on May 9, 2012 3:31 AM

After adding the no_xml_query_rewrite hint I get the PX Coordinator back and parallel processing is enabled; however, this comes at a significant performance impact (query takes 2-3 times longer). It currently appears that Parallel is not worth the cost of loosing the xml query rewrite unless a different indexing scheme can make up the difference.
Apparently the issue was the optimizer rewriting the xml query in the XMLTable which was causing Parallel processing to not be used.
For those interested, the full query is now as follows:
SELECT /*+ full(n) parallel(n,8) no_xml_query_rewrite */
     COUNT(*) as TOTAL_RECORDS,
     SUM(T7.x422s1) AS ArrestsDateEX,
     SUM(T7.x423s2) AS ArrNarAccDesEX,
     SUM(T7.x424s3) AS WitNarAccDesEX,
     SUM(T7.x425s4) AS WitFirstNameEX,
     SUM(T7.x426s5) AS WitFullNameEX,
     SUM(T7.x427s6) AS WitLastNameEX,
     SUM(T7.x428s7) AS WitMiddleNameEX,
     SUM(T7.x429s8) AS WitSexCodeEX,
     SUM(T7.x430s9) AS OfficerORIEX,
     SUM(T7.x431s10) AS OfficerFirstNameEX,
     SUM(T7.x432s11) AS OfficerFullNameEX,
     SUM(T7.x433s12) AS OfficerLastNameEX,
     SUM(T7.x434s13) AS OfficerMiddleNameEX,
     SUM(T7.x435s14) AS AreJuvDisCodeEX,
     SUM(T7.x436s15) AS AreUCRArrOffCodeEX,
     SUM(T7.x437s16) AS ArrAdtIndicatorEX,
     SUM(T7.x438s17) AS AreBirthDateEX,
     SUM(T7.x439s18) AS AreEthCodeEX,
     SUM(T7.x440s19) AS AreEyeColorEX,
     SUM(T7.x441s20) AS AreHairColorEX,
     SUM(T7.x442s21) AS ArrHeightEX,
     SUM(T7.x443s22) AS AreDvrLicNumEX,
     SUM(T7.x444s23) AS AreFBINumEX,
     SUM(T7.x445s24) AS ArePassportIDEX,
     SUM(T7.x446s25) AS AreSSNEX,
     SUM(T7.x447s26) AS AreStateIDEX,
     SUM(T7.x448s27) AS AreUSMSIDEX,
     SUM(T7.x449s28) AS AreFirstNameEX,
     SUM(T7.x450s29) AS AreFullNameEX,
     SUM(T7.x451s30) AS AreLastNameEX,
     SUM(T7.x452s31) AS AreMiddleNameEX,
     SUM(T7.x453s32) AS AreSexCodeEX,
     SUM(T7.x454s33) AS AreWeightEX,
     SUM(T7.x455s34) AS ArrLocCityEX,
     SUM(T7.x456s35) AS ArrLocCountryEX,
     SUM(T7.x457s36) AS ArrLocFullAddressEX,
     SUM(T7.x458s37) AS ArrLocFullStreetEX,
     SUM(T7.x459s38) AS ArrLocStateEX,
     SUM(T7.x460s39) AS ArrLocStreetNameEX,
     SUM(T7.x461s40) AS ArrLocStreetNumberEX,
     SUM(T7.x462s41) AS ArrLocStreetPostdirectionEX,
     SUM(T7.x463s42) AS ArrLocSteetPredirectionEX,
     SUM(T7.x464s43) AS ArrLocZipEX,
     SUM(T7.x465s44) AS OffCmpIndicatorEX,
     SUM(T7.x466s45) AS OffDesTextEX,
     SUM(T7.x467s46) AS OffDomVioIndicatorEX,
     SUM(T7.x468s47) AS OffFrcUseCodeEX,
     SUM(T7.x469s48) AS OffGangInvCodeEX,
     SUM(T7.x470s49) AS OffHmeInvIndicatorEX,
     SUM(T7.x471s50) AS OffIdtTftIndicatorEX,
     SUM(T7.x472s51) AS OffMOCCodeEX,
     SUM(T7.x473s52) AS OffOffCodeEX,
     SUM(T7.x474s53) AS OffTrrIndicatorEX,
     SUM(T7.x475s54) AS WrrAgencyEX,
     SUM(T7.x476s55) AS WrrAgencyORIEX,
     SUM(T7.x477s56) AS WrrCplOrgEX,
     SUM(T7.x478s57) AS WrrCplOrgORIEX,
     SUM(T7.x479s58) AS WrrCplPersonEX,
     SUM(T7.x480s59) AS WrrDesEX,
     SUM(T7.x481s60) AS WrrIssAuthorityEX,
     SUM(T7.x482s61) AS WrrIssAuthorityORIEX,
     SUM(T7.x483s62) AS WrrWrrDateEX
FROM NADS n, metas met, meta_types mtt,
     XMLTable(XMLNAMESPACES('http://fbi.gov/cjis/N-DEx' as "p1"),
     '/p1:DataItem' PASSING n.DATA_INTERNAL
     COLUMNS
          x451s30 NUMBER PATH 'count(Person[Role="Arrest Subject"]/Name/LastName)',
          x452s31 NUMBER PATH 'count(Person[Role="Arrest Subject"]/Name/MiddleName)',
          x453s32 NUMBER PATH 'count(Person[Role="Arrest Subject"]/Sex)',
          x454s33 NUMBER PATH 'count(Person[Role="Arrest Subject"]/Weight[PointValue or MaximumValue or MinimumValue])',
          x455s34 NUMBER PATH 'count(Location[AssociationReference/AssociationType=Arrest/AssociationReference/AssociationType and AssociationReference/AssociationGUID=Arrest/AssociationReference/AssociationGUID]/City)',
          x456s35 NUMBER PATH 'count(Location[Country])',
          x457s36 NUMBER PATH 'count(Location/FullAddress)',
          x458s37 NUMBER PATH 'count(Location/FullStreetAddress)',
          x459s38 NUMBER PATH 'count(Location/State)',
          x460s39 NUMBER PATH 'count(Location/StreetName)',
          x461s40 NUMBER PATH 'count(Location/StreetNumber)',
          x462s41 NUMBER PATH 'count(Location/StreetPostdirection)',
          x463s42 NUMBER PATH 'count(Location/StreetPredirection)',
          x464s43 NUMBER PATH 'count(Location/PostalCode)',
          x465s44 NUMBER PATH 'count(Offense/OtherContent[Info="offense was completed" or Info="offense was attempted"])',
          x466s45 NUMBER PATH 'count(Offense/OffenseDescriptionText)',
          x467s46 NUMBER PATH 'count(Offense/DomesticViolenceIndicator)',
          x468s47 NUMBER PATH 'count(Offense/ForceCategory)',
          x469s48 NUMBER PATH 'count(Offense/OtherContent[Info="gang"])',
          x470s49 NUMBER PATH 'count(Offense/OtherContent[Info="home invasion"])',
          x471s50 NUMBER PATH 'count(Offense/OtherContent[Info="identity theft"])',
          x472s51 NUMBER PATH 'count(Offense/MOCrimeAndMotive)',
          x473s52 NUMBER PATH 'count(Offense/Offense)',
          x474s53 NUMBER PATH 'count(Offense/OffenseTerrorismIndicator)',
          x475s54 NUMBER PATH 'count(Organization[AssociationReference/AssociationType="ActivityResponsibleOrganizationAssociation" and AssociationReference/AssociationGUID=Activity[OtherContent/Info="Warrant"]/AssociationReference/AssociationGUID]/Name)',
          x476s55 NUMBER PATH 'count(Organization[AssociationReference/AssociationType="ActivityResponsibleOrganizationAssociation" and AssociationReference/AssociationGUID=Activity[OtherContent/Info="Warrant"]/AssociationReference/AssociationGUID]/OrganizationID)',
          x477s56 NUMBER PATH 'count(Organization[AssociationReference/AssociationType="ActivityInvolvedOrganizationAssociation" and AssociationReference/AssociationGUID=Activity[OtherContent/Info="Warrant"]/AssociationReference/AssociationGUID]/Name)',
          x478s57 NUMBER PATH 'count(Organization[AssociationReference/AssociationType="ActivityInvolvedOrganizationAssociation" and AssociationReference/AssociationGUID=Activity[OtherContent/Info="Warrant"]/AssociationReference/AssociationGUID]/OrganizationID)',
          x424s3 NUMBER PATH 'count(Person[Role="Witness"]/WitnessNarrative)',
          x425s4 NUMBER PATH 'count(Person[Role="Witness" and string-length(Name/FirstName)>0])',
          x426s5 NUMBER PATH 'count(Person[Role="Witness" and string-length(Name/FullName)>0])',
          x427s6 NUMBER PATH 'count(Person[Role="Witness" and string-length(Name/LastName)>0])',
          x428s7 NUMBER PATH 'count(Person[Role="Witness" and string-length(Name/MiddleName)>0])',
          x429s8 NUMBER PATH 'count(Person[Role="Witness" and string-length(Sex)>0])',
          x422s1 NUMBER PATH 'count(Arrest/Date)',
          x423s2 NUMBER PATH 'count(Arrest/Narrative)',
          x430s9 NUMBER PATH 'count(Person[AssociationReference/AssociationType="PersonAssignedUnitAssociation" and AssociationReference/AssociationGUID=Organization[string-length(OrganizationID)>0]/AssociationReference[AssociationType="PersonAssignedUnitAssociation"]/AssociationGUID])',
          x431s10 NUMBER PATH 'count(Person[Role="Enforcement Official" and string-length(Name/FirstName)>0])',
          x432s11 NUMBER PATH 'count(Person[Role="Enforcement Official" and string-length(Name/FullName)>0])',
          x433s12 NUMBER PATH 'count(Person[Role="Enforcement Official" and string-length(Name/LastName)>0])',
          x434s13 NUMBER PATH 'count(Person[Role="Enforcement Official" and string-length(Name/MiddleName)>0])',
          x435s14 NUMBER PATH 'count(Person[Role="Arrest Subject"]/SubjectJuvenileSubmissionIndicator)',
          x436s15 NUMBER PATH 'count(Person[Role="Arrest Subject" and  ArrestSubjectUCROffenseCharge])',
          x437s16 NUMBER PATH 'count(Person[Role="Arrest Subject"]/TreatAsAdultIndicator)',
          x438s17 NUMBER PATH 'count(Person[Role="Arrest Subject"]/BirthDate)',
          x439s18 NUMBER PATH 'count(Person[Role="Arrest Subject"]/Ethnicity)',
          x440s19 NUMBER PATH 'count(Person[((Role="Arrest Subject") and (EyeColor or EyeColorText))])',
          x441s20 NUMBER PATH 'count(Person[((Role="Arrest Subject") and (HairColor or HairColorText))])',
          x442s21 NUMBER PATH 'count(Person[Role="Arrest Subject"]/Height[PointValue or MaximumValue or MinimumValue])',
          x443s22 NUMBER PATH 'count(Person[Role="Arrest Subject"]/DriverLicenseID/ID)',
          x444s23 NUMBER PATH 'count(Person[Role="Arrest Subject"]/FBINumber)',
          x445s24 NUMBER PATH 'count(Person[Role="Arrest Subject"]/PassportID/ID)',
          x446s25 NUMBER PATH 'count(Person[Role="Arrest Subject"]/SSN)',
          x447s26 NUMBER PATH 'count(Person[Role="Arrest Subject"]/StateFingerprintID)',
          x448s27 NUMBER PATH 'count(Person[Role="Arrest Subject"]/USMSFugitiveNumber)',
          x449s28 NUMBER PATH 'count(Person[Role="Arrest Subject"]/Name/FirstName)',
          x450s29 NUMBER PATH 'count(Person[Role="Arrest Subject"]/Name/FullName)',
          x479s58 NUMBER PATH 'count(Person[AssociationReference/AssociationType="ActivityInvolvedPersonAssociation" and AssociationReference/AssociationGUID=Activity[OtherContent/Info="Warrant"]/AssociationReference/AssociationGUID])',
          x480s59 NUMBER PATH 'count(Warrant/Description)',
          x481s60 NUMBER PATH 'count(Organization[AssociationReference/AssociationType="ActivityInformationClearerOrganizationAssociation" and AssociationReference/AssociationGUID=Activity[OtherContent/Info="Warrant"]/AssociationReference/AssociationGUID]/Name)',
          x482s61 NUMBER PATH 'count(Organization[AssociationReference/AssociationType="ActivityInformationClearerOrganizationAssociation" and AssociationReference/AssociationGUID=Activity[OtherContent/Info="Warrant"]/AssociationReference/AssociationGUID]/OrganizationID)',
          x483s62 NUMBER PATH 'count(Warrant/WarrantDate)') T7
      WHERE STATUS_ID=1
        AND NAT_SOURCE_ID=0
        AND OWNING_ORI like 'ABC123'
        and n.id=met.nads_id and met.type_id=mtt.id and mtt.name='ReportType' and met.val='Arrest Report';Edited by: drad on May 15, 2012 6:03 AM
Edited by: drad on May 15, 2012 6:04 AM
marking as answered as the above solution worked for me

Similar Messages

  • XMLTable join causes parallel query not to work

    We have a large table, a column stores xml data as binary xmltype storage, and XMLTABLE query is used to extract the data.
    If we just need to extract data into a column, and the data has no relation with other data columns, XMLTABLE query is super fast.
    Once the data has parent -> children relationship with other columns, the query becomes extremely slow. From the query plan, we could observe that the parallel execution is gone.
    I can reproduce the problem with the following scripts:
    1. Test scripts to setup
    =============================
    -- Test table
    drop table test_xml;
    CREATE table test_xml
    ( period date,
    xml_content xmltype)
    XMLTYPE COLUMN xml_content STORE AS SECUREFILE BINARY XML (
    STORAGE ( INITIAL 64K )
    enable storage in row
    nocache
    nologging
    chunk 8K
    parallel
    compress;
    -- Populate test_xml table with some records for testing
    insert into test_xml (period, xml_content)
    select sysdate, xmltype('<?xml version = "1.0" encoding = "UTF-8"?>
    <searchresult>
    <hotels>
    <hotel>
    <hotel.id>10</hotel.id>
    <roomtypes>
    <roomtype>
    <roomtype.ID>20</roomtype.ID>
    <rooms>
    <room>
    <id>30</id>
    <meals>
    <meal>
    <id>Breakfast</id>
    <price>300</price>
    </meal>
    <meal>
    <id>Dinner</id>
    <price>600</price>
    </meal>
    </meals>
    </room>
    </rooms>
    </roomtype>
    </roomtypes>
    </hotel>
    </hotels>
    </searchresult>') from dual;
    commit;
    begin
    for i in 1 .. 10
    loop
    insert into test_xml select * from test_xml;
    end loop;
    commit;
    end;
    select count(*) from test_xml;
    -- 1024
    2. Fast query. Only extract room_id info, the plan shows parallel execution. The performance is very good.
    =================================================================
    explain plan for
    select *
    from test_xml,
    XMLTABLE ('/searchresult/hotels/hotel/roomtypes/roomtype/rooms/room'
    passing xml_content
    COLUMNS
    room_id varchar2(4000) PATH './id/text()'
    ) a;
    select * from table(dbms_xplan.display());
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
    | 0 | SELECT STATEMENT | | 8364K| 15G| 548 (1)| 00:00:07 | | | |
    | 1 | PX COORDINATOR | | | | | | | | |
    | 2 | PX SEND QC (RANDOM) | :TQ10000 | 8364K| 15G| 548 (1)| 00:00:07 | Q1,00 | P->S | QC (RAND) |
    | 3 | NESTED LOOPS | | 8364K| 15G| 548 (1)| 00:00:07 | Q1,00 | PCWP | |
    | 4 | PX BLOCK ITERATOR | | | | | | Q1,00 | PCWC | |
    | 5 | TABLE ACCESS FULL| TEST_XML | 1024 | 2011K| 2 (0)| 00:00:01 | Q1,00 | PCWP | |
    | 6 | XPATH EVALUATION | | | | | | Q1,00 | PCWP | |
    3. The slow query. To extract room_id plus meal ids, no parallel execution. Performance is vert bad.
    ==============================================================
    -- One room can have multiple meal ids
    explain plan for
    select *
    from test_xml,
    XMLTABLE ('/searchresult/hotels/hotel/roomtypes/roomtype/rooms/room'
    passing xml_content
    COLUMNS
    room_id varchar2(4000) PATH './id/text()'
    , meals_node xmltype path './meals'
    ) a,
    XMLTABLE ('./meals/meal'
    passing meals_node
    COLUMNS
    meals_ids varchar2(4000) PATH './id/text()'
    ) b;
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 68G| 125T| 33M (1)|112:33:52 |
    | 1 | NESTED LOOPS | | 68G| 125T| 33M (1)|112:33:52 |
    | 2 | NESTED LOOPS | | 8364K| 15G| 676 (1)| 00:00:09 |
    | 3 | TABLE ACCESS FULL| TEST_XML | 1024 | 2011K| 2 (0)| 00:00:01 |
    | 4 | XPATH EVALUATION | | | | | |
    | 5 | XPATH EVALUATION | | | | | |
    Is the xml binary storage designed to only solve non-parent-children relationships data?
    I would hightly appreciate if someone could help.

    This problem has been confirmed as an oracle bug, currently the bug is not fixed yet.
    Bug 16752984 : PARALLEL EXECUTION NOT WORKING WITH XMLTYPE COLUMN

  • Temporary Table In SAP Query - Does not Work?

    DECLARE @date DATE
    DECLARE @delrows INT
    DECLARE @delquan INT
    DECLARE @a INT
    DECLARE @recrows INT
    DECLARE @recquan INT
    SET @a=0
    IF OBJECT_ID('tempdb..##tab) IS NOT NULL DROP TABLE ##tab
    CREATE TABLE ##tab
    [Date] date,
    [Delivery Rows] varchar(40),
    [Delivery Total Units] varchar(40),
    [Receipts Rows] varchar(40),
    [Receipts Total Units] varchar(40),
    WHILE @a!=7
         BEGIN
         SET @date=DATEADD(day,-@a, getdate())
         SELECT @delrows=ISNULL(COUNT(DLN1.[LineNum]),0), @delquan=ISNULL(SUM(DLN1.[Quantity]),0)
         FROM ODLN
         INNER JOIN DLN1 ON ODLN.[DocEntry]=DLN1.[DocEntry]
         WHERE ODLN.[CreateDate] = @date
         SELECT @recrows=ISNULL(COUNT(PCH1.[LineNum]),0) , @recquan=ISNULL(SUM(PCH1.[Quantity]),0)
         FROM OPCH
         INNER JOIN PCH1 ON OPCH.[DocEntry]=PCH1.[DocEntry]
         WHERE OPCH.[DocDate]=@date
         SET @a=@a+1
              INSERT INTO ##tab VALUES(@date,@delrows,@delquan,@recrows,@recquan)
    END
    SELECT * FROM ##tab
    {/code}
    Can anyone explain why this query does not work in SAP? It works fine on SQL but gives me this message in SAP:
    1). [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near ')'.
    2). [Microsoft][SQL Server Native Client 10.0][SQL Server]Statement 'Service Contracts' (OCTR) (s) could not be prepared.
    Edited by: Chris Candido on Feb 2, 2011 8:38 PM

    Chris,
    There are several areas in your code which needed changes. 
    1. On the field name for your temp table you had spaces.
    2. The SAP table name ODLN, OPCH, PCH1 had to be fully referenced like
    [dbo].[ODLN]
    3. You really need not have ## in front of your temp table, it could just be #
    The select at the end is actually what causes the most problem as for some reason from within SAP it does not produce the result.  I would suggest you put the whole code into a Stored Procedure and call the SP from SAP.  Corrected SQL below.  If you remove the Select line at the end the query would work with in SAP, but keep it give give you an error. SP is the best option for this.
    DECLARE @date DATE
    DECLARE @delrows INT
    DECLARE @delquan INT
    DECLARE @a INT
    DECLARE @recrows INT
    DECLARE @recquan INT
    SET @a=0
    IF object_id('tempdb..#tab') IS NOT NULL
    BEGIN
       DROP TABLE #tab
    END
    CREATE TABLE #tab
    [Date] date,
    DeliveryRows varchar(40),
    DeliveryTotalUnits varchar(40),
    ReceiptsRows varchar(40),
    ReceiptsTotalUnits varchar(40),
    WHILE @a!=7
    BEGIN
    SET @date=DATEADD(day,-@a, getdate())
    SELECT @delrows=ISNULL(COUNT(DLN1.LineNum),0), @delquan=ISNULL(SUM(DLN1.Quantity),0)
    FROM [dbo].[ODLN]
    INNER JOIN DLN1 ON [dbo].[ODLN].DocEntry=DLN1.DocEntry
    WHERE [dbo].[ODLN].CreateDate = @date
    SELECT @recrows=ISNULL(COUNT([dbo].[PCH1].LineNum),0) , @recquan=ISNULL(SUM([dbo].[PCH1].Quantity),0)
    FROM [dbo].[OPCH]
    INNER JOIN [dbo].[PCH1] ON [dbo].[OPCH].DocEntry=[dbo].[PCH1].DocEntry
    WHERE [dbo].[OPCH].DocDate=@date
    SET @a=@a+1
    INSERT INTO #tab VALUES(@date,@delrows,@delquan,@recrows,@recquan)
    END
    SELECT * FROM #tab
    Suda Sampath

  • Excel 2010 MS Query is not working

    Hi, I am in the process of upgrading all my Excel 2003 spreadsheets to Excel 2010.  I am running into problem with the MS Query.  Spreadsheets have MS Query linking to MS database.  However, when I open some of the spreadsheets, the MS Query
    is not working ie. the blue circle keeps turning and then not responding.  It is very weird that this MS Query is working fine with some spreadsheets but not couple and they are all linking to the same database except a small different in criteria.  I
    tried to re-create the Query in the spreadsheet in Excel 2010 by going to Data>From Other Sources>From Microsoft Query and select the database.  Once I set up the criteria and click Return data, the Query gets stuck.
    Please help! Any comments/suggestions will be appreciated.
    Thanks

    Hi,
    There are many possible causes that can crash MSQuery in Excel 2010.
    First, please make sure we have installed the latest Office 2010 and Windows patches.
    Second, Please read the Blog, it explains one typical crash scenario.
    =====
    AppName: msqry32.exe AppVer: 14.0.4750.1000 ModName: msvcr90.dll
    There are several possible resolution you can try to resolve the above crash:
    1. When you launch MS Query, just disable the option "Validate queries before saving or returning data", this is the fifth box in the options menu.
    The only problem is that if you have made any mistake in your query, you'll only be noticed when receiving the data in excel.
    2. Repair all the keys into registry at the following place:
    [HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\ODBC]
    For example:
    Windows Registry Editor Version 5.00
    [HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\ODBC]
    "TraceFile"="C:\\DOCUME~1\\...USERNAME...\\IMPOST~1\\Temp\\SQL.LOG"
    "TraceDll"="C:\\WINDOWS\\system32\\odbctrac.dll"
    http://blogs.technet.com/b/asiasupp/archive/2011/11/07/msquery-randomly-crashed.aspx
    =====
    Third, start the Excel 2010 with
    safe mode, it helps us confirm if some add-ins cause this issue.
    Hope it's helpful.
    Regards,
    George Zhao
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in
    Office programs.

  • Bex Query is not working in portal

    Dear Experts,
    i have uploaded BI master role into portal, By default Bex Queries are assgined to Master Role. when I clcik on preview for particular Bex Query, it's working fine. but after assigning the master role to end user, that same Bex Query is not working. it's showing Below error..
    Portal runtime error.
    An exception occurred while processing your request. Send the exception ID to your portal administrator.
    Exception ID: 05:22_18/08/10_0002_7116150
    Refer to the log file for details about this exception.
    please give me suggetions...
    Regards,
    VENU

    Hi Venu ,
    Can you please check the logs for details -  http(s):<host>:<port>/nwa . This may be a permissions issue . Check if the iview has read permission for everyone group and then test . Also post the error details here .
    Regards
    Mayank

  • Query is not working correctly

    Hi all,
    Below query is not working correctly. Please let me know, if you find the mistake
    select
    a.name,
    b.VOD_NAME,
    count(xm.ATTRIB_03)
    from
    siebel.s_vod b
    left outer join ISS_OBJ_DEF c on b.OBJECT_NUM=c.PAR_VOD_ID
    left outer join vod d on c.VOD_ID=d.row_id
    left outer join PROD_INT a on d.OBJECT_NUM=a.CFG_MODEL_ID
    left outer join PROD_INT_XM xm on a.row_id=xm.PAR_ROW_ID
    where
    b.VOD_TYPE_CD='CLASS_DEF'
    and
    c.LAST_VERS = 0
    and
    b.vod_name='Componentes'
    group by a.name,b.vod_name having count(xm.ATTRIB_03) >=5

    user9522927 wrote:
    Hi all,
    Below query is not working correctly. Please let me know, if you find the mistake
    select
    a.name,
    b.VOD_NAME,
    count(xm.ATTRIB_03)
    from
    siebel.s_vod b
    left outer join ISS_OBJ_DEF c on b.OBJECT_NUM=c.PAR_VOD_ID
    left outer join vod d on c.VOD_ID=d.row_id
    left outer join PROD_INT a on d.OBJECT_NUM=a.CFG_MODEL_ID
    left outer join PROD_INT_XM xm on a.row_id=xm.PAR_ROW_ID
    where
    b.VOD_TYPE_CD='CLASS_DEF'
    and
    c.LAST_VERS = 0
    and
    b.vod_name='Componentes'
    group by a.name,b.vod_name having count(xm.ATTRIB_03) >=5I couldn't see through the internet what happend when you ran said query. How about helping us out by showing us the evidence that it "is not working correctly".
    "Here's a picture of my car sitting in the driveway. Why won't it start?"

  • Select query is not working in BDC Program

    Hi,
    I am working in BDC for update valuation class for T-code mm01.Actually In this BDC i am using two recoding based on material type.
    i am using two internal table : I_DATA and ITAB
    Use I_DATA to hold excle data in which material No, plant , valuation type , valuation No. and ITAB for material No, material type Only.
    So, i am fetching material Type ( MARA-MTART ) through select query. But Select query is not working. and also i did check MARA table according that  Material Number then  material no. exit in Mara Table.
    Note : at run time  I_DATA have 1 row but ITAB have 0 row ....
    DATA: BEGIN OF I_DATA OCCURS 0,
    MATNR TYPE MARA-MATNR,
    WERKS TYPE MARC-WERKS,
    BWTAR TYPE RMMG1-BWTAR,
    VERPR TYPE BMMH1-VERPR,
    BKLAS TYPE MBEW-BKLAS,
    STATUS TYPE C,
    END OF I_DATA.
    DATA : BEGIN OF ITAB OCCURS 0,
    MATNR LIKE MARA-MATNR,
    MTART LIKE MARA-MTART,
    END OF ITAB.
    Loop at I_DATA.
    select matnr mtart from mara into table itab where matnr = I_DATA-matnr.
    endloop.
    Guide me..........

    If you use your
    Loop at I_DATA.
      select matnr mtart from mara into table itab
        where matnr = I_DATA-matnr.
    endloop.
    At end of loop, itab will only contain the result of the last select, so use a
    Loop at I_DATA.
      select matnr mtart from mara APPENDING table itab
        where matnr = I_DATA-matnr.
    endloop.
    better
    if I_DATA[] is not initial.
      select matnr mtart from mara into table itab
        FOR ALL ENTRIES IN i_data where matnr = i_data-matnr.
    endif.
    Some Remarks
    - If actually required (where does I_DATA come from, is it an external format, you need the internal value to use in SELECT statement), check via SE11 the correct [conversion exit|http://help.sap.com/saphelp_nw04/helpdata/en/35/26b217afab52b9e10000009b38f974/content.htm] associated with domain MATNR (Is it truly ALPHA, and not something like MATN1, so [CONVERSION_EXIT_MATN1_INPUT|http://www.sdn.sap.com/irj/scn/advancedsearch?query=conversion_exit_matn1_input])
    - You could try to use BAPI like [BAPI_MATERIAL_SAVEDATA|http://www.sdn.sap.com/irj/scn/advancedsearch?query=bapi_material_savedata] and not BDC
    Regards,
    Raymond

  • Why select query is not working?

    CREATE OR REPLACE TYPE prod_type AS OBJECT (
    pid INT,
    pprice NUMBER,
    MEMBER PROCEDURE display(pid IN NUMBER));
    create table prod of prod_type (pid primary key);
    CREATE OR REPLACE TYPE deal_type UNDER prod_type (
    ctr NUMBER,
    OVERRIDING MEMBER PROCEDURE display (pid IN NUMBER),
    insert into prod values(deal_type(101, 4, 1));
    insert into prod values(deal_type(102, 5, 0));
    ------below given select query is NOT WORKING ---------
    select ctr from prod p where p.pid=101;
    Thanks,
    -Nid

    ------below given select query is NOT WORKINGWondering how you inserted data ...
    SQL> CREATE OR REPLACE TYPE prod_type AS OBJECT (
      2  pid INT,
      3  pprice NUMBER,
      4  MEMBER PROCEDURE display(pid IN NUMBER));
      5  /
    Type created.
    SQL>
    SQL> create table prod of prod_type (pid primary key);
    Table created.
    SQL>
    SQL> CREATE OR REPLACE TYPE deal_type UNDER prod_type (
      2  ctr NUMBER,
      3  OVERRIDING MEMBER PROCEDURE display (pid IN NUMBER),
      4  );
      5  /
    Warning: Type created with compilation errors.
    SQL> sho err
    Errors for TYPE DEAL_TYPE:
    LINE/COL ERROR
    4/1      PLS-00103: Encountered the symbol ")" when expecting one of the
             following:
             , not pragma <an identifier>
             <a double-quoted delimited-identifier> final instantiable
             current order overriding static member constructor map
    SQL> CREATE OR REPLACE TYPE deal_type UNDER prod_type (
      2  ctr NUMBER,
      3  OVERRIDING MEMBER PROCEDURE display (pid IN NUMBER));
      4  /
    Warning: Type created with compilation errors.
    SQL> sho err
    Errors for TYPE DEAL_TYPE:
    LINE/COL ERROR
    1/1      PLS-00590: attempting to create a subtype UNDER a FINAL type
    SQL>You made an attempt to create a subtype UNDER a FINAL type - that the reason why can not work ...
    Avoid deriving a subtype from this FINAL type.
    HTH

  • What is a common cause for FaceTime to not work?

    What is a common cause for FaceTime to not work.
    The call rings but does not connect.

    Hi Yokanup,
    Thanks for visiting Apple Support Communities.
    If your FaceTime calls do not connect, start with the troubleshooting tips in this article:
    iOS: Troubleshooting FaceTime
    http://support.apple.com/kb/ts3367
    All the best,
    Jeremy

  • My iphone is not working. It syays that "iphone is disabled" then please connect to itunes. When I connect it It doesn't connect beacuase I should do enter first the code but I cant enter it cause my iphone is not working.

    My iphone is not working. It syays that "iphone is disabled" then please connect to itunes. When I connect it It doesn't connect beacuase I should do enter first the code but I cant enter it cause my iphone is not working.

    okej thank you, but when I restore it, it says that an unexpected error happened, what could this mean?

  • Using parameters in a select query sometimes not working

    I use parameters throughout my code - usually without problem, but for some reason in one case it does not return a result. When I modify the querystring to contain the value instead of using parameters it works. Is it because I'm secting a clob? or is it because I'm using a 9i ODP.net dll against a 10g database? this is c# 2.0
    here's the source code that does not work for me - REQUEST_DATA is a clob:
        public String loadRequest(String PSRNumber)
            String returnVal = null;
            ConnectionStringSettings connectionInfo = System.Configuration.ConfigurationManager.ConnectionStrings["Scribe"];
            OracleConnection myConnection = new OracleConnection();
            String strSQL = "select PSR, REQUEST_DATA from stats.request where PSR = :PSR";
            try
                myConnection.ConnectionString = connectionInfo.ConnectionString;
                OracleCommand cmd = new OracleCommand(strSQL, myConnection);
                cmd.CommandType = CommandType.Text;
                cmd.Parameters.Add("PSR", OracleDbType.Varchar2).Value = PSRNumber;
                myConnection.Open();
                OracleDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                    returnVal = dr.GetOracleString(dr.GetOrdinal("REQUEST_DATA")).ToString();
                else
                    returnVal = null;
                dr.Dispose();
                cmd.Dispose();
            catch (OracleException ex)
                printError(ex.Message);
            finally
                myConnection.Close();
                myConnection.Dispose();
            return returnVal;
        }when I replace the line generating the sql, and remove the lines pertaining to parameters it works:
    String strSQL = String.Format("select PSR, REQUEST_DATA from stats.request where PSR = {0}", PSRNumber);
    I'm fine just using this as a workaround, but I need an explanation why the other does not work - I prefer to use parameters.
    Message was edited by:
    user633546

    I figured it out. thank you for your help in pointing me in the right direction.
    the problem was there was a trailing space in the data.
    when the data for that table is numeric for every record, the query allows me to leave out the single quotes. Trailing spaces do not seem to cause the database to see it as non-numeric - leaving out the quote still finds the record even if there is a trailing space.
    but when I put in the quote, it is not an exact string match, so it could not find the record. sometimes this flexibility gets me into trouble :\

  • Characteristic "Master Data" setting in Query definition not working?

    Hi,
    I am having a problem with a query definition. (BI 7.0)
    The query comprises the following definition which relate to displaying Milestone dates for respective projects in a time series so the dates are populated in the correct column in a time series:
    Filter
    Project Definition = Fixed Single Project Definition
    Fiscal Year Variant = K4
    Project Profit Centre = Hierarchy Node
    Project Plant = Fixed Single Value
    Free Chars
    Network
    Network Activity
    Activity Element
    Rows
    Project Plant
    Project Profit Centre (With hierarchy)
    Project Definition
    Milestone Type  (Setting in characteristic to pick up Master Data)
    CSR Relevant    (Setting in characteristic to pick up Master Data)
          Structure
               Actual
               Scheduled
        (Actual:  Value type = Actual,  Origin = Manual ,Event = Start)
        (Scheduled:  Value type = Actual,  Origin = Scheduled ,Event = Start)
    Columns
    Key Figure structure of 12 key figures in a time series
    Selection
    Key Figure = Date
    Fiscal Year/Period = Current Fiscal Year / Period (SAP EXIT) (With Offset 1 to 12)
    FYI
    When I run the above it comes back correctly. However when I add "MILESTONE" (Characteristic setting (Posted Values) to the Query Definition immediately after the "Milestone Type" and before CSR it does not work it just is hanging for a considerable time.
    I am not using "Master Data" for the "Access Type for Result Vales" for the additional characteristic "MILESTONE" just "Posted Values".
    I was expecting that it would just show all Milestone types as per Master Data but just the Milestones that are posted for this result.
    I would appreciate a solution to this issue and an explanation to why it hangs when I add the "MILESTONE" characteristic to the definition as explained above.
    Thanks in advance..
    Stevo

    Hello there,
    Putting Milestone in the rows in the query definition is not being hang there (i.e., while creating and saving the query) right?
    It is stucked while executing the query isn't it so?
    That's because you have too many records to be desaggregated by milestone characteristic, and this is indepently of posted values in the characteristic settings.
    Putting milestone characteristic in the free characteristics will allow you to run the query, but desaggregate it (add it to the rows) will be to much information to read from your dataprovider (this is just a guess).
    If it is being stucked in query execution whike milestone is in the rows. Try this for example:
    Add milestone to the free chars. Execute the query. Filter milestone characteristic while still in the free rows and choose a value that you are pretty sure has the smallest records in the Dataprovider (could be for example value #). Than drill down milestone to the rows. You'll see that it can be executed without any problem.
    Diogo.

  • Degree in parallel hint is not working properly.

    Hi Experts,
    I am using the following delete statement.
    delete /*+ parallel(t,30) */ from master_header t;
    Sometimes the degree 30 is not working.
    On what basis we have to give the degree.
    Is the degree is session specific?
    To use this hint we need to follow any guidelines or check list.
    Please help me.
    Thanks.

    does your system have the capacity to have multiple parallel queries with 30 processes running concurrently? (like a Sun 6900 with 48-dual core processors or something. A little 8cpu box will not be able to handle this. That is why it is called a "hint". While you can "hint" in a query, the CBO can (and in this case will) ignore it and will reduce the parallel degree to what it sees the system can handle. It tries to keep developers from doing stupid stuff.

  • Update Query is not working

    Hi all,
    Below update query throws error.
    update S_ISS_OBJ_ATTR set DEFAULT_VAL in (
    SELECT
    T5.name
    FROM
    S_VOD_VER T1
    INNER JOIN S_VOD T2 ON T1.VOD_ID = T2.ROW_ID
    LEFT OUTER JOIN S_ISS_OBJ_DEF T3 ON T1.VOD_ID = T3.VOD_ID
    LEFT OUTER JOIN S_VOD T4 ON T3.PAR_VOD_ID = T4.OBJECT_NUM
    LEFT OUTER JOIN S_PROD_INT T5 ON T2.OBJECT_NUM = T5.CFG_MODEL_ID
    LEFT OUTER JOIN S_ISS_OBJ_ATTR T6 ON T2.row_id = T6.vod_id
    WHERE
    (T5.name='3EH03253AA-[My Teamwork Office Edition'
    or
    T5.name ='3EH03255AA-[My Teamwork Office Edition'
    or
    T5.name='3EH03257AA-[My Teamwork Office Edition'
    Error like "The use of the reserved word "IN" following "" is not valid.  Expected tokens may include:  "= ."."
    Please help me to resolve above error.
    Give me idea to update those records.
    Edited by: user9522927 on Jul 20, 2010 2:41 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    update S_ISS_OBJ_ATTR set DEFAULT_VAL in (
    SELECT
    T5.name
    FROM
    S_VOD_VER T1
    INNER JOIN S_VOD T2 ON T1.VOD_ID = T2.ROW_ID
    LEFT OUTER JOIN S_ISS_OBJ_DEF T3 ON T1.VOD_ID = T3.VOD_ID
    LEFT OUTER JOIN S_VOD T4 ON T3.PAR_VOD_ID = T4.OBJECT_NUM
    LEFT OUTER JOIN S_PROD_INT T5 ON T2.OBJECT_NUM = T5.CFG_MODEL_ID
    LEFT OUTER JOIN S_ISS_OBJ_ATTR T6 ON T2.row_id = T6.vod_id
    WHERE
    (T5.name='3EH03253AA-[My Teamwork Office Edition'
    or
    T5.name ='3EH03255AA-[My Teamwork Office Edition'
    or
    T5.name='3EH03257AA-[My Teamwork Office Edition'
    Error like "The use of the reserved word "IN" following "" is not valid.  Expected tokens may include:  "= ."."
    Please help me to resolve above error.
    The syntax is wrong.It should be:  > update S_ISS_OBJ_ATTR set DEFAULT_VAL = (....)This will however set all values ( all rows) of that column to the same value. I don't know if that is your intention.Edit: Regaring the JOIN and the OR's the query will probably still not work, because the SELECt will most probably return more than one value HTH,FJFrankenMy Blog: http://managingoracle.blogspot.comEdited by: fjfranken on 20-jul-2010 2:42                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Execute Query is not working

    hi all,
    In my when-new-form-instance form level trigger i have given go_block('blockname')
    execute_query
    but this execute query is not firing .when i checked using message i was able to reach line b4 and after the execute query but still it has not populated the data from the base table.
    the base table also contains records.
    when i run this particular fmx in the similliar but differnt database this form runs well and data gets populated automatically.
    i am unable to move fwd becouse of this i have spend many hours on this issue. please help me out.
    please write for any further clarifications..
    thanks and regards,

    There is no data on the table that satisfies the query. Copy the data from the database that does return data and try again. Are you looking at the correct table, it maybe a synonym issue as someone previously mentioned.
    A trick to see the select statement is this :- Press enter_query, enter :A into one of the query fields, press enter_query. A query box should appear. Type dog=1 and click ok. You will then get an error message (FRM-40505). Choose 'Display error' of the help menu (or Shift+F1). This will display the select statement. Obviously ignore the dog=1 as this is what caused the error but look at the where clause for clues.
    It does sound like the form is looking at at different table to you.

Maybe you are looking for

  • Open a crystal report on B1 look in feel

    There's a way to open a crystal report on B1 look in feel? In SAP B1 8.8 we have a way to open a external crystal file. In menu Tolls >> Preview External Crystal Reports File, you inform the file and the report will open in a SAP B1 form. I need open

  • URGENT - Web Gallery isn't in iWeb list

    I just published a mobile me gallery via aperture and i can view it online. I went into iWeb to add it to my website but when I choose add mobile me gallery, it's not in the list???? I tried publishing my site so it would log in and sync or whatever

  • SQL 2005 & 2012

    We have a server with SQL 2005 on it.  We just installed SQL 2012.  When I look in the services there is also an instance called SQLEXPRESS.  When I go into the control panel to uninstall a program I do not see any SQL Express installed.  I have stop

  • Paste function in XChange Viewer

    When I draw a shape or line in PDF XChange Viewer (to mark edits on a pdf) I am unable to paste the shape. I can copy the shape but the paste function is unavailable. I can only use the paste function when I copy and paste within the ONE text box.

  • Legal consolidation reset values

    Hi All My legal consolidation package behaves strangely. I input my data for consolidation on COM_RAW datascr which has is_CONSOL to Y and DATASCR_TYPE to I. In my businnes rules I used COM_RAW as source datascr and ELIM1 as destination datasrc which