Slow Select Query - Where clause contains Seconday index field +other flds

Hi friends,
The below query is taking about an Hour to execute in production server when there are about 6 Million records in PLAF table. I have verified the trace in ST05 and the correct secondary index (Material Matnr + Plant Plwrk) is being selected.
SELECT plnum
             matnr
             plwrk
             pedtr
             dispo
             rsnum  FROM  plaf
            INTO TABLE it_orders
            WHERE ( ( matnr  IN r_mat1 )  OR
                             matnr IN r_mat2  AND dispo IN s_mrp1 ) AND
             pedtr IN s_date AND   
             obart = '1'.
Will it be a good idea to have only MATNR (secondary index field) in the where condition of the select query and delete the internal table entries for the other where conditions ?
Edited by: Shruthi Seth on Feb 1, 2009 10:10 AM

Hello.
Creating a range r_mat = r_mat1 + r_mat2, I would do something like:
READ TABLE s_mrp1 TRANSPORTING NO FIELDS INDEX 1.
IF sy-subrc EQ 0.
  SELECT plnum matnr plwrk pedtr dispo rsnum
    FROM plaf
    INTO wa_orders
   WHERE matnr IN r_mat
     AND pedtr IN s_date
     AND obart = '1'.
    IF wa_orders-matnr IN r_mat2.
      CHECK wa_orders-dispo IN s_mrp1.
    ENDIF.
    APPEND wa_orders TO it_orders.
  ENDSELECT.
ELSE.
  SELECT plnum matnr plwrk pedtr dispo rsnum
    FROM plaf
    INTO TABLE it_orders
   WHERE matnr IN r_mat1
     AND pedtr IN s_date
     AND obart = '1'.
ENDIF.
Regards,
Valter Oliveira.

