Where clause help.

Hi,
I have table with a partition on a column of date data type. Each partition has a month's data in it. I use the following query to fetch the data:
select column1, column2
from table1 partition(apr2011)
where trunc(date_column) = '01-APR-11';
The query works fast when partition has less records(data for 10-15 days). But as the number of records in the partition increases(at month end), the time taken to retrieve the result is much more. Request you to please help me with an alternative for the 'where clause' to get faster data.
Thanks.

Thanks Mohamed,
Finally the coin dropped
SQL> CREATE TABLE sales_range
(salesman_id  NUMBER(5),
sales_date    DATE)
PARTITION BY RANGE(sales_date)
PARTITION sales_jan2000 VALUES LESS THAN(TO_DATE('02/01/2000','MM/DD/YYYY')),
PARTITION sales_feb2000 VALUES LESS THAN(TO_DATE('03/01/2000','MM/DD/YYYY')),
PARTITION sales_mar2000 VALUES LESS THAN(TO_DATE('04/01/2000','MM/DD/YYYY')),
PARTITION sales_apr2000 VALUES LESS THAN(TO_DATE('05/01/2000','MM/DD/YYYY'))
Table created.
SQL> set autotrace traceonly explain
SQL> SELECT * FROM   sales_range
WHERE  sales_date = TO_DATE ( '03/01/2000', 'MM/DD/YYYY');
no rows selected.
Execution Plan
   0       SELECT STATEMENT Optimizer Mode=ALL_ROWS (Cost=2 Card=1 Bytes=97)
   1    0    PARTITION RANGE SINGLE (Cost=2 Card=1 Bytes=97)
   2    1      TABLE ACCESS FULL KORT.SALES_RANGE (Cost=2 Card=1 Bytes=97)
SQL> SELECT * FROM   sales_range
WHERE  TRUNC (sales_date) = TO_DATE ( '03/01/2000', 'MM/DD/YYYY');
no rows selected.
Execution Plan
   0       SELECT STATEMENT Optimizer Mode=ALL_ROWS (Cost=2 Card=1 Bytes=97)
   1    0    PARTITION RANGE ALL (Cost=2 Card=1 Bytes=97)
   2    1      TABLE ACCESS FULL KORT.SALES_RANGE (Cost=2 Card=1 Bytes=97)
Your explanation If using TRUNC, you don't get partition elimination
Regards
Peter

