Return all Groups for Outer Join + Count + Group By

I have two tables, TC and XEA. The relationship is one TC to many XEA. TC is a lookup table and has one field, the code field TCSI_CD. XEA has the same code field called BAM_TCSI, which is the joining key, and also another field, the date field, LOAD_DATE.
I want to generate a report counting the records in XEA and grouping by the code list in TC. When a TC code is not found in XEA, the report must show a count of zero. The SQL shown does not work, as codes not found in XEA are omitted. Thanks in advance for any help.
SELECT
TC.TCSI_CD,DECODE(COUNT(XEA.BAM_TCSI),NULL,0,COUNT(XEA.BAM_TCSI))
FROM
OB_TCSI_CD TC,
TEMP_OB_XEA_HIST XEA
WHERE
TC.TCSI_CD = XEA.BAM_TCSI(+) AND
XEA.LOAD_DATE > '1-JUN-2002'
GROUP BY
TC.TCSI_CD

You need to include a (+) after the load_date column. If you omit that, it negates the whole outer join and turns your query into an inner join. Then just a regular count will work, returning 0 for the null values. You also might want to use the to_date function, instead of relying on your session having the matching nls_date_format.
SELECT   tc.tcsi_cd,
         COUNT (xea.bam_tcsi)
FROM     ob_tcsi_cd       tc,
         temp_ob_xea_hist xea
WHERE    tc.tcsi_cd = xea.bam_tcsi (+)
AND      xea.load_date (+) > TO_DATE ('1-JUN-2002', 'DD-MON-YYYY')
GROUP BY tc.tcsi_cd

Similar Messages

  • Oj syntax for outer join

    Is there a way to make Crystal Reports XI not generate the {oj .....   syntax for outer joins?
    In Crystal Reports 8, you could do a registry change to keep CR from using oj, but that doesn't seem to work on CR XI (or I don't know where to make the registry change)

A: oj syntax for outer join

Outer Join Escape Sequence builds the syntax for ODBC drivers using the outer join syntax in its SQL syntax.
Use Regedit on the problem client machine add following keys:
STEP 1........For Crystal Reports 9: HKEY_CURRENT_USER\Software\Crystal Decisions\9.0\Crystal Reports\Database\QueryBuilder\OuterJoinEscSeq
<<<OR>>>
...................For Crystal Reports 10:HKEY_CURRENT_USER\Software\Crystal Decisions\10.0\Crystal Reports\Database\QueryBuilder\OuterJoinEscSeq
STEP 2........"MSOuterJoinEscSeq"= "insert your ODBC driver name here": List of the drivers that support Microsoft ODBC {oj ..} join escape sequence.
"NoOuterJoinEscSeq"= "insert your ODBC driver name here": List of the drivers that do not support any join escape sequence.
For example...
MSOuterJoinEscSeq = "UVODBC"