Similar Messages

  • ? Mail [12721] Error 1 performing query: WHERE clause too complex...

    Console keeps showing this about a zillion times in a row, a zillion times a day: "Mail [12721] Error 1 performing query: WHERE clause too complex no more than 100 terms allowed"
    I can't find any search results anywhere online about this.
    Lots of stalls and freezes in mail, finder/os x, and safari -- freqent failures to maintain a broadband connection (multiple times every day).
    All apps are slow, cranky with interminable beach balls getting worse all the time.
    anyone know what the heck is going on?

    Try rebuilding the mailbox to see if that helps.
    Also, how much disk space is available on your boot drive?

  • Change my sql query where-clause in an extended controller

    Hello,
    i am trying to change my sql query where-clause in an extended controller
    personAplListVO.setWhereClause(null); // first set to null
    personAplListVO.setWhereClauseParams(null); // first set to null
    personAplListVO.setWhereClause(personAplListVOWhereClause +
    newWhereClause);
    personAplListVO.setWhereClauseParams(whereClauseParams);
    personAplListVO.executeQuery();
    System.out.println(">>>>>>>>getQuery = " + personAplListVO.getQuery());
    when i get the query ( personAplListVO.getQuery()) after executeQuery(), the new newWhereClause values are missing.
    Also i am getting null from personAplListVO.getWhereClause() after executeQuery()
    as if the above code is not making any effect.
    any ideas why?
    Thank you

    Hello,
    My Query:
    /* Formatted on 2011/06/15 15:50 (Formatter Plus v4.8.8) */
    SELECT /*+ FIRST_ROWS */
    NULL AS selectflag, ppf.full_name AS person_name,
    ppf.first_name AS person_first_name, ppf.last_name AS person_last_name,
    ppf.email_address, addr.derived_locale, addr.address_id,
    phn.phone_number, phn.phone_id, ppf.date_of_birth, addr.address_line1,
    (SELECT COUNT (*)
    FROM per_all_assignments_f paf2,
    per_all_people_f ppf2
    WHERE paf2.assignment_type = 'A'
    AND :1 BETWEEN paf2.effective_start_date AND paf2.effective_end_date
    AND paf2.person_id = ppf2.person_id
    AND paf2.effective_start_date BETWEEN ppf2.effective_start_date
    AND ppf2.effective_end_date
    AND ppf2.party_id = ppf.party_id
    HAVING COUNT (*) > 0) AS jobs_applied_for,
    (SELECT MAX (paf.effective_start_date)
    FROM per_all_assignments_f paf,
    per_all_people_f ppf2
    WHERE paf.assignment_type = 'A'
    AND :2 >= paf.effective_start_date
    AND paf.person_id = ppf2.person_id
    AND paf.effective_start_date BETWEEN ppf2.effective_start_date
    AND ppf2.effective_end_date
    AND ppf2.party_id = ppf.party_id) AS last_application,
    ppf.person_id, ppf.effective_start_date, ppf.effective_end_date,
    DECODE (vac.manager_id, :3, 'Y', 'N') AS my_applicants,
    vac.NAME AS vacancy_name, vac.vacancy_id, paf.assignment_id,
    (SELECT /*+ push_subq */
    MIN (pasf.effective_start_date)
    FROM per_all_assignments_f pasf
    WHERE pasf.assignment_id = paf.assignment_id) AS application_date,
    paf.effective_end_date AS assignment_end_date,
    ast.user_status AS application_status, ast.assignment_status_type_id,
    vac.status AS vacancy_status, mgr.full_name AS recruiting_manager,
    mgr.person_id AS recruiting_manager_id,
    mgr.effective_start_date AS effective_start_date1,
    mgr.effective_end_date AS effective_end_date1,
    rec.full_name AS recruiter, rec.person_id AS recruiter_id,
    rec.effective_start_date AS effective_start_date2,
    rec.effective_end_date AS effective_end_date2,
    ppf.per_information_category, ppf.per_information1,
    ppf.per_information2, ppf.per_information3, ppf.per_information4,
    ppf.per_information5, ppf.per_information6, ppf.per_information7,
    ppf.per_information8, ppf.per_information9, ppf.per_information10,
    ppf.per_information11, ppf.per_information12, ppf.per_information13,
    ppf.per_information14, ppf.per_information15, ppf.per_information16,
    ppf.per_information17, ppf.per_information18, ppf.per_information19,
    ppf.per_information20, ppf.per_information21, ppf.per_information22,
    ppf.per_information23, ppf.per_information24, ppf.per_information25,
    ppf.per_information26, ppf.per_information27, ppf.per_information28,
    ppf.per_information29, ppf.per_information30,
    FLOOR
    (irc_location_utility.sdo_miles (iwp.geometry, loc.geometry, 0.01)
    ) AS distance_to_location,
    loc.location_id, loc.derived_locale AS derived_locale1,
    doc.document_id, doc.file_name,
    NVL2 (doc.document_id, 'Y', 'N') AS previewenabled,
    inp.notification_preference_id, ppf.attribute_category, ppf.attribute1,
    ppf.attribute2, ppf.attribute3, ppf.attribute4, ppf.attribute5,
    ppf.attribute6, ppf.attribute7, ppf.attribute8, ppf.attribute9,
    ppf.attribute10, ppf.attribute11, ppf.attribute12, ppf.attribute13,
    ppf.attribute14, ppf.attribute15, ppf.attribute16, ppf.attribute17,
    ppf.attribute18, ppf.attribute19, ppf.attribute20, ppf.attribute21,
    ppf.attribute22, ppf.attribute23, ppf.attribute24, ppf.attribute25,
    ppf.attribute26, ppf.attribute27, ppf.attribute28, ppf.attribute29,
    ppf.attribute30, TO_CHAR (ROWNUM) AS rownumber,
    TO_CHAR
    ((irc_utilities_pkg.get_recruitment_person_id (ppf.person_id, :4))
    ) AS root_person_id,
    TO_CHAR
    (irc_skills_matching_pkg.vacancy_match_percent
    (irc_utilities_pkg.get_recruitment_person_id (ppf.person_id,
    :5
    vac.vacancy_id,
    :6
    ) AS match_percent,
    ppf.party_id, paf.effective_start_date AS assignment_start_date,
    pov.vendor_id, pov.vendor_name, regatmpt.attempt_id AS reg_attempt_id,
    TO_NUMBER (DECODE (regatmpt.raw_score, -1000, NULL, regatmpt.raw_score)
    ) AS reg_attempt_score,
    NVL2
    (regatmpt.mastery_score,
    DECODE (GREATEST (regatmpt.mastery_score, regatmpt.raw_score),
    regatmpt.raw_score, 'P',
    'F'
    NVL2 (fnd_profile.VALUE ('IRC_REGISTER_TEST'),
    NVL2 (inp.attempt_id, 'A', 'N'),
    NULL
    ) AS reg_attempt_status,
    aplatmpt.attempt_id AS apl_attempt_id,
    TO_NUMBER (DECODE (aplatmpt.raw_score, -1000, NULL, aplatmpt.raw_score)
    ) AS apl_attempt_score,
    NVL2
    (aplatmpt.mastery_score,
    DECODE (GREATEST (aplatmpt.mastery_score, aplatmpt.raw_score),
    aplatmpt.raw_score, 'P',
    'F'
    NVL2 (vac.assessment_id, NVL2 (iad.attempt_id, 'A', 'N'), NULL)
    ) AS apl_attempt_status,
    hrl.meaning, hrl.lookup_type, hrl.lookup_code,
    iad.assignment_details_id, iad.considered AS considered,
    vac.business_group_id,
    NVL
    ((SELECT iav.manage_applicants_allowed
    FROM irc_agency_vacancies iav
    WHERE iav.vacancy_id = vac.vacancy_id
    AND iav.agency_id = fnd_profile.VALUE ('IRC_AGENCY_NAME')),
    'Y'
    ) AS manage_applicants_allowed,
    DECODE (paf.source_type, 'ER', 'Y', 'N') AS referred,
    ircreferralinfoeo.start_date, ircreferralinfoeo.end_date,
    (SELECT meaning
    FROM hr_lookups
    WHERE lookup_code = ircreferralinfoeo.source_type
    AND lookup_type = 'REC_TYPE') AS sourcetype,
    DECODE (ircreferralinfoeo.source_type,
    'ER', (SELECT full_name
    FROM per_all_people_f
    WHERE person_id = ircreferralinfoeo.source_person_id
    AND SYSDATE BETWEEN effective_start_date
    AND effective_end_date),
    ircreferralinfoeo.source_name
    ) AS sourcename,
    ircreferralinfoeo.object_id, ircreferralinfoeo.object_type
    FROM per_addresses addr,
    per_phones phn,
    per_all_people_f ppf,
    per_all_assignments_f paf,
    per_all_vacancies vac,
    per_assignment_status_types_v ast,
    per_all_people_f mgr,
    per_all_people_f rec,
    irc_notification_preferences inp,
    hr_locations_all_vl loc,
    irc_documents doc,
    irc_search_criteria iwp,
    per_all_people_f irc_ppf,
    po_vendors pov,
    ota_attempts regatmpt,
    irc_assignment_details_f iad,
    ota_attempts aplatmpt,
    hr_lookups hrl,
    irc_referral_info ircreferralinfoeo
    WHERE irc_utilities_pkg.get_recruitment_person_id (ppf.person_id, :7) =
    irc_ppf.person_id
    AND :8 BETWEEN ppf.effective_start_date AND ppf.effective_end_date
    AND irc_ppf.party_id = ppf.party_id
    AND ppf.person_id = paf.person_id
    AND paf.assignment_type = 'A'
    AND paf.vacancy_id = vac.vacancy_id
    AND :9 BETWEEN paf.effective_start_date AND paf.effective_end_date
    AND paf.assignment_status_type_id = ast.assignment_status_type_id
    AND irc_ppf.person_id = doc.person_id(+)
    AND irc_ppf.person_id = phn.parent_id(+)
    AND phn.parent_table(+) = 'PER_ALL_PEOPLE_F'
    AND phn.phone_type(+) = 'H1'
    AND :10 BETWEEN NVL (phn.date_from(+), :11) AND NVL (phn.date_to(+), :12)
    AND vac.manager_id = mgr.person_id(+)
    AND :13 BETWEEN mgr.effective_start_date(+) AND mgr.effective_end_date(+)
    AND vac.recruiter_id = rec.person_id(+)
    AND :14 BETWEEN rec.effective_start_date(+) AND rec.effective_end_date(+)
    AND irc_ppf.person_id = inp.person_id(+)
    AND inp.person_id = addr.person_id(+)
    AND NVL (inp.address_id, DECODE (addr.address_type(+), 'REC', addr.address_id(+),
    -1)) = addr.address_id(+)
    AND :15 BETWEEN addr.date_from(+) AND NVL (addr.date_to(+), :16)
    AND loc.location_id(+) = vac.location_id
    AND doc.TYPE(+) LIKE '%RESUME'
    AND doc.end_date(+) IS NULL
    AND irc_ppf.person_id = iwp.object_id(+)
    AND iwp.object_type(+) = 'WPREF'
    AND :17 BETWEEN irc_ppf.effective_start_date AND irc_ppf.effective_end_date
    AND ( inp.agency_id = fnd_profile.VALUE ('IRC_AGENCY_NAME')
    OR fnd_profile.VALUE ('IRC_AGENCY_NAME') IS NULL
    AND inp.agency_id = pov.vendor_id(+)
    AND inp.attempt_id = regatmpt.attempt_id(+)
    AND paf.assignment_id = iad.assignment_id(+)
    AND :18 BETWEEN iad.effective_start_date(+) AND iad.effective_end_date(+)
    AND iad.latest_details(+) = 'Y'
    AND iad.attempt_id = aplatmpt.attempt_id(+)
    AND hrl.lookup_type(+) = 'VACANCY_STATUS'
    AND vac.status = hrl.lookup_code(+)
    AND paf.assignment_id = ircreferralinfoeo.object_id(+)
    AND SYSDATE BETWEEN ircreferralinfoeo.start_date(+) AND ircreferralinfoeo.end_date(+)
    AND ( 1 = 1
    AND (NVL (doc.document_id, 1) =
    NVL ((SELECT MAX (idoc1.document_id)
    FROM irc_documents idoc1
    WHERE idoc1.person_id = irc_ppf.person_id
    AND idoc1.TYPE IN ('RESUME', 'AUTO_RESUME')
    AND idoc1.end_date IS NULL
    AND idoc1.last_update_date =
    (SELECT MAX (idoc2.last_update_date)
    FROM irc_documents idoc2
    WHERE idoc2.person_id = irc_ppf.person_id
    AND idoc2.TYPE IN
    ('RESUME', 'AUTO_RESUME')
    AND idoc2.end_date IS NULL)),
    1
    and my where clause that i want to append to the existing one:
    and ppf.sex = 'M' and ppf.nationality = '1680'
    my processFormRequest function in my extended CO
    public void processFormRequest(OAPageContext pageContext,
    OAWebBean webBean) {
    super.processFormRequest(pageContext, webBean);
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    String genderValue = pageContext.getParameter("gender");
    String nationality = pageContext.getParameter("nationality");
    ViewObject personAplListVO = am.findViewObject("PersonAplListVO");
    String personAplListVOWhereClause = personAplListVO.getWhereClause();
    Object[] whereClauseParams = personAplListVO.getWhereClauseParams();
    String newWhereClause = "";
    //gender
    if (genderValue != null && !genderValue.trim().equals("")) {
    newWhereClause += " and ppf.sex = '" + genderValue + "'";
    //nationality
    if (nationality != null && !nationality.trim().equals("")) {
    newWhereClause += " and ppf.nationality = '" + nationality + "'";
    System.out.println("\n>>>>>>>>getQuery = " + personAplListVO.getQuery());
    System.out.println("\n>>>>>>>>newWhereClause = " + newWhereClause);
    if (!newWhereClause.equals("")) {
    personAplListVO.clearCache();
    personAplListVO.setWhereClause(null); // first set to null
    personAplListVO.setWhereClauseParams(null); // first set to null
    personAplListVO.setWhereClause(personAplListVOWhereClause +
    newWhereClause);
    personAplListVO.setWhereClauseParams(whereClauseParams);
    personAplListVO.executeQuery();
    // System.out.println(">>>>>>>>newWhereClause" +
    // personAplListVOWhereClause + newWhereClause);
    // System.out.println(">>>>>>>>getWhereClause" +
    // personAplListVO.getWhereClause());
    // System.out.println(">>>>>>>>getQuery = " +
    // personAplListVO.getQuery());
    any tips?
    thanks a lot

  • Selecting values for query where clause

    hi guys, this is possibly a silly question but not sure if i am approaching the solution in the correct mannor.
    At the top of my form i have text box which the user fills in various values. These values are then used to refine the query results in the block below. I know i can go into the datablock being queried and set the where clause to equal the value of the text boxes above but i dont feel this is the right place to do it.
    If i do it that way when the text box above is blank it returns no reults when infact i want to query everything if the values are left blank. So should i put it in pre query? if so what way should it be done?
    Any help would be greatly appreciated.
    Thanks.

    Hello,
    If i do it that way when the text box above is blank it returns no reults when infact i want to query everything if the values are left blank. So should i put it in pre query? if so what way should it be done?Not really if you use like below in block's where clause...
    db_field_name1=NVL(:form_field_name1,db_field_name1) AND
    db_field_name2=NVL(:form_field_name2,db_field_name2)-Ammad

  • Very slow select query-

    Hi Guys,
    First of all apologies for the long post…
    I have written a query to fetch some data but it’s really slow…
    SELECT di.doc_no       doc_no,
           di.doc_class    doc_class,
           di.doc_sheet    doc_sheet,
           di.doc_rev      doc_rev
    FROM  dia_table di, pi_table pi
    WHERE pi.user_id = 'alain'
    AND   (1 IN (SELECT 1
                 FROM   spg_table s, ur_table r
                 WHERE  r.identity     = pi.user_id
                 AND    r.role         = s.role
                 AND    s.privilege_id = 'ADMINISTRATOR' )
    OR ( (di.edit_access = 1 OR di.view_access = 1) AND  di.person_id = pi.person_id )
    OR ( (di.edit_access = 1 OR di.view_access = 1) AND (di.person_id   = '*') )
    OR ( (di.edit_access = 1 OR di.view_access = 1) AND (di.group_id IS NOT NULL)
          AND
         (1 IN   (SELECT 1 
                  FROM   dgm_table  
                  WHERE  group_id = di.group_id 
                  AND  ( person_id = pi.person_id OR person_id = '*' ) ) )
         )This will take more than 3 hours to run…
    dia_table - 1400000 records
    pi_table - 2500 records
    spg_table - 20 records
    ur_table - 12000 records
    dgm_table - 1500 records
    Can you please advice on what kind of modifications that I could do to improve the above query…
    To get an idea I have the following results also…
    1.
    SELECT count(*)
    FROM  dia_table di, pi_table pi
    WHERE di.doc_no LIKE '10012%';
    If I run the above query (with out the where clause and with a extra condition to reduce the time to execute the query) it will return 481381 records within 4 seconds.
    2.
    SELECT count(*)
    FROM  dia_table di, pi_table pi
    WHERE pi.user_id = 'alain'
    AND   (1 IN (SELECT 1
                 FROM   spg_table s, ur_table r
                 WHERE  r.identity     = pi.user_id
                 AND    r.role         = s.role
                 AND    s.privilege_id = 'ADMINISTRATOR' )
    OR ( (di.edit_access = 1 OR di.view_access = 1) AND  di.person_id = pi.person_id )
    OR ( (di.edit_access = 1 OR di.view_access = 1) AND (di.person_id   = '*') )
    OR ( (di.edit_access = 1 OR di.view_access = 1) AND (di.group_id IS NOT NULL) )
    AND di.doc_no LIKE '10012%';
    This will return 241999 records within135 seconds. (Without the final AND clause)
    3.
    SELECT count(*)
    FROM  dia_table di, pi_table pi
    WHERE pi.user_id = 'alain'
    AND   (1 IN (SELECT 1
                 FROM   spg_table s, ur_table r
                 WHERE  r.identity     = pi.user_id
                 AND    r.role         = s.role
                 AND    s.privilege_id = 'ADMINISTRATOR' )
    OR ( (di.edit_access = 1 OR di.view_access = 1) AND  di.person_id = pi.person_id )
    OR ( (di.edit_access = 1 OR di.view_access = 1) AND (di.person_id   = '*') )
    OR ( (di.edit_access = 1 OR di.view_access = 1) AND (di.group_id IS NOT NULL)
          AND
         (1 IN   (SELECT 1 
                  FROM   dgm_table  
                  WHERE  group_id = di.group_id 
                  AND  ( person_id = pi.person_id OR person_id = '*' ) ) )
    AND di.doc_no LIKE '10012%';
    This will return 32299 records in 461 seconds. The extra condition (AND di.doc_no LIKE '10012%') was used to reduce the overall time taken so that I could see the execution times more quickly.I really appreciate any help/comments/advices you guys can provide…

    Hi... hope this will be a help to provide a suggestion…
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 2456893396
    | Id  | Operation                      | Name                      | Rows  | Byt
    |   0 | SELECT STATEMENT               |                           |  1332K|
    |   1 |  CONCATENATION                 |                           |       |
    |*  2 |   FILTER                       |                           |       |
    |   3 |    MERGE JOIN CARTESIAN        |                           |   517 | 284
    |*  4 |     TABLE ACCESS BY INDEX ROWID| DIA_TABLE                 |     1 |
    |*  5 |      INDEX RANGE SCAN          | DIA_PK                    |     1 |
    |   6 |     BUFFER SORT                |                           |  2393 | 263
    |   7 |      TABLE ACCESS FULL         | PI_TABLE                  |  2393 | 263
    |   8 |    INLIST ITERATOR             |                           |       |
    |*  9 |     INDEX RANGE SCAN           | DGM_PK                    |     1 |
    |* 10 |   FILTER                       |                           |       |
    |  11 |    MERGE JOIN CARTESIAN        |                           |   897 | 493
    |* 12 |     TABLE ACCESS FULL          | DIA_TABLE                 |     1 |
    |  13 |     BUFFER SORT                |                           |  2393 | 263
    |  14 |      TABLE ACCESS FULL         | PI_TABLE                  |  2393 | 263
    PLAN_TABLE_OUTPUT
    |  15 |    INLIST ITERATOR             |                           |       |
    |* 16 |     INDEX RANGE SCAN           | DGM_PK                    |     1 |
    |* 17 |   FILTER                       |                           |       |
    |* 18 |    HASH JOIN                   |                           | 46630 |  25
    |  19 |     TABLE ACCESS FULL          | PI_TABLE                  |  2393 | 263
    |* 20 |     TABLE ACCESS FULL          | DIA_TABLE                 |   139K|  60
    |  21 |    INLIST ITERATOR             |                           |       |
    |* 22 |     INDEX RANGE SCAN           | DGM_PK                    |     1 |
    |* 23 |   FILTER                       |                           |       |
    |  24 |    NESTED LOOPS                |                           | 64224 |  34
    |  25 |     TABLE ACCESS BY INDEX ROWID| PI_TAB                    |     1 |
    |* 26 |      INDEX UNIQUE SCAN         | USER_ID_UX                |     1 |
    |  27 |       NESTED LOOPS             |                           |     1 |
    |* 28 |        INDEX FULL SCAN         | SYSTEM_PRIVILEGE_GRANT_PK |     1 |
    |* 29 |        INDEX UNIQUE SCAN       | FND_USER_ROLE_RUNTIME_PK  |     1 |
    |* 30 |     TABLE ACCESS FULL          | DIA_TABLE                 |  1284K|
    |  31 |    INLIST ITERATOR             |                           |       |
    |* 32 |     INDEX RANGE SCAN           | DGM_PK                    |     1 |
    --------------------------------------------------------------------------------Edited by: Napster on Oct 20, 2009 1:13 AM

  • How To change the ADF View Object  query where-clause at RunTime?

    I am trying to create a simple display page which will display user data (username, assoc_dist_id, assoc_agent_id, status , etc). The User data is stored in a database table and i am using an ADF Read Only table based on the View Object to display the data on the JSF page.
    However, i want to display only the users that a particular person accessing the page has the AUTH LEVEL to see. e.g. If the person accessing the page is an 'ApplicationAdministrator' then the page should display all users in the table, If its a 'DistributorAdministrator' then the page should display only users associated with that Distributor (i.e. assoc_dist_id = :p_Dist_id ) and If its an 'AgentAdministrator' , then the page should display only users associated with that Agent ( i.e. assoc_agent_id = :p_Agent_id).
    Currently my af:table component displays all the users in the table because the query for the view object is (select * from users) . However, i want to use the same viewobject and just set the where-clause at runtime with the appropriate parameter to restrict the dataset returned.
    Do anyone knows how to accomplish this ?

    David,
    See the custom method initializeDynamicVariableDefaults() in the SRViewObjectImpl.java class in the FrameworkExtentions project in the SRDemoSampleADFBC sample application. You can find out how to install the demo if you haven't already from the ADF Learning Center at:
    http://www.oracle.com/technology/products/adf/learnadf.html
    This class is a framework extension class for view objects that adds a neat, generic feature to be able to dynamic default the value of named bind variables. You can read more about what framework extension classes are and how to use them in Chapter 25, "Advanced Business Components Techniques" of the ADF Developer's Guide for Forms/4GL Developers, also available at the learning center above.
    It is an example of generic framework functionality that "kicks in" based on the presence of custom metadata properties on a named bind variable. See section 25.3.3 "Implementing Generic Functionality Driven by Custom Properties" in the dev guide for more details. Using this sample code, if you add a bind variable to a view object, and define a custom metadata property named "DynamicDefaultValue" on that bind variable, and set this custom metadata property to the value "CurrentUser", then that bind variable will have its value dynamically defaulted to the name of the authenticated user logged in. If instead you set this custom property to the value "UserRole", then the bind variable will be set to the comma-separated string containing the list of roles that the authenticated user is part of.
    Once you've created a framework extension class for view objects like this, you can have the view objects you create inherit this generic functionality.See section 25.1.4 "How to Base an ADF Component on a Framework Extension Class" in the dev guide for more info on this.
    By adapting a technique like this (or some idea similar that better suits your needs) you can have your view object query contain bind variables whose values automatically take on the defaults based on something in the user-session environment.

  • Linq to XML query where clause excluding null attribute in child

    I'm quite new to linq/XML and although I'm making progress I'm stuck at combining two levels of elements in a where clause. The XML is something like this
    <employees type="cashier">
    <employee hired="Jun 1 2000" fired="Jun 1 2013">
    <stats name="jane doe">
    ... other stuff ...
    <stats />
    <employee/> <employee hired="Jun 1 2000">
            <stats name="john doe">
                ... other stuff ...
            <stats />
        <employee/>
    <employees/>
    I'm trying to retrieve all employees of type "cashier" that haven't been fired.
    I tried this
    IEnumerable<XElement> CashierElements = from el in xDoc.Root.Descendants("employees")
    where (string)el.Attribute("type")=="cashier"
    && (string)el.Element("stats").Attribute("fired") != null
    select el;
    But that returns entries where the fired attribute doesn't exist. I'm not even sure I can reference the stats element attribute in this way but VS2013 doesn't complain about it.
    I have managed to muddle past by using two linq selections, the one above without the stats comparison followed by a second on the results that checks for "fired" being null.
    How would I achieve this with one select statement?
    Thanks!

    Hi,
    1) Your XML contains the attribute "fired" on "employee" element. Your query search this attribute on the "stats" element.
    2) you say "that haven't been fired" by you search an attribute fired != null ? I'm not sure about your logic.
    If I understand your request, your LINQ Query is more than :
    IEnumerable<XElement> CashierElements =
    // Loop on <employees>
    from emps in xDoc.Root.Descendants("employees")
    // only 'cashier' type
    where (string)emps.Attribute("type") == "cashier"
    // Loop on <employee> in filtered <employees>
    from emp in emps.Elements("employee")
    // only the employee not fired
    where emp.Attribute("fired") == null
    // select the employee element
    select emp;
    Regards
    Yan Grenier
    Merci de bien vouloir "Marquer comme réponse", les réponses qui ont répondues à votre question, et de noter les réponses que vous avez trouvé utiles.

  • Nested table collection in select query "in clause" taking long time

    create or replace type t_circuitids is table of varchar2(100);
    --Below anonymous block keeps on running and never ends
    DECLARE
       v_circuitid    t_circuitids;
       v_count number;
       l_circuitids   VARCHAR2 (4000)
          := 'value1,value2,value3,value4,value5';
    BEGIN
    --Below query converts comma concatinated output to list and stores in nested table collection v_circuitids
       WITH a AS
            (SELECT ',' || l_circuitids || ',' AS circuitid
               FROM DUAL)
       SELECT DISTINCT TRIM (SUBSTR (circuitid,
                                     INSTR (circuitid, ',', 1, LEVEL) + 1,
                                       INSTR (circuitid, ',', 1, LEVEL + 1)
                                     - INSTR (circuitid, ',', 1, LEVEL)
                                     - 1
                            ) cid
       BULK COLLECT INTO v_circuitid
                  FROM a
            CONNECT BY LEVEL <
                             LENGTH (circuitid)
                             - LENGTH (REPLACE (circuitid, ','));
       SELECT COUNT (1)
         INTO v_count
         FROM table
        WHERE name IN (SELECT COLUMN_VALUE
                                          FROM TABLE (v_circuitid));
    END;
    --I got the issue, query "SELECT COLUMN_VALUE FROM TABLE (v_circuitid)" which is used in above code is responsible for this.
    --Same code works fine in Development and Test environments, But in prod it keeps on running
    --I solved this issue by creating a temp table, loading all values in collection into the temp table and using that temp table in "in clause"    "
    --Can any one answer why its behaving like this when i use collection in where clause?
    --I am using Oracle 9i

    Below is the code i used
    DECLARE
       v_circuitid    t_circuitids;
       v_count number;
       l_circuitids   VARCHAR2 (4000)
          := 'value1,value2,value3,value4,value5';
    BEGIN
    --Below query converts comma concatinated output to list and stores in nested table collection v_circuitids
       WITH a AS
            (SELECT ',' || l_circuitids || ',' AS circuitid
               FROM DUAL)
       SELECT DISTINCT TRIM (SUBSTR (circuitid,
                                     INSTR (circuitid, ',', 1, LEVEL) + 1,
                                       INSTR (circuitid, ',', 1, LEVEL + 1)
                                     - INSTR (circuitid, ',', 1, LEVEL)
                                     - 1
                            ) cid
       BULK COLLECT INTO v_circuitid
                  FROM a
            CONNECT BY LEVEL <
                             LENGTH (circuitid)
                             - LENGTH (REPLACE (circuitid, ','));
       SELECT COUNT (1)
         INTO v_count
         FROM table
        WHERE name IN (SELECT COLUMN_VALUE
                                          FROM TABLE (ccard(v_circuitid)));
    END;
    And got below error
    ORA-06550: line 27, column 5:
    PL/SQL: ORA-00906: missing left parenthesis
    ORA-06550: line 24, column 4:
    PL/SQL: SQL Statement ignored

  • Select avoiding where clause

    Hello,
    I am using JPA in my app and I am confused because of a select that is returning data as I didn't have anything in my where clause.
    Select A (with problems):
    Query q = em.createQuery(
    " Select distinct p "+
    " From Subgrupo sub,"+
    " UsuarioSubgrupo usb," +
    " Usuario u, "+
    " Grupo g, "+
    " Projeto p "+
    " where "+
    " sub.cdGrupo = g.cdGrupo and "+
    " g.cdProje = p.cdProje and "+
    " g.stAdmin = 1 and " +
    " sub.cdSubgr = usb.cdSubgr and " +
    " usb.cdUsuar = u.cdUsuar and " +
    " u.cdUsuar = 1"
    Select B (almost OK):
    Query q = em.createQuery(
    " Select p.dsProje "+ // the only difference
    " From Subgrupo sub,"+
    " UsuarioSubgrupo usb," +
    " Usuario u, "+
    " Grupo g, "+
    " Projeto p "+
    " where "+
    " sub.cdGrupo = g.cdGrupo and "+
    " g.cdProje = p.cdProje and "+
    " g.stAdmin = 1 and " +
    " sub.cdSubgr = usb.cdSubgr and " +
    " usb.cdUsuar = u.cdUsuar and " +
    " u.cdUsuar = 1"
    In the second select, I've got the rows according with where clause and I cannot understand how the fact of selecting an objetc Projeto (p) (select A) can make such a "mess" avoiding the rules of the where clause.
    Could someone give me a help about this problem?
    I'll be glad with any help!!
    []'s
    Alex
    !_Let's share ideas_!

    Hi,
    The issue is I am getting differents results from selects A and B and both have the same where clause.
    I have done this:
    Query q = em.createQuery(
    " SELECT NEW entity.Projeto (p.dsProje, p.cdProje) "+
    " From Subgrupo sub, "+
    " UsuarioSubgrupo usb," +
    " Usuario u, "+
    " Grupo g, "+
    " Projeto p "+
    " where sub.cdGrupo = g.cdGrupo "+
    " and g.cdProje = p.cdProje "+
    " and g.stAdmin = 1 "+
    " and sub.cdSubgr = usb.cdSubgr "+
    " and usb.cdUsuar = u.cdUsuar "+
    " and u.cdUsuar = " + cdUsuar
    I am getting what I need, but the reason why a simple select p does not work I don't know.
    This select is not generate by TopLink.
    Cheers!

  • PL/SQL: how to use in parameter in select sql where clause

    Hi
    in a procedure, I need to apply 'in parameter' in 'where clause' along with other table fields. Purpose is to create dynamic select querry with multiple conditions.
    select count(*) from table xx
    where y_code=2008 and v_type in ('SI', 'TI', 'DI') ;
    my requirement is replace 'and v_type in ('SI', 'TI', 'DI')' with in parameter. pls note in paramter may contain null value.
    Regards

    ... e.g. why on earth do you want to pass in a string to be appended to the WHERE clause of an SQL.I second that and I strongly advice NOT to do it. If you really want to do it, then come back and show us, how you would prevent SQL injection. This approach is too dangerous (and too complex) IMHO.
    Do it straight forward as in the article of Tom Kyte (link in the post of BluShadow above)

  • Avoid repeating same logic in 'select' and 'where' clauses?

    I'll preface by saying I'm self-taught and have only been fiddling with SQL for a couple of months, so forgive me if this is a dumb question. I have a query written to pull out customers who are configured to have their products stored at the wrong warehouse, according to the first 3 digits of the zip code. Here is an extremely simplified version of a query I'm trying to run:
    select custno, custbuy_zip_cd, custbuy_prim_ship_loc_cd as Warehouse,
    case when substr(custbuy_zip_cd,1,3) in ('839','848') then '20'
    when substr(custbuy_zip_cd,1,3) in ('590','591') then '33'
    end as StdWhse
    from customers
    where case when substr(custbuy_zip_cd,1,3) in ('839','848') then '20'
    when substr(custbuy_zip_cd,1,3) in ('590','591') then '33'
    end <> custbuy_prim_ship_loc_cd
    or (case when substr(custbuy_zip_cd,1,3) in ('839','848') then '20'
    when substr(custbuy_zip_cd,1,3) in ('590','591') then '33'
    end is not null and custbuy_prim_ship_loc_cd is null)
    Now, the query works, but it seems overly convoluted and feels like there must be a way to make it simpler and faster. I'm using the same 'case when' 3 times. Originally, I had thought I could use the aliases from the 'select' clause in the 'where' clause, which would simplify things:
    select custno, custbuy_prim_ship_loc_cd as Warehouse,
    case when substr(custbuy_zip_cd,1,3) in ('839','848') then '20'
    when substr(custbuy_zip_cd,1,3) in ('590','591') then '33'
    end as StdWhse
    from customers
    where StdWhse <> custbuy_prim_ship_loc_cd
    or (StdWhse is not null and custbuy_prim_ship_loc_cd is null)
    I then found out that that caused 'invalid identifier' errors. My first attempt at a solution was to use a subquery in the 'from' clause, but that ran the 'case when' on every single customer instead of the small subset, so it wound up taking much longer even though it looked neater. Any tips on how to clean up that first query to make it run faster?
    this is Oracle 11i, I believe. As a side note, I don't have write access to the database.

    Thanks for all the tips so far - still going through them. You all respond fast! Sorry about using double angle brackets for != and not using code tags, I'll make sure to format my posts properly going forward. I think the double angle brackets messed up the appearance of my original queries a little. Here's how I probably should have pasted my first query in my first post:
    select custno, custbuy_zip_cd, custbuy_prim_ship_loc_cd as Warehouse,
        case when substr(custbuy_zip_cd,1,3) in ('839','848') then '20'
            when substr(custbuy_zip_cd,1,3) in ('590','591') then '33'
        end as StdWhse
    from customers
    where case when substr(custbuy_zip_cd,1,3) in ('839','848') then '20'
            when substr(custbuy_zip_cd,1,3) in ('590','591') then '33'
        end != custbuy_prim_ship_loc_cd
        or (case when substr(custbuy_zip_cd,1,3) in ('839','848') then '20'
            when substr(custbuy_zip_cd,1,3) in ('590','591') then '33'
        end is not null and custbuy_prim_ship_loc_cd is null)The almost unanimous opinion seems to be that I should use a subquery in one way or another, but the problem remains that the only significant logic to narrow down the results is the logic that matches the 'case when' results (which are what the warehouse number should be, based on the zip code) to the current warehouse number. Therefore, it seems like any subquery is going to return my entire list of 600k customers, and take a much longer time than my original (messy) query. At least it has in the test runs I created based on
    Satyaki's and Peter's examples. The query based on my original example takes about 2.5 minutes, and the subquery examples take about 5+ even though they look cleaner.
    to clarify what the query is trying to accomplish, I want it to pull any records where the warehouse number does not equal the correct warehouse number based on zip code (or if the warehouse number is null when it shouldn't be).
    I'll try to create some sample data and sample results. Customers table:
    custno   custbuy_zip_cd  custbuy_prim_ship_loc_cd
    1        59024           20
    2        59024           33desired results:
    custno   custbuy_zip_cd   warehouse   StdWhse
    1        59024            20          33If I could create a table to hold the standard warehouses to join on, the whole thing would be much easier. The full version of the query really has hundreds of zip code prefixes and 5 different warehouses and each account has 4 alternate warehouses as well. However, I'm stuck with read only access so everything has to go right in the query. It wouldn't be the end of the world to just stick with my original query since it's not like it takes hours, and I'll only be running it weekly. I just wanted to make sure there wasn't some other solution that wasn't just cleaner but was also faster.

  • Can't Export data if WHERE clause contains AND/OR

    I am able to export the results of a query if the WHERE clause only has one condition. But if there is and AND or an OR, you can right-click and choose Export Data, but nothing happens.
    For example, the following will Export just fine:
    SELECT * FROM DUAL
    WHERE ROWNUM = 1;
    But throw in an 'AND', and it won't Export:
    SELECT * FROM DUAL
    WHERE ROWNUM = 1 AND ROWNUM < 2;
    I am running Ver 1.5.3 and haven't applied any patches.

    Unfortunately, as part of trying to fix other issues with the export functionality, 1.5.3 introduced problems where certain types of SQL statements wouldn't export (either nothing happened as you are seeing or reporting error messages like ORA-936). While it is not yet perfect, 1.5.5 handles exporting results much better (it copes with your case that fails in 1.5.3), so I would suggest you upgrade to 1.5.5.
    theFurryOne

  • MDX query - need to run different query (where clause) on mondays

    The below query works OK and uses the substitution variable CurrentWeek in the WHERE clause, but I have one shortcoming that I need your help for:
    The query works fine for all days but mondays. On Mondays I need the query to fetch numbers from last week (as opposed to current week) as the query returns null as the cubes have no data for current week on mondays. Hence I need to change the where clause to use substitution variable LastWeek, or in some other way run a different query on mondays. I have another substitution variable called WeekDay which I can use to test which day of the week it is, but I am not sure of the syntax I need to use to test for day of week and then have the query use different substitution variables as a result of this test.
    Please help.
    Henning Strand
    SELECT NON EMPTY {[Measures].[meas_sg]} ON COLUMNS,
    NON EMPTY {[Kunde],[Kunde].[KU01],[Kunde].[KU02],[Kunde].[KU03],[Kunde].[KU04]} ON ROWS
    FROM MIFS.MIFS
    WHERE ([Marked].[Dagligvare],[Tid].[&CurrentWeek])

    Or to go off of Sean's suggestion, programmatically change the value of the substitution variable, and leave the code alone.
    Other thoughts -- have a load process to a single cell (sorry, my BSO roots are showing, but the concept is the same, load a single number) and then do a boolean test off its value -- 0 = Monday, 1 = the rest of the week.
    Regards,
    Cameron Lackpour

  • Query, where clause not working.

    Hi,
    Query is:
    select vbeln posnr matnr
    from vbap
    into table it_ivbap.
    it_ivbap is internal table. i got records when i executed this query.
    gave  a where clause
    select vbeln posnr matnr
    from vbap
    into table it_ivbap
    where vbeln = '5049'.
    it is not returning any records. i tried with all the possile values of vbeln
    what I am doing wrong.
    Thanks in advance.

    Hello,
    Change like this,
    select vbeln posnr matnr
    from vbap
    into table it_ivbap
    where vbeln = '0000005049'. " Check here
    Regards,
    vasanth

  • Dynamic Query Where Clause

    Hi,
    I have the following query in a SQL Query (Pl/Sql Function Body Returning Sql Query) report:
    DECLARE
    q VARCHAR2(32767); -- query
    w VARCHAR2(4000) ; -- where clause
    we VARCHAR2(1) := 'N'; -- identifies if where clause exists
    BEGIN
    q:= 'SELECT "OSP_ID",' ||
    ' "OSP_NUMBER",'||
    ' "PROPOSAL_TITLE",'||
    ' "PROPOSAL_TYPE",'||
    ' "AGENCY_TYPE_CODE",'||
    ' "AGENCY_TYPE",'||
    ' "AGENCY_CODE",'||
    ' "AGENCY_NAME",'||
    ' "AGENCY_ABBREVIATION",'||
    ' "SPONSOR_CODE",'||
    ' "SPONSOR_NAME",'||
    ' "PI_NAME",'||
    ' "PI_EMP_NUMBER",'||
    ' "PI_PERS_ID" '||
    ' FROM "PROPOSAL_V" ';
    IF :P25_OSP_NUMBER != '-All-'
    THEN
    w := ' OSP_NUMBER = :P25_OSP_NUMBER ';
    we := 'Y';
    END IF;
    IF :P25_PROPOSAL_TYPE != '-1'
    THEN
    IF we = 'Y'
    THEN
    w := w || ' AND PROPOSAL_TYPE = :P25_PROPOSAL_TYPE ';
    ELSE
    w := ' PROPOSAL_TYPE = :P25_PROPOSAL_TYPE ';
    we := 'Y';
    END IF;
    END IF;
    IF we = 'Y'
    THEN q := q || ' WHERE '|| w;
    END IF;
    RETURN q;
    END;
    What I need is to change the ' OSP_NUMBER = :P25_OSP_NUMBER ';
    to ' OSP_NUMBER LIKE '%'||:P25_OSP_NUMBER'%'|| ';
    But I'm getting errors when I do like above.
    Can somebody please help...
    Thanks in advance
    - Pradeep

    First of all, get rid of that silly "where exists" variable, just add a where clause like where 1=1 to the query and keep adding dynamic clauses with AND clause as needed.
    Try
    q := q||'and OSP_NUMBER LIKE ''%'''||:P25_OSP_NUMBER||'''%''';

Maybe you are looking for