Similar Messages

  • Case Statement in a Where clause help

    Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    "CORE     11.2.0.1.0     Production"
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    Hello,
    I have an APEX application that I need to build a SQL statement for a LOV (List of Values). I have a hidden filed that contains the customer type which can be an 'R' or 'B'. The query needs to be able to display two different result sets based on the customer type of 'R' or 'B'.
    If the customer type is 'R' then:
    SELECT drg_descr d, drg_code r
    FROM distance_ranges
    WHERE  drg_min_miles IN (0,5)
    ORDER BY drg_min_milesIf the customer type is 'B' then:
    SELECT drg_descr d, drg_code r
    FROM distance_ranges
    WHERE  drg_min_miles IN (0,5,10,15,20)
    ORDER BY drg_min_milesCan someone help me with what I think needs to be a case statement?
    Thanks,
    Joe

    Hi,
    You can try CASE statement with WHERE clause
    SELECT drg_descr d, drg_code r
    FROM distance_ranges
    WHERE (CASE param_cust_type
    WHEN(param_cust_type='R') THEN (drg_min_miles IN (0, 5)
    WHEN (param_cust_type='B') THEN (drg_min_miles IN (0,5,10,15,20)
    END;
    Please try and let me know if anything wrong.
    Anyone from the forum comment my code if there is any wrong.
    Thanks!
    Naresh

  • Dynamic query, where clause help

    Hi Folks,
    Using my code below to generate a query.
    When using more than one condition, I'm not sure how to work out where the AND goes.
    Can anyone please help?
    Thankyou
    WHERE
    <cfif stafffilter neq "">
    deviceofficer = #stafffilter#
    </cfif>
    <cfif assetid neq "">
    AND deviceasset = '#assetid#'
    </cfif>
    <cfif isdefined("noasset")>
    AND deviceasset = ''
    </cfif>
      <cfif  isdefined("noserial")>
    AND deviceserial = ''
    </cfif>
    <cfif serial neq "">
    AND deviceserial = '#serial#'
    </cfif>
    <cfif servicearea neq "">
    AND deviceservice = #servicearea#
    </cfif>
    ORDER by locationname

    I do this sort of thing:
    <cfset sWhereAnd = "WHERE">
    <cfif isdefined("colFilter")>
         #sWhereAnd# col = #colFilter#
        <cfset sWhereAnd = "AND">
    </cfif>
    <cfif isdefined("someOtherColFilter")>
         #sWhereAnd# someOtherCol = #someOtherColFilter#
        <cfset sWhereAnd = "AND">
    </cfif>
    [etc]
    (that's pseudocode... I'd never use isDefined() or not use a <cfqueryparam> tag for my parameter values).
    I don't like doing the somewhat popular WHERE 1=1 approach as it can force a full table scan (all rows in the table will match that, and each WHERE filter expression is applied to every row of the table being filtered), unless the DB optimises it out as noise (which is what it is).  To me it's using bad SQL to cut corners.
    To be honest though, I shy away from these generic sort of queries these days.  Most of the genericism never gets used, and more specific requirements are better implemented to meet the precise need.
    Adam

  • Can you help me with the WHERE clause? Any issue with this code block?

    Hi,
    I am looking for blogs or any document on how to implement a Lookup during data loads in BW.
    The problem is that all those that I find on this site are mostly about u201CLookup in XIu201D
    I have read bits and hints on different postings on this site and this is the best I could do for the scenario shown below:
    I need to add the Chars: Char1, Char2, Char3 to CubeX
    so that I can display the data for these 3 Chars in a report.
    Char1 and Char2 are filled in ODS12 and Char3 is filled in Cube3.
    Can you help me write a routine so that while loading data to CubeX, it will read Char1, Char2, Char3 from ODS12 and Cube3; and make them available in CubeX?
    This is my attempt so far:   continue:
    u201C----
    select /bic/Char1 from /bic/ODS12
    select /bic/Char2 from /bic/ODS12
    select /bic/Char3 from /bic/Cube3
    into result
    WHERE u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026u2026
    and objvers = 'A' .        
    end select.
    u201C----
    1. What should be my WHERE clause?
    2. In the select statement, by studying samples on this where should there be an u201CMu201D in front of the ODS? e.g. select /bic/Char1 from /bic/MODS12
    If so, what is the significance and the other options?
    3. Should this code be in the Start routing of CubeX? Or any other possible location? Also, in the start routine does it matter where within the start routine this code needs to be placed?
    4. Can you please fix this code and add any lines I may be missing?
    Is what I am looking to do refer to as u201Cdoing a lookupu201D?
    Thanks

    ok

  • Help on Where clause

    Hi,
    I am a newbie on Oracle and I need help on this problem:
    I have a data block in a form and I need to insert in the Property 'WHERE CLAUSE' a where clause based on the conditions:
    1) ANA_TYPE := TXT_ANA_TYPE AND ANA_CODE := TXT_ANA_CODE. The two variable are initialized in Header Block. No problem for this.
    2) The other Where clause depend from an other variable of the Header Block . For example:
    If :SITUATION = 1 then the clause must be AND DOC_PAID <> 0
    if :SITUATION = 2 then the clause must be AND DOC_PAID = 0
    if :SITUATION = 3 then the clause must be AND DOC_INS <> 0
    Is possible to create a unique Where clause with this conditions ? If Yes How?
    I hope...
    Best Regards
    Gaetano

    and abs(sign(doc_paid)) = abs(sign(:situation-2))Also beware when you are using the where clause property in Forms. Make sure you refer to the Forms-fields and not to its contents.
    So use 'field1 = :block.item1' and not 'field1 = ' || :block.item1
    The first one used bind variables and will therefore share the plan of the query stored in the library cache, the latter one doesn't and will leave you with lots of unique statements that will thrash your shared_pool and will ultimately kill the performance.
    Regards,
    Rob.

  • Urgent Help - Getting Org_id for where clause

    HI All,
    I am trying to customise "Out of office rule" - Delegate LOV sql, it works fine from responsibility e.g. iProcurment etc. but not from HomePage worklist. The problem is getting the Org_id of the user logged-in I have tried following different methods:
    From VO:
    (1) FND_GLOBAL.ORG_ID
    (2) fnd_profile.value('ORG_ID')
    From CO: by setting the where clause
    (1) oadbtransaction.getOrgId()
    (2) oapagecontext.getOrgId()
    But every time same problem some how it's not working from Application HomePage but it will work fine if user will click on any responsibility and then come back to homepage.
    Please help it's an urgent issue.
    Thanks!

    Anoop,
    That what are the options to get the Org id on the home page for the user logged-in as user can set "Out of Office Rules" with out clicking on any responsibility ...directly from the home page.
    Thanks

  • Need Help on where clause condition

    Hello All,
    Thanks in advance::
    I have below SQL query which is returning 1500 records when i dont use any condition in where clause(Please see the query below);
    SELECT POS_TYPE,
    POS_ID,
    SUB_ACNT_ID,
    CHRG,
    DOC,
    NULL,
    ACNT_RLN,
    ACCOUNT_FLODERS_VER,
    DM_LSTUPDDT,
    DM_BTNUMBER,
    DM_USERID,
    DM_WSID,
    STAT_FLG,
    SERVICES_FLG,
    SERVICES,
    INTRST_COND,
    PST_INSTRN
    FROM &&SRC.ACCOUNT_FOLDERS,
    &&SRC.DB;
    Output: 15 rows retured
    And when i validate the data by putting some conditions in where clause , it is giving 1499 records ( Please see the query below with condition )
    SELECT POS_TYPE,
    POS_ID,
    SUB_ACNT_ID,
    CHRG,
    DOC,
    NULL,
    ACNT_RLN,
    ACCOUNT_FLODERS_VER,
    DM_LSTUPDDT,
    DM_BTNUMBER,
    DM_USERID,
    DM_WSID,
    STAT_FLG,
    SERVICES_FLG,
    SERVICES,
    INTRST_COND,
    PST_INSTRN
    FROM &&SRC.ACCOUNT_FOLDERS,
    &&SRC.DB
    WHERE (POS_TYPE,
    POS_ID,
    SUB_ACNT_ID) IN (SELECT POS_TYPE,
    POS_ID,
    SUB_ACNT_ID FROM ACCOUNT
    WHERE DM_LSTUPDDT > 1_LAST_RUN_DATE OR 1_FIRST_RUN_FLAG=1);
    Now, I wanted to know that missing record(1st SQL is giving 1500 rows without any condition & 1nd SQL is giving 1499 rows with condition in where clause)
    I am worried and confused to find out the missing record. Tried with different conditions like Not In... nothing worked perfectly.
    Could some one please have a look and provide me the correct SQL , Performance wise also it should be good, SQL should not cause any performance issues.
    Please help me on it..
    Thanks,
    MKR

    Do a minus
    SELECT POS_TYPE,
           POS_ID,
           SUB_ACNT_ID,
           CHRG,
           DOC,
           NULL,
           ACNT_RLN,
           ACCOUNT_FLODERS_VER,
           DM_LSTUPDDT,
           DM_BTNUMBER,
           DM_USERID,
           DM_WSID,
           STAT_FLG,
           SERVICES_FLG,
           SERVICES,
           INTRST_COND,
           PST_INSTRN
      FROM &&SRC.ACCOUNT_FOLDERS, &&SRC.DB;
    MINUS
    SELECT POS_TYPE,
           POS_ID,
           SUB_ACNT_ID,
           CHRG,
           DOC,
           NULL,
           ACNT_RLN,
           ACCOUNT_FLODERS_VER,
           DM_LSTUPDDT,
           DM_BTNUMBER,
           DM_USERID,
           DM_WSID,
           STAT_FLG,
           SERVICES_FLG,
           SERVICES,
           INTRST_COND,
           PST_INSTRN
      FROM &&SRC.ACCOUNT_FOLDERS, &&SRC.DB
    WHERE (POS_TYPE, POS_ID, SUB_ACNT_ID) IN (SELECT POS_TYPE, POS_ID, SUB_ACNT_ID
                                                 FROM ACCOUNT
                                                WHERE DM_LSTUPDDT > 1_LAST_RUN_DATE
                                                   OR  1_FIRST_RUN_FLAG = 1);  G.

  • Expenditure Type LOV-- Adding where clause with controller extension- help

    Hi Gurus,
    I'm new to OA Framework and Java and I need to extend the controller for the expenditure type lov in iProcurement. I need to add a where clause to the VO to show only those expenditure
    types that will pass transactions controls based on the project and task.
    Name of the VO:ExpenditureTypeNoAwardLOVVO
    controller:oracle.apps.icx.lov.webui.ExpenditureTypeLovCO
    Original Query from the VO:
    select * from (SELECT et.expenditure_type, et.sys_link_start_date_active,
    et.sys_link_end_date_active, 1 as dummy_number
    FROM pa_expenditure_types_expend_v et
    WHERE et.system_linkage_function = 'VI'
    and (trunc(sysdate) between et.expnd_typ_start_date_active and
    nvl(et.expnd_typ_end_date_active, trunc(sysdate+1)))
    and (trunc(sysdate) between et.sys_link_start_date_active and
    nvl(et.sys_link_end_date_active, trunc(sysdate+1))) QRSLT
    ((WHERE UPPER(EXPENDITURE_TYPE) like UPPER(:1)
    AND (UPPER(EXPENDITURE_TYPE) like :2 or UPPER(EXPENDITURE_TYPE) like :3
    or UPPER(EXPENDITURE_TYPE) like :4 or UPPER(EXPENDITURE_TYPE) like :5)))
    I created a custom database function xxpa_check_txnctl which takes project_id, task_id and expenditure type as parameters and returns "Y" if that expenditure type is valid or
    returns "N" if it is not valid.
    What I need to add to the where clause of the above query is
    and *'Y' = ( select xxpa_check_txnctl(project_id,task_id,et.expenditure_type) from dual)* to the standard VO query so that only valid expenditure types will show up in the LOV for that
    project/task combination.
    I enabled the Debug Log from Diagnostics and able to see the values of project_id and task_id in the controller attached to the LOV (oracle.apps.icx.lov.webui.ExpenditureTypeLovCO) as shown
    below. Please tell me how I can add the where condition to the custom controller .
    I really appreciate your help.
    Thanks in Advance,
    Shree.
    ==========================================================================================
    [28]:STATEMENT:[icx.lov.webui.ExpenditureTypeLovCO]:#Param# ProjectId=13
    [28]:STATEMENT:[icx.lov.webui.ExpenditureTypeLovCO]:lov criteria item from dictionary in getLovItemNumber():
    [28]:STATEMENT:[icx.lov.webui.ExpenditureTypeLovCO]:#Param# TaskId=796
    [28]:STATEMENT:[icx.lov.webui.ExpenditureTypeLovCO]:VO used in ExpenditureTypeLovCO.java:
    [28]:STATEMENT:[icx.lov.webui.ExpenditureTypeLovCO]:#Param# voName=ExpenditureTypeNoAwardLovVO
    ==========================================================================================
    Here is the code for the standard controller:
    ==========================================================================================
    package oracle.apps.icx.lov.webui;
    import com.sun.java.util.collections.ArrayList;
    import oracle.apps.fnd.common.VersionInfo;
    import oracle.apps.fnd.framework.OAApplicationModule;
    import oracle.apps.fnd.framework.OAViewObject;
    import oracle.apps.fnd.framework.webui.OAPageContext;
    import oracle.apps.fnd.framework.webui.beans.OAWebBean;
    import oracle.apps.fnd.framework.webui.beans.form.OAFormValueBean;
    import oracle.apps.fnd.framework.webui.beans.layout.OAListOfValuesBean;
    import oracle.apps.fnd.framework.webui.beans.message.OAMessageStyledTextBean;
    import oracle.apps.icx.por.req.webui.CheckoutInfoBaseCO;
    import oracle.jbo.domain.Number;
    public class ExpenditureTypeLovCO extends CheckoutInfoBaseCO
    public static final String RCS_ID = "$Header: ExpenditureTypeLovCO.java 120.1 2006/07/25 06:33:16 sudsubra noship $";
    public static final boolean RCS_ID_RECORDED = VersionInfo.recordClassVersion("$Header: ExpenditureTypeLovCO.java 120.1 2006/07/25 06:33:16 sudsubra noship $",
    "oracle.apps.icx.lov.webui");
    public ExpenditureTypeLovCO()
    public void processRequest(OAPageContext oapagecontext, OAWebBean oawebbean)
    super.processRequest(oapagecontext, oawebbean);
    java.util.Dictionary dictionary = oapagecontext.getLovCriteriaItems();
    Number number = getLovItemNumber(oapagecontext, dictionary, "ReqAwardId");
    Number number1 = getLovItemNumber(oapagecontext, dictionary, "ProjectId");
    Number number2 = getLovItemNumber(oapagecontext, dictionary, "TaskId");
    String s = null;
    if(number == null)
    s = "ExpenditureTypeNoAwardLovVO";
    } else
    ArrayList arraylist = new ArrayList(1);
    arraylist.add("getDefaultAwardId");
    Number number3 = (Number)executeServerCommand(oapagecontext, oapagecontext.getApplicationModule(oawebbean), "CheckoutLovSvrCmd", arraylist);
    if(isLoggingEnabled(oapagecontext, 1))
    logParam(this, oapagecontext, "defaultAwardId", number3, 1);
    if(number.equals(number3))
    s = "ExpenditureTypeWithDefaultAwardLovVO";
    OAViewObject oaviewobject = (OAViewObject)oapagecontext.getApplicationModule(oawebbean).findViewObject("ExpenditureTypeWithDefaultAwardLovVO");
    oaviewobject.setWhereClauseParam(0, number1);
    oaviewobject.setWhereClauseParam(1, number2);
    } else
    s = "ExpenditureTypeWithAwardLovVO";
    OAViewObject oaviewobject1 = (OAViewObject)oapagecontext.getApplicationModule(oawebbean).findViewObject("ExpenditureTypeWithAwardLovVO");
    oaviewobject1.setWhereClauseParam(0, number);
    if(isLoggingEnabled(oapagecontext, 1))
    logMsg(this, oapagecontext, "VO used in ExpenditureTypeLovCO.java:", 1);
    logParam(this, oapagecontext, "voName", s, 1);
    OAMessageStyledTextBean oamessagestyledtextbean = (OAMessageStyledTextBean)oawebbean.findIndexedChildRecursive("ExpenditureType");
    oamessagestyledtextbean.setViewUsageName(s);
    OAMessageStyledTextBean oamessagestyledtextbean1 = (OAMessageStyledTextBean)oawebbean.findIndexedChildRecursive("StartDate");
    oamessagestyledtextbean1.setViewUsageName(s);
    OAMessageStyledTextBean oamessagestyledtextbean2 = (OAMessageStyledTextBean)oawebbean.findIndexedChildRecursive("EndDate");
    oamessagestyledtextbean2.setViewUsageName(s);
    OAFormValueBean oaformvaluebean = (OAFormValueBean)oawebbean.findIndexedChildRecursive("ReqAwardId");
    oaformvaluebean.setViewUsageName(s);
    OAFormValueBean oaformvaluebean1 = (OAFormValueBean)oawebbean.findIndexedChildRecursive("ProjectId");
    oaformvaluebean1.setViewUsageName(s);
    OAFormValueBean oaformvaluebean2 = (OAFormValueBean)oawebbean.findIndexedChildRecursive("TaskId");
    oaformvaluebean2.setViewUsageName(s);
    ((OAListOfValuesBean)oawebbean).setViewUsageName(s);
    public void processFormRequest(OAPageContext oapagecontext, OAWebBean oawebbean)
    super.processFormRequest(oapagecontext, oawebbean);
    ==========================================================================================

    Hi, I will try to look into the issue. I have also done customizations like this in past.
    To achieve this, we must read the Process request of CO properly and understand the places, where you have to make changes. In my case, I identify such places and also I couldn't extend the controller class. SO I took the code from standard CO, changed it at couple of places and created a class file with same code as standard CO but with changed at some places. After that I gave newly created CO name in personalization property, so that the page will follow newly created custom CO.
    So I would suggest to read the CO properly, to understand which line is doing what......

  • Need help in clearing string buffer during dynamic VO where clause in oaf

    Hi All,
    I am dynamically setting where clause in OAF using string buffer, but the issue is when i am executing the vo multiple times so the old data in the string buffer it is not clearing .so every time my where clause adding to the query and it is erroring out, please help me how to clear string buffer class in oaf.
    Thnaks

    Hi,
    Could you please share the code segment for reference. Then we can tell the solution.
    Regards,
    Tarun

  • Date functions in WHERE clause? HELP

    The following two queries are identical except for how I supply the date values in the where clause, yet the first query using the a custom my_date function runs 30x slower than the one using the TO_DATE() function. Both return DATE types...any reason for the difference?
    SELECT * from outcomes
    WHERE start_time >=fn_my_date('START_MONTH')
    AND start_time < fn_my_date('END_MONTH')+1
    -- This runs 30x faster--
    SELECT * from outcomes
    WHERE start_time >=TO_DATE('08/01/2001','MM/DD/YYYY')
    AND start_time < TO_DATE('08/31/2001','MM/DD/YYYY')+1
    On the flip side, I've also experienced queries running slower using the TO_DATE() function vs the LAST_DAY(sysdate) for equivalenet dates.
    null

    I haven't seen the message coming up when using LENGTH or SUBSTR, but every time I connect to a database or attempt to change my preferences (including the "NLS Parameters: Comp" preference), this appears.
    You are attempting to set the preference you should be to switch this from ANSI to something else, but SQL Developer is ignoring the preference setting (which I think is a bug).
    A way to set the NLS_COMP to something else is to use something like "alter session set nls_comp = BINARY;". Note that changing any preference after that appears to overwrite this and you need to do this for each new connection you start.

  • Help:alternate for calling function in where clause

    Hi ,
    In below query i'm calling function in where clause to avoid COMPLETE status records,due to this query taking 700 secs to return result.If i'm remove below function condition it's returning results with in 5 secs.Can you some one advice to any alternate idea for this?
    WHERE mark_status != 'COMPLETE'
    SELECT assessment_school,
      subject,
      subject_option,
      lvl,
      component,mark_status,
      mark_status
      NULL AS grade_status,
      NULL AS sample_status,
      :v_year,
      :v_month,
      :v_formated_date,
      :v_type,
      cand_lang
    FROM
      (SELECT assessment_school,
        subject,
        subject_option,
        lvl,
        programme,
        component,
        paper_code,
        cand_lang,
        mark_entry.get_ia_entry_status(:v_year, :v_month, assessment_school, subject_option, lvl, cand_lang, component, paper_code) AS mark_status
      FROM
        (SELECT DISTINCT ccr.assessment_school,
          ccr.subject,
          ccr.subject_option,
          ccr.lvl,
          ccr.programme,
          ccr.language AS cand_lang,
          ccr.paper_code,
          ccr.component
        FROM candidate_component_reg ccr
        WHERE ccr.split_session_year = :v_year
        AND ccr.split_session_month  = :v_month
        AND EXISTS
          (SELECT 1
          FROM IBIS.subject_component sc
          WHERE sc.year          = ccr.split_session_year
          AND sc.month           = ccr.split_session_month
          AND sc.paper_code      = ccr.paper_code
          AND sc.assessment_type = 'INTERNAL'
          AND sc.subject_option NOT LIKE '%self taught%'
          AND sc.component NOT IN ('PERFORMANCE  PRODUCTION','PRESENTATION WORK','REFLECTIVE PROJECT','SPECIAL SYLLABUS INT. ASSESSMENT')
        AND NVL(ccr.withdrawn,'N') = 'N'
        AND ccr.mark_status       != 'COMPLETE'
        AND EXISTS
          (SELECT 1
          FROM school s
          WHERE s.school_code   = ccr.assessment_school
          AND s.training_school = 'N'
    WHERE mark_status != 'COMPLETE';

    One thing you can test quickly is to put the function call in it's own select ...from dual.
    This might make a difference.
    However, only you can check this, I don't have your tables or data.
    So, what happens if you use:
        paper_code,
        cand_lang,
      (select mark_entry.get_ia_entry_status(:v_year, :v_month, assessment_school, subject_option, lvl, cand_lang, component, paper_code) from dual ) AS mark_status
      FROM
        (SELECT DISTINCT ccr.assessment_school,  --<< is the DISTINCT really needed?
          ccr.subject,
          ccr.subject_option,
    ...Also, try to find out the purpose of that above DISTINCT, is it really needed or is there some join missing?

  • My function in where clause? help me please.

    hello friends, I need to call my function in where clause as dummy example below:
    declare
    name_ table1.name%type;
    function return_id(id number) return number is
    begin
    return 1;
    end return_id;
    begin
    select name into name_
    from table1
    where id = return_id(table1.id);
    end;
    raise exception: 'the function doesn't used in where clause'. why????

    -- CREATING A FUNCTION AVAILABLE THROUGH A PACKAGE SPEC.
    SQL> ed
    Wrote file afiedt.buf
      1  create package mypackage is
      2    function myfunc(p_val NUMBER) RETURN NUMBER;
      3* end;
    SQL> /
    Package created.
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace package body mypackage is
      2    function myfunc(p_val NUMBER) RETURN NUMBER IS
      3    begin
      4      RETURN (p_val*p_val)-1;
      5    end;
      6* end;
    SQL> /
    Package body created.
    SQL> declare
      2    v_myval NUMBER := 2;
      3  begin
      4    select mypackage.myfunc(v_myval)
      5    into   v_myval
      6    from   dual;
      7    dbms_output.put_line(v_myval);
      8    select mypackage.myfunc(v_myval)
      9    into   v_myval
    10    from   dual;
    11    dbms_output.put_line(v_myval);
    12  end;
    13  /
    3
    8
    PL/SQL procedure successfully completed.
    -- CREATING A STANDALONE DATABASE FUNCTION.
    SQL> create or replace function myfunc2(p_val number) return number is
      2  begin
      3    return (p_val*2)+1;
      4  end;
      5  /
    Function created.
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_myval NUMBER := 2;
      3  begin
      4    select myfunc2(v_myval)
      5    into    v_myval
      6    from dual;
      7    dbms_output.put_line(v_myval);
      8    select myfunc2(v_myval)
      9    into    v_myval
    10    from dual;
    11    dbms_output.put_line(v_myval);
    12* end;
    SQL> /
    5
    11
    PL/SQL procedure successfully completed.
    -- CREATING A LOCAL FUNCTION IN THE ANONYMOUS PL/SQL BLOCK
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_myval NUMBER := 2;
      3    function myfunc3(p_val number) return number is
      4    begin
      5      return (p_val*p_val*p_val);
      6    end;
      7  begin
      8    select myfunc3(v_myval)
      9    into    v_myval
    10    from dual;
    11    dbms_output.put_line(v_myval);
    12    select myfunc3(v_myval)
    13    into    v_myval
    14    from dual;
    15    dbms_output.put_line(v_myval);
    16* end;
    SQL> /
      select myfunc3(v_myval)
    ERROR at line 8:
    ORA-06550: line 8, column 10:
    PLS-00231: function 'MYFUNC3' may not be used in SQL
    ORA-06550: line 8, column 10:
    PL/SQL: ORA-00904: : invalid identifier
    ORA-06550: line 8, column 3:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 12, column 10:
    PLS-00231: function 'MYFUNC3' may not be used in SQL
    ORA-06550: line 12, column 10:
    PL/SQL: ORA-00904: : invalid identifier
    ORA-06550: line 12, column 3:
    PL/SQL: SQL Statement ignored
    SQL>As you can see (and as previously mentioned by someone else) the function has to be available to the SQL engine either via a datavbase package or as a database function. If you declare the function locally within the anonymous PL/SQL block then the function only exists in the scope of that PL/SQL block and thus when your SQL statement is sent to the SQL engine for execution, the SQL engine can't see it.
    ;)

  • Help: how to make this WHERE CLAUSE?

    Hi,
    SELECT * FROM TAB_A
    WHERE
         FLG IN (DECODE(C_FLG, 0, 'C', 1, '''A'', ''I'''));
    What I really want to achieve is:
    If C_FLG is 0 then the where clause becomes
    WHERE FLG IN ('C')
    If C_FLG is 1 then the where clause becomes
    WHERE FLG IN ('A', 'I')
    Any suggestions?
    Thank you in advance.
    Jimmy

    How about:
    WHERE (C_FLG = 0 AND FLG = 'C') OR (C_FLG = 1 AND FLG IN ('A','I'))

  • Help with Get-EventLog and where clause

    I am trying to display a list of event IDs 1123 for the past 24 hours from Server1 using Get-EvenLog.
    Using the script below I get a list of all events 1123, can someone assist with incorporating $date =  Get-Date  $date = AddDays(-1) to where clause ?
    Get-EventLog -LogName $logName -ComputerName Server1 | where {$_.eventID -eq 1123} | fl -Property timegenerated, replacementstrings, message
    Thanks

    I also want to get the events emailed to me so I added the following, but the script seems to be getting stuck at the $msgbody line. Is this not the right way to send email?
    $date =  (Get-Date).AddDays(-1)
    $msgbody = Get-EventLog
    -LogName $logname -ComputerName hqdbsp18
    | where {$_.eventID
    -eq 1123 -and $_.timegenerated
    -gt $date} | fl
    -Property timegenerated, replacementstrings, message
    send-MailMessage -To "[email protected]" -from "[email protected]" -Subject "events from the past 24 hours" -body $msgbody -SmtpServer
    mysmtpserver

  • HELP: WHERE Clause based on value of the column

    I am selecting from a table as follows and want to have a where condition that is dependent of the value of the column, type of the current row.
    CREATE TABLE tbl (INT id, VARCHAR type, VARCHAR comment)
    I have 3 different values for the type column, EMPLOYEE, CUSTOMER, SUPPLIER. What I want is to have a where clause in my select that is based on the value of type.
    I tried the following but was not successful..
    SELECT * from tbl
    CASE
    WHEN type = 'EMPLOYEE' THEN
    WHERE comment LIKE '%employee%'
    WHEN type = 'CUSTOMER' THEN
    WHERE comment LIKE '%customer%'
    WHEN type = 'SUPPLIER' THEN
    WHERE comment LIKE '%supplier%'
    END
    I am not proficient with stored procedures so if you could please tell me how to do it with straight query, I would greatly appreciated it..
    Thank you,

    Or maybe this:
    SELECT *
      FROM tbl
    WHERE "COMMENT" LIKE
              CASE TYPE
                 WHEN 'EMPLOYEE'
                    THEN '%employee%'
                 WHEN 'CUSTOMER'
                    THEN '%customer%'
                 WHEN 'SUPPLIER'
                    THEN '%supplier%'
              END

Maybe you are looking for

  • Ipod cannot be synced. The required file cannot be found

    Up until recently, the only thing there was wrong with my Ipod was the occasionally "100% freeze that only could be solved by draining the Ipod from battery", which it did less than three times a month. Then this sunday, when I was going to work (nig

  • Hp pavilion p7-1167c windows 7 64bit

    Boots up most of the time with a "Default" desktop. File folders etc. are no longer on desktop but appear in program list. Fire Fox browser is in default with no saved information. Sometimes after various restore operations my regular desktop appears

  • Cannot sync with windows vista pc ?

    Tried all tips in help sections but still cannot sync !

  • Maximum number of pages and links in an InDesign Document

    We have an InDesign document that is 79 pages, and contains about 700 image links and 700 text links. The links in total are about 7GB (most text documents are 2-6K; images could be anywhere from 1 to 50MB). the InDesign document is 220MB. If we hous

  • E-mail signature does not appear in recipient's e-mail

    I send e-mails with a detailed footer that is not appearing in the recipients e-mail. My footer includes contact information, an image and a legal disclaimer. What causes this and how do I remedy it? Eric