Outer Join Escape Sequence builds the syntax for ODBC drivers using the outer join syntax in its SQL syntax.
Use Regedit on the problem client machine add following keys:
STEP 1........For Crystal Reports 9: HKEY_CURRENT_USER\Software\Crystal Decisions\9.0\Crystal Reports\Database\QueryBuilder\OuterJoinEscSeq
<<<OR>>>
...................For Crystal Reports 10:HKEY_CURRENT_USER\Software\Crystal Decisions\10.0\Crystal Reports\Database\QueryBuilder\OuterJoinEscSeq
STEP 2........"MSOuterJoinEscSeq"= "insert your ODBC driver name here": List of the drivers that support Microsoft ODBC {oj ..} join escape sequence.
"NoOuterJoinEscSeq"= "insert your ODBC driver name here": List of the drivers that do not support any join escape sequence.
For example...
MSOuterJoinEscSeq = "UVODBC"

  • Need help further tuning view source for outer join

    I have been working on tuning views for use in Discoverer for some time, and I have greatly improved upon what was there, but it is still not where I need it to be. There are 2 views the users join together in Discoverer - one for contract lines, and one for contract flexfields. Run as a 1 to 1 join on contract number, performance is great. However, as soon as I have an outer join on flexfields, the performance is awful. We are talking a difference of under a minute to hours and hours. I have to be able to perform an outer join because there can be contracts without flexfields. Can anyone suggest an alternative method to get the data or further tuning? I will paste both the contract lines and contract flexfields source - I have tuned the flexfields but have done nothing to date with the lines.
    CREATE OR REPLACE VIEW XXDBD_CONTRACT_FLEXFIELDS AS
    SELECT core.contract_id, core.service_id, core.contract_number, core.service_line, core.service, core.product_line, core.equipment, core.UL_Certificate_And_End_Date, core.MAF, core.Termination_Penalty_Percentage, core.multi_year, core.multi_year_effective_dates, core.terms_multi_year, core.SerLineRenPricingMethod, core.ren_line_change, core.zone, core.add_invoice_display, core.add_subgrouping, re.diebold_price, attr.coverage_hours, attr.reaction_times, attr.resolution_times, attr.repair_times, tr.performance_requirement, attr.penalty, attr.penalty_amount, attr.penalty_bonus, attr.mon_break_start, attr.mon_break_end, attr.tues_break_start, attr.tues_break_end, attr.wed_break_start, attr.wed_break_end, attr.thu_break_start, attr.thu_break_end, attr.fri_break_start, attr.fri_break_end, attr.sat_break_start, attr.sat_break_end, attr.sun_break_start, attr.sun_break_end, attr.split_covering, attr.cash_handling
    FROM (SELECT aa.ID Contract_id,
    aa.contract_number,
    dd.id Service_ID ,
    dd.cle_id dd_cle_id,
    dd.line_number service_line,
    xxdbd_Disco_Service_Contract.GetServNameInv
    (dd.id) Service,
    dd.line_number ||'.'||ee.line_number Product_Line,
    xxdbd_Disco_Service_Contract.GetEqpNoInvoice(ee.id)
    Equipment,
    DECODE(dd.attribute_category,'Service Contracts',
    NVL(xxdbd_Disco_Service_Contract.GetContractMasterProperty('DBD_OKS_50_CHARS', dd.attribute1),dd.attribute1),'') UL_Certificate_And_End_Date,
    dd.attribute2 MAF,
    DECODE(dd.attribute_category,'Service Contracts',NVL(xxdbd_Disco_Service_Contract.GetContractMasterProperty('DBD_OKS_NUMERIC', dd.attribute3),dd.attribute3),'') Termination_Penalty_Percentage,
    DECODE(dd.attribute_category,'Service Contracts', DECODE(NVL(xxdbd_Disco_Service_Contract.GetContractMasterProperty('DBD_OKS_MULTIYEAR', dd.attribute5),dd.attribute5),
    'N','No Multi-Year',
    'Y','Multi-Year, Years not Known',
    'Y1','Multi-Year for 1 Year',
    'Y2','Multi-Year for 2 Year',
    'Y3','Multi-Year for 3 Year',
    'Y4','Multi-Year for 4 Year',
    'Y5','Multi-Year for 4 Year',dd.attribute5),'')Multi_Year,
    dd.attribute4 Multi_Year_Effective_Dates,
    DECODE(dd.attribute_category,'Service Contracts', NVL(xxdbd_Disco_Service_Contract.GetContractMasterProperty('DBD_OKS_450_CHARS', dd.attribute9),dd.attribute9),'') Terms_Multi_Year,
    DECODE(dd.attribute_category,'Service Contracts', DECODE(NVL(xxdbd_Disco_Service_Contract.GetContractMasterProperty('DBD_OKS_RENEWAL_PRICING', dd.attribute6),dd.attribute6),
    'MP', 'DBD Markup Percent',
    'CP', 'DBD Contract Price',
    'AI', 'DBD Amount Increase',
    'AD', 'DBD Amount Decrease',
    'TA', 'DBD Target Amount',
    'FR', 'DBD Flat Rate',dd.attribute6),'') SerLineRenPricingMethod,
    DECODE(dd.attribute_category,'Service Contracts', NVL(xxdbd_Disco_Service_Contract.GetContractMasterProperty('DBD_OKS_NUMERIC', dd.attribute7),dd.attribute7),'') Ren_Line_Change,
    DECODE(dd.attribute_category,'Service Contracts', DECODE(NVL(xxdbd_Disco_Service_Contract.GetContractMasterProperty('DBD_OKS_ZONE', dd.attribute8),dd.attribute8),
    'DNA1','DNA Zone 1',
    'DNA2','DNA Zone 2',
    'DNA3','DNA Zone 3',
    'BRAZIL1','Brazil Zone 1 (50 KM)',
    'BRAZIL2','Brazil Zone 2 (80 KM)',
    'BRAZIL3','Brazil Zone 3 (200 KM)',dd.attribute8),'')Zone,
    DECODE(dd.attribute11, 'N','None','SC','Sub Component', 'SN', 'Serial Number', 'SNSC', 'Serial Number and Sub-Component') Add_Invoice_Display,
    DECODE(dd.attribute10, 'SI','Service Item', 'CP','Covered Product', 'PC','Product Category') Add_SubGrouping,
    dd.attribute12 Diebold_Price,
    ee.id ee_id,
    ee.cle_id ee_cle_id
    FROM okc_k_headers_b aa,
    okc_k_lines_b dd,
    okc_k_lines_b ee
    -- xxdbd_temp_flex_contract tfc
    WHERE aa.id = dd.DNZ_CHR_ID
    AND dd.CLE_ID IS NULL
    AND dd.id = ee.cle_id
    AND ee.DNZ_CHR_ID = aa.id
    AND ee.LSE_ID =9
    AND dd.LSE_ID =1
    -- and aa.contract_number = 'NL0000014'
    -- and aa.contract_number in (select contract_number from xxdbd_flex_contract)
    -- AND tfc.contract_number = aa.contract_number
    ) core,
    (SELECT h.contract_number,
    DECODE(l.attribute_category,
    'Coverage Break', xxdbd_get_sib_cont_id(xxdbd_get_parent_cle_id(l.cle_id,2)),
    'Business Process',xxdbd_get_sib_cont_id(xxdbd_get_parent_cle_id(l.cle_id,1)),
    'Coverage Template Header',xxdbd_get_sib_cont_id(l.cle_id),
    'Transaction Type', xxdbd_get_sib_cont_id(xxdbd_get_parent_cle_id(l.cle_id,2)),null) ee_id,
    DECODE(l.attribute_category, 'Business Process', l.attribute1) Coverage_Hours,
    DECODE(l.attribute_category, 'Business Process', l.attribute2) Reaction_Times,
    DECODE(l.attribute_category, 'Business Process', l.attribute3) Resolution_Times,
    DECODE(l.attribute_category, 'Business Process', l.attribute4) Repair_Times,
    DECODE(l.attribute_category, 'Business Process', DECODE(l.attribute5,
    'RA', 'REACTION'
    , 'RS', 'RESOLUTION'
    , 'RR', 'REACTION & RESOLUTION'
    , 'NR', 'NO REQUIREMENT',
    l.attribute5)) Performance_Requirement,
    DECODE(l.attribute_category, 'Coverage Template Header', l.attribute1) Penalty,
    DECODE(l.attribute_category, 'Coverage Template Header', l.attribute2) Penalty_Amount,
    DECODE(l.attribute_category, 'Coverage Template Header', l.attribute3) Penalty_Bonus,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute1) Mon_Break_Start,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute2) Mon_Break_End,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute3) Tues_Break_Start,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute4) Tues_Break_End,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute5) Wed_Break_Start,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute6) Wed_Break_End,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute7) Thu_Break_Start,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute8) Thu_Break_End,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute9) Fri_Break_Start,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute10) Fri_Break_End,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute11) Sat_Break_Start,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute12) Sat_Break_End,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute13) Sun_Break_Start,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute14) Sun_Break_End,
    DECODE(l.attribute_category, 'Transaction Type', l.attribute1) Split_Covering,
    DECODE(l.attribute_category, 'Transaction Type', l.attribute2) Cash_Handling
    from okc_k_lines_b l , okc_k_headers_b h--, xxdbd_temp_flex_contract tfc
    where l.attribute_category in ('Coverage Break', 'Business Process', 'Coverage Template Header','Transaction Type')
    and h.id = l.dnz_chr_id
    -- and h.contract_number in (select contract_number from xxdbd_flex_contract)
    -- and tfc.contract_number = h.contract_number
    ) attr
    where core.ee_id = attr.ee_id (+)
    and core.contract_number = attr.contract_number (+);
    create or replace view xxdbd_contract_lines as
    select aa.id Contract_id,
    bb.id Service_id,
    aa.CONTRACT_NUMBER,
    F1.USER_NAME Created_By,
    F2.USER_NAME LastUpdated_By,
    bb.LINE_NUMBER Service_Line_No,
    bb.LINE_NUMBER ||'.'|| cc.LINE_NUMBER Product_Line_No,
    xxdbd_Disco_Service_Contract.GetServNameInv(bb.id) Service,
    xxdbd_Disco_Service_Contract.GetServDescInv(bb.id) Service_Desc,
    xxdbd_Disco_Service_Contract.GetServicePrice(bb.id) Service_Price,
    bb.PRICE_UNIT Service_List_Price,
    bb.CURRENCY_CODE,
    aa.SCS_CODE Contract_Type,
    bb.STS_CODE Service_Status,
    bb.TRN_CODE Term_Code,
    bb.START_DATE Service_start,
    bb.END_DATE Service_end,
    TO_NUMBER(OKS_ENT_UTIL_PVT.get_billtoshipto(Null, bb.id, 'OKX_BILLTO' )) SERVICE_BillToSite,
    xxdbd_Disco_Service_Contract.GetLocAccount(TO_NUMBER(OKS_ENT_UTIL_PVT.get_billtoshipto(Null, bb.id, 'OKX_BILLTO' ))) Bill_Account,
    xxdbd_Disco_Service_Contract.GetLocation(TO_NUMBER(OKS_ENT_UTIL_PVT.get_billtoshipto(NULL, bb.id, 'OKX_BILLTO' ))) Service_BillTo,
    TO_NUMBER(OKS_ENT_UTIL_PVT.get_billtoshipto(NULL, bb.id, 'OKX_SHIPTO' )) SERVICE_ShipToSite ,
    xxdbd_Disco_Service_Contract.GetLocation(TO_NUMBER(OKS_ENT_UTIL_PVT.get_billtoshipto(NULL, bb.id, 'OKX_SHIPTO' ))) Service_Ship_To,
    xxdbd_Disco_Service_Contract.GetLocAccount(TO_NUMBER(OKS_ENT_UTIL_PVT.get_billtoshipto(NULL, bb.id, 'OKX_SHIPTO' ))) Ship_Account,
    bb.DATE_RENEWED,
    bb.DATE_TERMINATED,
    cc.START_DATE Eqp_Start,
    cc.END_DATE Eqp_End,
    xxdbd_Disco_Service_Contract.GetEqpNoInvoice(cc.id) Eqp_No,
    xxdbd_Disco_Service_Contract.GetEqpDescInvoice(cc.ID) Eqp_Desc,
    xxdbd_Disco_Service_Contract.GetEqpQuantityInvoice(cc.id) Eqp_Quan,
    xxdbd_Disco_Service_Contract.GetEqpSerialNoInvoice(cc.id) Eqp_Serial,
    xxdbd_Disco_Service_Contract.GetCustomerCt(aa.id, bb.id) Cust_Contact,
    DD.ORGANIZATION_ID,
    dd.INSTALL_ADDRESS,
    dd.INSTALL_DATE,
    dd.INSTALL_SITE_ID INSTALL_SITE_USE_ID,
    dd.PARTY_SITE_NAME INSTALL_SITE_NAME,
    dd.PARTY_SITE_NUMBER INSTALL_SITE_NUMBER
    ,cii.inventory_item_id
    ,cii.inv_master_organization_id
    ,aa.authoring_org_id
    ,cc.id equipment_id
    ,TO_NUMBER(replace(bb.attribute12,',','')) annual_contract_amt
    ,ou.name operating_unit
    ,ou.organization_id operating_unit_id
    ,substr(xxdbd_ra_utility.Get_BusinessProcess(cc.cle_id),1,100) business_process
    ,cii.instance_id
    ,cii.instance_number
    from okc_k_headers_b aa
    ,okc_k_lines_b bb
    ,okc_k_lines_b cc
    ,fnd_user f1
    ,fnd_user f2
    ,csi_item_instances cii
    ,okc_k_items items
    ,hr_all_organization_units ou
    ,xxdbd_oks_install_info_v dd
    where aa.id = bb.dnz_chr_id
    and bb.cle_id is null
    and cc.cle_id = bb.id
    and cc.dnz_chr_id = aa.id
    and f1.user_id = bb.created_by
    and f2.user_id = bb.last_updated_by
    and cc.lse_id in (9,25,18,40)
    and dd.line_id (+) = cc.id
    and items.cle_id = cc.id
    and cii.instance_id = items.object1_id1
    and aa.authoring_org_id = ou.organization_id (+);
    Here are the explain plans from TOAD:
    Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
    SELECT STATEMENT Optimizer Mode=CHOOSE 6 49124
    NESTED LOOPS OUTER 6 80 K 49124
    VIEW 6 80 K 49112
    HASH JOIN 6 1 K 49112
    HASH JOIN 17 K 2 M 20214
    TABLE ACCESS FULL OKC.OKC_K_HEADERS_B 5 K 175 K 37
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 17 K 1 M 20162
    INDEX SKIP SCAN XXDBD.XXDBD_OKC_K_LINES_B_N10 39 17085
    TABLE ACCESS FULL OKC.OKC_K_LINES_B 502 K 34 M 27803
    VIEW PUSHED PREDICATE 1 107 2
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 42 3 K 216
    NESTED LOOPS 50 5 K 219
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_HEADERS_B 1 33 3
    INDEX RANGE SCAN OKC.OKC_K_HEADERS_B_U2 1 2
    INDEX RANGE SCAN OKC.OKC_K_LINES_B_N2 1 K 32
    Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
    SELECT STATEMENT Optimizer Mode=CHOOSE 245 63309
    NESTED LOOPS 245 291 K 63309
    NESTED LOOPS OUTER 245 286 K 63064
    NESTED LOOPS 245 80 K 62574
    HASH JOIN 245 74 K 61839
    HASH JOIN 245 71 K 61756
    HASH JOIN OUTER 245 68 K 61673
    HASH JOIN 245 60 K 61664
    HASH JOIN 205 K 32 M 28046
    TABLE ACCESS FULL OKC.OKC_K_HEADERS_B 5 K 244 K 37
    TABLE ACCESS FULL OKC.OKC_K_LINES_B 205 K 23 M 27803
    TABLE ACCESS FULL OKC.OKC_K_LINES_B 2 M 168 M 27803
    TABLE ACCESS FULL HR.HR_ALL_ORGANIZATION_UNITS 2 K 64 K 8
    TABLE ACCESS FULL APPLSYS.FND_USER 13 K 172 K 81
    TABLE ACCESS FULL APPLSYS.FND_USER 13 K 172 K 81
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_ITEMS 1 26 3
    INDEX RANGE SCAN OKC.OKC_K_ITEMS_N1 1 2
    VIEW APPS.XXDBD_OKS_INSTALL_INFO_V 1 861 2
    UNION-ALL PARTITION
    NESTED LOOPS 1 167 9
    NESTED LOOPS 1 108 8
    NESTED LOOPS 1 85 7
    NESTED LOOPS 1 51 6
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 1 25 3
    INDEX UNIQUE SCAN OKC.OKC_K_LINES_B_U1 1 2
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_ITEMS 1 26 3
    INDEX RANGE SCAN OKC.OKC_K_ITEMS_N1 1 2
    TABLE ACCESS BY INDEX ROWID CSI.CSI_ITEM_INSTANCES 1 34 1
    INDEX UNIQUE SCAN CSI.CSI_ITEM_INSTANCES_U01 1
    TABLE ACCESS BY INDEX ROWID AR.HZ_PARTY_SITES 1 23 1
    INDEX UNIQUE SCAN AR.HZ_PARTY_SITES_U1 1
    TABLE ACCESS BY INDEX ROWID AR.HZ_LOCATIONS 1 59 1
    INDEX UNIQUE SCAN AR.HZ_LOCATIONS_U1 1
    NESTED LOOPS 1 144 8
    NESTED LOOPS 1 85 7
    NESTED LOOPS 1 51 6
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 1 25 3
    INDEX UNIQUE SCAN OKC.OKC_K_LINES_B_U1 1 2
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_ITEMS 1 26 3
    INDEX RANGE SCAN OKC.OKC_K_ITEMS_N1 1 2
    TABLE ACCESS BY INDEX ROWID CSI.CSI_ITEM_INSTANCES 1 34 1
    INDEX UNIQUE SCAN CSI.CSI_ITEM_INSTANCES_U01 1
    TABLE ACCESS BY INDEX ROWID AR.HZ_LOCATIONS 1 59 1
    INDEX UNIQUE SCAN AR.HZ_LOCATIONS_U1 1
    NESTED LOOPS 1 161 8
    NESTED LOOPS 1 85 7
    NESTED LOOPS 1 51 6
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 1 25 3
    INDEX UNIQUE SCAN OKC.OKC_K_LINES_B_U1 1 2
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_ITEMS 1 26 3
    INDEX RANGE SCAN OKC.OKC_K_ITEMS_N1 1 2
    TABLE ACCESS BY INDEX ROWID CSI.CSI_ITEM_INSTANCES 1 34 1
    INDEX UNIQUE SCAN CSI.CSI_ITEM_INSTANCES_U01 1
    TABLE ACCESS BY INDEX ROWID AR.HZ_PARTIES 1 76 1
    INDEX UNIQUE SCAN AR.HZ_PARTIES_U1 1
    TABLE ACCESS BY INDEX ROWID CSI.CSI_ITEM_INSTANCES 1 21 1
    INDEX UNIQUE SCAN CSI.CSI_ITEM_INSTANCES_U01 1
    And here is the SQL to join:
    select * from xxdbd_contract_lines l, xxdbd_contract_flexfields f
    where f.service_id (+) = l.service_id
    and f.contract_number (+) = l.contract_number
    and l.contract_number = 'NL0000014'
    Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
    SELECT STATEMENT Optimizer Mode=CHOOSE 1 49221
    HASH JOIN OUTER 1 38 K 49221
    VIEW APPS.XXDBD_CONTRACT_LINES 1 19 K 96
    NESTED LOOPS OUTER 1 1 K 96
    NESTED LOOPS 1 358 94
    NESTED LOOPS 1 345 93
    NESTED LOOPS 1 332 92
    NESTED LOOPS 1 311 91
    NESTED LOOPS 1 285 88
    NESTED LOOPS 448 72 K 88
    NESTED LOOPS OUTER 1 78 4
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_HEADERS_B 1 46 3
    INDEX RANGE SCAN OKC.OKC_K_HEADERS_B_U2 1 2
    TABLE ACCESS BY INDEX ROWID HR.HR_ALL_ORGANIZATION_UNITS 1 32 1
    INDEX UNIQUE SCAN HR.HR_ORGANIZATION_UNITS_PK 1
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 378 32 K 84
    INDEX RANGE SCAN XXDBD.XXDBD_OKC_K_LINES_B_N10 378 16
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 1 119
    INDEX RANGE SCAN OKC.OKC_K_LINES_B_N2 1 K 32
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_ITEMS 1 26 3
    INDEX RANGE SCAN OKC.OKC_K_ITEMS_N1 1 2
    TABLE ACCESS BY INDEX ROWID CSI.CSI_ITEM_INSTANCES 1 21 1
    INDEX UNIQUE SCAN CSI.CSI_ITEM_INSTANCES_U01 1
    TABLE ACCESS BY INDEX ROWID APPLSYS.FND_USER 1 13 1
    INDEX UNIQUE SCAN APPLSYS.FND_USER_U1 1
    TABLE ACCESS BY INDEX ROWID APPLSYS.FND_USER 1 13 1
    INDEX UNIQUE SCAN APPLSYS.FND_USER_U1 1
    VIEW APPS.XXDBD_OKS_INSTALL_INFO_V 1 861 2
    UNION-ALL PARTITION
    NESTED LOOPS 1 167 9
    NESTED LOOPS 1 108 8
    NESTED LOOPS 1 85 7
    NESTED LOOPS 1 51 6
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 1 25 3
    INDEX UNIQUE SCAN OKC.OKC_K_LINES_B_U1 1 2
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_ITEMS 1 26 3
    INDEX RANGE SCAN OKC.OKC_K_ITEMS_N1 1 2
    TABLE ACCESS BY INDEX ROWID CSI.CSI_ITEM_INSTANCES 1 34 1
    INDEX UNIQUE SCAN CSI.CSI_ITEM_INSTANCES_U01 1
    TABLE ACCESS BY INDEX ROWID AR.HZ_PARTY_SITES 1 23 1
    INDEX UNIQUE SCAN AR.HZ_PARTY_SITES_U1 1
    TABLE ACCESS BY INDEX ROWID AR.HZ_LOCATIONS 1 59 1
    INDEX UNIQUE SCAN AR.HZ_LOCATIONS_U1 1
    NESTED LOOPS 1 144 8
    NESTED LOOPS 1 85 7
    NESTED LOOPS 1 51 6
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 1 25 3
    INDEX UNIQUE SCAN OKC.OKC_K_LINES_B_U1 1 2
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_ITEMS 1 26 3
    INDEX RANGE SCAN OKC.OKC_K_ITEMS_N1 1 2
    TABLE ACCESS BY INDEX ROWID CSI.CSI_ITEM_INSTANCES 1 34 1
    INDEX UNIQUE SCAN CSI.CSI_ITEM_INSTANCES_U01 1
    TABLE ACCESS BY INDEX ROWID AR.HZ_LOCATIONS 1 59 1
    INDEX UNIQUE SCAN AR.HZ_LOCATIONS_U1 1
    NESTED LOOPS 1 161 8
    NESTED LOOPS 1 85 7
    NESTED LOOPS 1 51 6
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 1 25 3
    INDEX UNIQUE SCAN OKC.OKC_K_LINES_B_U1 1 2
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_ITEMS 1 26 3
    INDEX RANGE SCAN OKC.OKC_K_ITEMS_N1 1 2
    TABLE ACCESS BY INDEX ROWID CSI.CSI_ITEM_INSTANCES 1 34 1
    INDEX UNIQUE SCAN CSI.CSI_ITEM_INSTANCES_U01 1
    TABLE ACCESS BY INDEX ROWID AR.HZ_PARTIES 1 76 1
    INDEX UNIQUE SCAN AR.HZ_PARTIES_U1 1
    VIEW APPS.XXDBD_CONTRACT_FLEXFIELDS 6 112 K 49124
    NESTED LOOPS OUTER 6 80 K 49124
    VIEW 6 80 K 49112
    HASH JOIN 6 1 K 49112
    HASH JOIN 17 K 2 M 20214
    TABLE ACCESS FULL OKC.OKC_K_HEADERS_B 5 K 175 K 37
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 17 K 1 M 20162
    INDEX SKIP SCAN XXDBD.XXDBD_OKC_K_LINES_B_N10 39 17085
    TABLE ACCESS FULL OKC.OKC_K_LINES_B 502 K 34 M 27803
    VIEW PUSHED PREDICATE 1 107 2
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 42 3 K 216
    NESTED LOOPS 50 5 K 219
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_HEADERS_B 1 33 3
    INDEX RANGE SCAN OKC.OKC_K_HEADERS_B_U2 1 2
    INDEX RANGE SCAN OKC.OKC_K_LINES_B_N2 1 K 32

    DECODE(l.attribute_category, 'Coverage Template Header', l.attribute3) Penalty_Bonus,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute1) Mon_Break_Start,
    DECODE(l.attribute_category, 'Transaction Type', l.attribute1) Split_Covering,Uh oh, the dreaded entity attibute value, or generic, data model.
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:10678084117056
    I am afraid slow performance is a built in feature of this database design, not much you can do in queries.
    You could possibly create the views as materialized views and query those instead.
    Quote from the linked article
    But, how does it perform? Miserably, terribly, horribly. A simple "select
    first_name, last_name from person" query is transformed into a 3-table join with
    aggregates and all. Further, if the attributes are "NULLABLE" - that is, there
    might not be a row in OBJECT_ATTRIBUTES for some attributes, you may have to
    outer join instead of just joining which in some cases can remove more optimal
    query plans from consideration.
    Writing queries might look pretty straightforward, but it's impossible to do in
    a performant fashion.

  • Newbie: Syntax for OUTER joins

    Hello there,
    I'm trying to write some very simple ANSI outer joins using quest's TOAD software but I keep running into syntax errors.
    Take the following classic text book example
    Find all customers who have not placed an order
    SELECT c.customerid, o.orderid
    FROM customers c
    LEFT OUTER JOIN orders o
    ON c.customerid = o.customerid
    WHERE o.orderid IS NULL
    alternative syntax supported by SQL Server
    SELECT c.customerid, o.orderid
    FROM customers c, orders o
    WHERE c.customerid *= o.customerid AND o.orderid IS NULL
    How do you write the above style of statements. Can you write RIGHT JOIN and FULL JOIN statements? What about CROSS JOIN statements
    Cheers,
    Colin Rippey
    null

    SELECT c.customerid, o.orderid
    FROM customers c, orders o
    WHERE
    c.customerid = o.customerid(+) and
    o.orderid IS NULL
    null

  • Compatible query for outer join..

    SELECT e.ename, a.street_address, a.city,a.state,a.post_code
    FROM emp e, addr a
    WHERE e.empno = a.empno(+)
    AND a.state = 'TEXAS'
    Which is the compatible ANSI/ISO query for the above mentioned query (A or B)
    A)
    SELECT e.ename, a.street_address, a.city,a.state,a.post_code
    FROM emp e RIGHT OUTER JOIN addr a
    ON (e.empno = a.empno)
    AND a.state = 'TEXAS'
    B)
    SELECT e.ename, a.street_address, a.city,a.state,a.post_code
    FROM emp e LEFT OUTER JOIN addr a
    ON (e.empno = a.empno)
    AND a.state = 'TEXAS'
    Thanks
    Sameer

    B)
    SELECT e.ename, a.street_address, a.city,a.state,a.post_code
    FROM emp e LEFT OUTER JOIN addr a
    ON (e.empno = a.empno)
    AND a.state = 'TEXAS'
    http://www.oracle.com/oramag/oracle/01-nov/index.html?o61sql.html
    You posted this question three times. Please post each question only once. Sometimes there is a delay from the time that you click on submit until the time that the post is displayed.

  • Alternative for OUTER Join for use in fast refresh materialized view

    Hi ,
    I have two tables as :
    CREATE TABLE TEST_SANDY1
    COL1 NUMBER
    CREATE TABLE TEST_SANDY2
    COL1 NUMBER,
    COL2 VARCHAR2(10 BYTE)
    Data for the tables are :
    INSERT INTO TEST_SANDY1 ( COL1 ) VALUES (
    1);
    INSERT INTO TEST_SANDY1 ( COL1 ) VALUES (
    2);
    INSERT INTO TEST_SANDY1 ( COL1 ) VALUES (
    3);
    COMMIT;
    INSERT INTO TEST_SANDY2 ( COL1, COL2 ) VALUES (
    1, 'a');
    INSERT INTO TEST_SANDY2 ( COL1, COL2 ) VALUES (
    2, 'b');
    INSERT INTO TEST_SANDY2 ( COL1, COL2 ) VALUES (
    4, 'd');
    COMMIT;
    Now when I run the following select statement :
    select
    b.col1
    from
    test_sandy1 a,
    test_sandy2 b
    where
    b.COL1 = a.COL1(+)
    I get :
    COL1
    1
    2
    4
    I want to build a materialized view to generate the same values but it has to be fast refresh. But since I am using outer join I am unable to create a fast refresh one.
    Can someone suggest an alternate select to create fast refresh materialized view.
    Thanks,
    Sandipan

    The select statement was not fitting my problem , so I'll change it as :
    select
    a.col1, nvl(b.col2, 'DEFAULT')
    from
    test_sandy1 a,
    test_sandy2 b
    where
    b.COL1(+) = a.COL1
    I get :
    COL1     VAL
    1     a
    2     b
    3     DEFAULT
    How do I this ?

  • Returning all records for a query

    Hi,
    still working on this library. I have the majority of it working (not pretty but it works). One problem I have run into is that when I query an authors name I would like all records for that author to be shown. However, it is only showing the final record.
                   public void Search_a()throws Exception{
              String S_author1 = JOptionPane.showInputDialog(null,"Please enter the authors name");
                   String query = ("select * from library where Author=('"+S_author1+"')");
                   ResultSet rs = db_statement.executeQuery(query);
                   while (rs.next()) {
                  String s = rs.getString("Author");
                  output.setText(rs.getString("ISBN")+"\t"+rs.getString("Title")+"\t"+ s +"\t"+ rs.getString("Publisher")+"\t"+rs.getString("Genre")+"\t"+rs.getString("Details")+"\n");
              }//end while
         }// end search_aI cannot see where the error is. I think maybe I am overwriting the previous records but thought that the inclusion of +"\n" would force each result to a new line.
    Any ideas?

    Thanks for that. Not really sure how I would implement that (new to programming) but I have managed to solve it using               output.setText(output.getText()+rs.getString("ISBN")+"\t"+rs.getString("Title")+"\t"+ s +"\t"+ rs.getString("Publisher")+"\t"+rs.getString("Genre")+"\t"+rs.getString("Details")+"\n");Thanks for the reply though.

  • Strange result for outer join with rownum

    I'm using rownum in join condition of left outer join query but i'm getting strange results.
    Query is:
    Select * from table1 left outer join table2 on table1.id = table2.id or rownum=1
    Data in table1 is
    id
    7
    8
    9
    Data in table2 is
    id
    10
    11
    12
    Result of above query in Oracle 9.2.0.1 is
    table1.id table2.id
    7 10
    7 11
    7 12
    8 10
    8 11
    8 12
    9 10
    9 11
    9 12
    Even if change is rownum related condition to like rownum >2 even than i'm getting same result.
    In case of inner join, the above condition gives results as required.
    Can anybody explain the result or is it a bug?

    could you please explain why you are using rownum.
    You may have a look at the following link explaining rownum and you should understand why you got this result, keep in mind that you are using an OR condition.
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/sql_elements6a.htm#4295

  • Performance for outer join

    Hello expert,
    following statement is left outer join or right outer join? and comparing with statement " from PCM RIGHT OUTER JOIN R ON PCM.practice_state_code = R.practice_state_code ", whose performance is better? Appreciate very much.
    PCM.practice_state_code (+) = R.practice_state_code

    Hi,
    843178 wrote:
    Hello expert,
    following statement is left outer join or right outer join?
    PCM.practice_state_code (+) = R.practice_state_codeNeither. It's the old outer join notation. Using that syntax, the order in which you put the tables in the FROM clause doesn't matter.
    and comparing with statement " from PCM RIGHT OUTER JOIN R ON PCM.practice_state_code = R.practice_state_code ", whose performance is better? They're equal.

  • Query Plan Question for Outer Join

    I have the following join query:
    select unique ep.ACT_UID,
    ep.SE_REQ_TS,
    sr.SERVICE_NM
    from
    eaisvcs.Service_requests sr,
    eaisvcs.SERVICE_EPISODE ep
    where
    ep.ACT_UID = sr.ACT_UID;
    I have an index on the act_uid in both tables, and the statistics are up-to-date. There are about 3.2 million rows in each table. 10% of the act_uid's that are in the ep table that do not have a match in the sr table. Other than that, most id's match up between the tables.
    Here is the query plan:
    ID PARENT_ID OPERATION OPTIONS
    0 SELECT STATEMENT
    1 0 SORT UNIQUE
    2 1 MERGE JOIN
    3 2 SORT JOIN
    4 3 TABLE ACCESS FULL
    5 2 SORT JOIN
    6 5 TABLE ACCESS FULL
    I cannot figure out why a table scan is being performed every time on both tables. The Act_UID is the PK in the ep table. There is a composite index (act_uid, sev_seq_no) in the sr table. the act_id is a varchar2 column in both tables. The sev_seq_no column is numeric.
    Any ideas or insights about this would be greatly appreciated.
    Thanks!

    The plan can be good.
    Oracle choose a full table scan for these reason too:
    - sr.SERVICE_NM is not a part of the index and so a full table scan is less expensive. If you will add this field to your composite index Oracle will probably take this new index.
    Bye, Aron

  • Help need for Outer Join Query Mysterious Query...

    I have two table parent tablea and child tableb
    Now
    tableb has field by name table_id,keyword_name,keyword_value
    tablea has field by name
    table_id,table_name
    I need a query which would retrieve union of this two set...(for table_name)
    1)all table_name having keyword_name='abc' and value=12
    2)all the table_name that does not have 'abc' as keyword in tableb.....
    Please let me know how it can be done....

    Ok then, try this.
    select
        a.table_name
    from
        tablea a, tableb b
    where
        a.table_id = b.table_id
        and b.keyword_name = 'abc'
        and b.value = 12
    union
    select
        c.table_name
    from
        tablea c
    where
        not exists (select 1 from tableb d
                    where d.table_id = c.table_id
                          and d.keyword_name = 'abc'
                   ) ;To get a faster answer and avoid wrong guesses, I always find it helpful to show sample data and sample output when asking a SQL question. For example:
    TableA -----------------
    table_id    table_name
      1           AAA
      2           BBB
      3           CCC
      4           DDD
      5           EEE
    TableB -----------------
    table_id    keyword_name   value
        1             abc       12
        1             def       23
        2             abc       13
        4             def       12
        5             abc       13
        5             def       12
    Desired output of query: -----------------
    AAA
    CCC
    DDD

  • TABLE_ENTRIES_GET_VIA_RFC doesn't return all data for table VBRP

    Hi guys,
    I'm trying to import data from table VBRP using fm TABLE_ENTRIES_GET_VIA_RFC in Microsoft access.
    However it only seem to import first few fields of table and then nothing !
    Am I missing something. It works fine for other tables, i tries EKPO and it works a treat. ???!!
    Many thanks
    SA
    PS: Points will be awarded.

    According to note 881127:
    Reason and Prerequisites
    The function module is only intended for internal use in the ALE area, and only for reading numerical tables.
    Solution
    Use another or a customer-specific function module.
    Rob

  • Get All group from LCES using Livecycle java API

    Hello ,
    Can anyone told me how i can retrieve all the groups that exist in my livecyle using JAVA API.
    Some method who return all groups ??
    Thanks!

    First Thank you for your answer
    I tried this part
    //Set connection properties required to invoke LiveCycle ES
                Properties connectionProps = new Properties();
                connectionProps.setProperty(ServiceClientFactoryProperties.DSC_DEFAULT_EJB_ENDPOINT, "jnp://test:1099");
                                                                      connectionProps.setProperty(ServiceClientFactoryProperties.DSC_TRANSPORT_PROTOCOL,Service ClientFactoryProperties.DSC_EJB_PROTOCOL);
                connectionProps.setProperty(ServiceClientFactoryProperties.DSC_SERVER_TYPE, "JBoss");
                connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME, "administrator");
                connectionProps.setProperty(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD, "password");
                ServiceClientFactory scf = ServiceClientFactory.createInstance(connectionProps);
                DirectoryManager directoryManager = new DirectoryManagerServiceClient(scf);
                PrincipalSearchFilter psf = new PrincipalSearchFilter();
        psf.setPrincipalType(Principal.PRINCIPALTYPE_GROUP);  //Recommended - refines the search to a User or Group
        psf.setRetrieveOnlyActive(); // Recommended - returns only ative users/groups and not obsolete/deleted users/groups
        List<Principal> resultList = directoryManager.findPrincipals(psf);
        System.out.println("Done");
    and when I check the result of my list I find incomprehensible informations.
    So when I debug the code ,  my list  contains little information.
    NB : my LDAP contains hundreds of groups.
    Any suggestion
    Any code Source.

  • Outer join query for SQL server from Oracle

    Hi All,
    My question is regarding making queries from Oracle to SQL Server database thorugh DBLink.
    In my oracle database I have a DBLink emp.world for SQL Server database.
    I need to query SQL Server data from oracle (so that this query can be combined with other oracle tables).
    Query is given below:
    SELECT
            a."EmpID" as "Employee ID",
            a."EmpStatus" "Employee Status"
            b."EmpSub" as "Employee Subjects"
    FROM
            [email protected] a
            left outer join [email protected] b on a."EmpID" = b."suEmpID"
    ORDER BY  a."EmpID";My problem is when I run the same query from oracle, it does not show the EmpID that does not exist in Subjects table, but when run from actual SQL Server database, it shows all the records.
    Samples are given below:
    Run from Oracle
    Employee ID      Employee Status     Employee Subjects
    101                     Active                     Maths
    102                     Active                     Maths
    102                     Active                     Physics
    104                   Inactive                  Chemistry
    Run form SQL Server
    Employee ID      Employee Status     Employee Subjects
    101                     Active                     Maths
    102                     Active                     Maths
    102                     Active                     Physics
    103                 Active                       NULL
    104             Inactive            ChemistryI am not sure why in oracle outer join for SQL server tables is not working. What is the right way for outer join in this case.
    I am using oracle database 10gR2 and SQL Server 2005.
    Please Help.
    Thanks.

    SELECT
    a."EmpID" as "Employee ID",
    a."EmpStatus" "Employee Status"
    b."EmpSub" as "Employee Subjects"
    FROM
    [email protected] a
    left outer join [email protected] b on a."EmpID" = b."suEmpID"
    ORDER BY a."EmpID";
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm#sthref3175
    From your description, it appears you may need a right outer join. You want to get back all the rows from 'B', not from 'A'. Try a right join and let us know.

  • Left Outer Join Problem for Multiple Condition

    Hi This is the code and I want to return the vlaues evens if it is not ther so my Sysntax is not right for that can you plz help me
    SELECT ap.descripcion AS Production_Description,
    conceptes.descripcion AS Concepts_Description ,
    um.Nomenclatura AS Unit_Measure ,
    -- real_daily_detail.FechaProduccion AS Production_Date ,
    period.Codigo as June,
    period.anio AS YEAR_08 ,
    rmd.Valor AS Values_Monthly,
    budgetd.Valor as Budget
    FROM sgr_area_produccion ap ,
    sgr_conceptos conceptes ,
    SGR_Unidad_Medida um ,
    SGR_Unidad_Produccion up ,
    SGR_Unidad_Area_Produccion uap ,
    SGR_Real_Mensual_Detalle rmd ,
    SGR_Periodo period ,
    SGR_Real_Mensual rm ,
    SGR_Presupuesto budget ,
    SGR_Presupuesto_Detalle budgetd
    where uap.ID_Unidad_Produccion = up.ID_Unidad_Produccion (+)
    and uap.ID_Area_Produccion = ap.ID_Area_Produccion (+)
    and rm.ID_Area_Produccion = uap.ID_Area_Produccion (+)
    and rm.ID_Unidad_Produccion = uap.ID_Unidad_Produccion (+)
    and rmd.ID_Unidad_Produccion = rm.ID_Unidad_Produccion (+)
    and rmd.ID_Area_Produccion = rm.ID_Area_Produccion (+)
    and rmd.ID_Periodo = rm.ID_Periodo (+)
    and period.ID_Periodo = rm.ID_Periodo (+)
    and conceptes.ID_Concepto = rmd.ID_Concepto (+)
    and budget.ID_Unidad_Produccion = uap.ID_Unidad_Produccion(+)
    and budget.ID_Area_Produccion = uap.ID_Area_Produccion (+)
    and budget.ID_Unidad_Produccion = budgetd.ID_Unidad_Produccion
    and budget.ID_Area_Produccion = budgetd.ID_Area_Produccion (+)
    and budget.ID_Periodo = budgetd.ID_Periodo (+)
    and period.ID_Periodo = budget.ID_Periodo (+)
    and period.Codigo = 'JUNIO-08'
    and conceptes.ID_Concepto = budgetd.ID_Concepto (+)
    and daily.ID_Area_Produccion = uap.ID_Area_Produccion (+)
    and daily.ID_Unidad_Produccion = uap.ID_Unidad_Produccion (+)
    and dailyd.ID_Unidad_Produccion = daily.ID_Unidad_Produccion(+)
    and dailyd.ID_Area_Produccion = daily.ID_Area_Produccion (+)
    and period.ID_Periodo = daily.ID_Periodo (+)
    and conceptes.ID_Concepto = dailyd.ID_Concepto (+)
    and um.ID_Unidad_Medida = conceptes .ID_Unidad_Medida (+)

    Oracle old outer join syntax had more restrictions than more recent ANSI outer join syntax. I do'nt want to emulate compiler and go through your code to spot any possible problems, even more if you cannot say also the exact error or exact problem what you get.
    And bear in mind that for outer joins THERE IS DIFFERENCE [url http://www.gplivna.eu/papers/sql_join_types.htm#p6.4]between join conditions and predicates in where clause.
    Gints Plivna
    http://www.gplivna.eu

  • Maybe you are looking for

    • To oprn old posting period

      Hi all Posting period open in my system is 03/2007. I want 01/2007 to be open and all other periods to be closed. How can I do it?Please explain in detail.Should I close 03/2007 by using MMPV and then open 01/2007?If so, how to open 01/2007 period, i

    • PAP2 and compatable modem/router

      I purchased a PAP2 and my modem doesn't have an Ethernet port. Can someone recommend a modem that will enable me to connect my new PAP2 and my PC. Do I need a modem/router? Prefer non wireless.

    • LSMW using IDOC - Loading Communication infotype 0105(HR Master)

      Hi, Loading IT0105(email data) using LSMW IDOC. Input File: YPERNR,YCHOIC,YSUBTY,YBEGDA,YENDDA,ID_NUMBER 08999989,0105,0010,20040101,99991231,TEST@YAHOOO Message Type - HRMASTER02 Basic Type - HRMASTER02 Mapped Structure - E1BPHR0105 I am getting an

    • Calculating words per minute

      Hi, trying to write a typing tutor program. Having trouble calculating the words per minute. Does anyone know what Im doing wrong? import java.awt.*; import java.util.Timer; import java.util.TimerTask; import java.awt.Component; import java.awt.Conta

    • Saving draft mails as part of conversations?

      Hi there, is there a way to see draft mails (incompleted replies) as a part of the on going conversation ? using Mail.app in 10.7. cheers, s.