Explain working of query

Hallow all....Kindly help working of this query
Delete from student where rowid not in(select min(rowid) from student group by stud_name).
is it work for duplication deletetion?

is it work for duplication deletetion?yes
for sql/plsql - PL/SQL

Similar Messages

  • How to force Work Item Query Policy to refresh its cached query results?

    I have enabled the Work Item Query Policy on my TFS project.  It works as expected, except when using Visual Studio 2013 with the following sequence of steps:
    User selects Check in Pending Changes from the Source Control Explorer
    User enters in the ID of the work item to be associated to the changeset
    User clicks the Check In button
    Work Item Query Policy displays message ' Work item ##### was not found in the results of stored query...'
    User realizes his mistake, and modifies (and saves) the work item so that it is returned in in the query result set
    User clicks the Check In button again expecting the TFS policy to accept the association
    Work Item Query Policy still displays message ' Work item ##### was not found in the results of stored query...'
    Removing the Work Item and re-associating it does not make a difference.  The only workaround that I have found is to close Visual Studio and reopen it.  Does any one have a better solution than this?

    Our setup is different from the one you are using:
    - User is using VS 2013 Update 4.
    - We are running TFS 2010 SP1
    The test case that you described is different from the one that is causing my problem (that scenario works fine for me as well).  I am trying to associate the check in to the same work item both times; whereas, you are associating it to a different
    work item the second time.  I can consistently reproduce the error using the following steps:
    1) Create a query that returns All Bugs in Active state, and set it as the query for the Work Item Query Policy
    2) Create and save a new Bug
    3) Run the query to confirm that the new bug does not appear in the result set
    4) Checkout a file, modify it, save it
    5) Check in the file and associate it to the bug from step 2)
    - the Work Item Query Policy will issue an error message saying that the work item cannot be found in the associated query
    6) Change the state of the bug to Active, and save
    7) Refresh the query to confirm that the bug now appears in the result set
    8) Check in the file again
    - error message from step 5) will not go away

  • Can you please explain how this query is fetching the rows?

    here is a query to find the top 3 salaries. But the thing is that i am now able to understand how its working to get the correct data :How the data in the alias table P1 and P2 getting compared. Can you please explain in some steps.
    SELECT MIN(P1.SAL) FROM PSAL P1, PSAL P2
    WHERE P1.SAL >= P2.SAL
    GROUP BY P2.SAL
    HAVING COUNT (DISTINCT P1.SAL) <=3 ;
    here is the data i used :
    SQL> select * from psal;
    NAME SAL
    able 1000
    baker 900
    charles 900
    delta 800
    eddy 700
    fred 700
    george 700
    george 700
    Regards,
    Renu

    ... Please help me in understanding the query.
    Your query looks like anything but a Top-N query.
    If you run it in steps and analyze the output at the end of each step, then you should be able to understand what it does.
    Given below is some brief information on the same:
    test@ora>
    test@ora> --
    test@ora> -- Query 1 - using the non-equi (theta) join
    test@ora> --
    test@ora> with psal as (
      2    select 'able' as name, 1000 as sal from dual union all
      3    select 'baker',   900 from dual union all
      4    select 'charles', 900 from dual union all
      5    select 'delta',   800 from dual union all
      6    select 'eddy',    700 from dual union all
      7    select 'fred',    700 from dual union all
      8    select 'george',  700 from dual union all
      9    select 'george',  700 from dual)
    10  --
    11  SELECT p1.sal AS p1_sal, p1.NAME AS p1_name, p2.sal AS p2_sal,
    12         p2.NAME AS p2_name
    13    FROM psal p1, psal p2
    14   WHERE p1.sal >= p2.sal;
        P1_SAL P1_NAME     P2_SAL P2_NAME
          1000 able          1000 able
          1000 able           900 baker
          1000 able           900 charles
          1000 able           800 delta
          1000 able           700 eddy
          1000 able           700 fred
          1000 able           700 george
          1000 able           700 george
           900 baker          900 baker
           900 baker          900 charles
           900 baker          800 delta
           900 baker          700 eddy
           900 baker          700 fred
           900 baker          700 george
           900 baker          700 george
           900 charles        900 baker
           900 charles        900 charles
           900 charles        800 delta
           900 charles        700 eddy
           900 charles        700 fred
           900 charles        700 george
           900 charles        700 george
           800 delta          800 delta
           800 delta          700 eddy
           800 delta          700 fred
           800 delta          700 george
           800 delta          700 george
           700 eddy           700 eddy
           700 eddy           700 fred
           700 eddy           700 george
           700 eddy           700 george
           700 fred           700 eddy
           700 fred           700 fred
           700 fred           700 george
           700 fred           700 george
           700 george         700 eddy
           700 george         700 fred
           700 george         700 george
           700 george         700 george
           700 george         700 eddy
           700 george         700 fred
           700 george         700 george
           700 george         700 george
    43 rows selected.
    test@ora>
    test@ora>This query joins PSAL with itself using a non equi-join. Take each row of PSAL p1 and see how it compares with PSAL p2. You'll see that:
    - Row 1 with sal 1000 is >= to all sal values of p2, so it occurs 8 times
    - Row 2 with sal 900 is >= to 9 sal values of p2, so it occurs 7 times
    - Row 3: 7 times again... and so on.
    - So, total no. of rows are: 8 + 7 + 7 + 5 + 4 + 4 + 4 + 4 = 43
    test@ora>
    test@ora> --
    test@ora> -- Query 2 - add the GROUP BY
    test@ora> --
    test@ora> with psal as (
      2    select 'able' as name, 1000 as sal from dual union all
      3    select 'baker',   900 from dual union all
      4    select 'charles', 900 from dual union all
      5    select 'delta',   800 from dual union all
      6    select 'eddy',    700 from dual union all
      7    select 'fred',    700 from dual union all
      8    select 'george',  700 from dual union all
      9    select 'george',  700 from dual)
    10  --
    11  SELECT p2.sal AS p2_sal,
    12         COUNT(*) as cnt,
    13         COUNT(p1.sal) as cnt_p1_sal,
    14         COUNT(DISTINCT p1.sal) as cnt_dist_p1_sal,
    15         MIN(p1.sal) as min_p1_sal,
    16         MAX(p1.sal) as max_p1_sal
    17    FROM psal p1, psal p2
    18   WHERE p1.sal >= p2.sal
    19  GROUP BY p2.sal;
        P2_SAL        CNT CNT_P1_SAL CNT_DIST_P1_SAL MIN_P1_SAL MAX_P1_SAL
           700         32         32               4        700       1000
           800          4          4               3        800       1000
           900          6          6               2        900       1000
          1000          1          1               1       1000       1000
    test@ora>
    test@ora>Now, if you group by p2.sal in the output of query 1, and check the number of distinct p1.sal, min of p1.sal etc. you see that for p2.sal values - 800, 900 and 1000, there are 3 or less p1.sal values associated.
    So, the last 3 rows are the ones you are interested in, essentially. As follows:
    test@ora>
    test@ora> --
    test@ora> -- Query 3 - GROUP BY and HAVING
    test@ora> --
    test@ora> with psal as (
      2    select 'able' as name, 1000 as sal from dual union all
      3    select 'baker',   900 from dual union all
      4    select 'charles', 900 from dual union all
      5    select 'delta',   800 from dual union all
      6    select 'eddy',    700 from dual union all
      7    select 'fred',    700 from dual union all
      8    select 'george',  700 from dual union all
      9    select 'george',  700 from dual)
    10  --
    11  SELECT p2.sal AS p2_sal,
    12         COUNT(*) as cnt,
    13         COUNT(p1.sal) as cnt_p1_sal,
    14         COUNT(DISTINCT p1.sal) as cnt_dist_p1_sal,
    15         MIN(p1.sal) as min_p1_sal,
    16         MAX(p1.sal) as max_p1_sal
    17    FROM psal p1, psal p2
    18   WHERE p1.sal >= p2.sal
    19  GROUP BY p2.sal
    20  HAVING COUNT(DISTINCT p1.sal) <= 3;
        P2_SAL        CNT CNT_P1_SAL CNT_DIST_P1_SAL MIN_P1_SAL MAX_P1_SAL
           800          4          4               3        800       1000
           900          6          6               2        900       1000
          1000          1          1               1       1000       1000
    test@ora>
    test@ora>
    test@ora>That's what you are doing in that query.
    The thing is - in order to find out Top-N values, you simply need to scan that one table PSAL. So, joining it to itself is not necessary.
    A much simpler query is as follows:
    test@ora>
    test@ora>
    test@ora> --
    test@ora> -- Top-3 salaries - distinct or not; using ROWNUM on ORDER BY
    test@ora> --
    test@ora> with psal as (
      2    select 'able' as name, 1000 as sal from dual union all
      3    select 'baker',   900 from dual union all
      4    select 'charles', 900 from dual union all
      5    select 'delta',   800 from dual union all
      6    select 'eddy',    700 from dual union all
      7    select 'fred',    700 from dual union all
      8    select 'george',  700 from dual union all
      9    select 'george',  700 from dual)
    10  --
    11  SELECT sal
    12  FROM (
    13    SELECT sal
    14      FROM psal
    15    ORDER BY sal DESC
    16  )
    17  WHERE rownum <= 3;
           SAL
          1000
           900
           900
    test@ora>
    test@ora>
    test@ora>And for Top-3 distinct salaries:
    test@ora>
    test@ora> --
    test@ora> -- Top-3 DISTINCT salaries; using ROWNUM on ORDER BY on DISTINCT
    test@ora> --
    test@ora> with psal as (
      2    select 'able' as name, 1000 as sal from dual union all
      3    select 'baker',   900 from dual union all
      4    select 'charles', 900 from dual union all
      5    select 'delta',   800 from dual union all
      6    select 'eddy',    700 from dual union all
      7    select 'fred',    700 from dual union all
      8    select 'george',  700 from dual union all
      9    select 'george',  700 from dual)
    10  --
    11  SELECT sal
    12  FROM (
    13    SELECT DISTINCT sal
    14      FROM psal
    15    ORDER BY sal DESC
    16  )
    17  WHERE rownum <= 3;
           SAL
          1000
           900
           800
    test@ora>
    test@ora>
    test@ora>You may also want to check out the RANK and DENSE_RANK analytic functions.
    RANK:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions123.htm#SQLRF00690
    DENSE_RANK:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions043.htm#SQLRF00633
    HTH
    isotope

  • Can someone explain this crazy query optimisation?

    A software company has me trialling a product that has a query optimiser. I can't for the life of me explain what is going on below and would like some help from someone with a bit more SQL experience. I have a query I've been struggling to bring down the time on:
    CREATE OR REPLACE VIEW PLATE_STATS_DATA_VIEW AS
    SELECT P.Folder_ID, P.expt_or_control_ID, P.Plate_Type, P.Dose_Weight, P.Volume, P.Strain_Code, P.S9_Plus,
    P.type_Name as Contents, P.Replicate_ID,
    P.Number_Of_Plates, round(avg(P.count)) as mean_count,
    min(P.count) as min_count, max(P.count) as max_count, count(P.count) as Plates_Counted
    FROM expt_folder_plates P, History_Control_Log L
    WHERE P.expt_or_control_ID = L.Control_ID
    AND P.Strain_Code = L.Strain_Code
    AND P.Plate_Type = L.Type_Code
    AND P.S9_Plus = L.S9_Plus
    AND L.control_Included > 0
    GROUP BY P.Folder_ID, P.expt_or_control_ID, P.Plate_Type, P.Dose_Weight, P.Volume, P.Strain_Code,
    P.S9_Plus, P.type_Name, P.Replicate_ID, P.Number_Of_PlatesIt took 20 seconds on my large test database, so I put it through the optimiser. It took it down to 0.1 seconds simply by changing 'WHERE P.expt_or_control_ID = L.Control_ID' to 'WHERE P.expt_or_control_ID = L.Control_ID + 0'.
    I have no idea why this would make any difference - adding zero to a value?! Can anyone enlighten me?
    Many thanks,
    Gary
    Message was edited by:
    GaryKyle

    Ahhh, thanks guys. I'm a bit of a beginner here. This is my first look at explain plans - just had to work out how to see them! I think I understand what is happening now - it looks like that with the index, it does the group by FIRST on all the data and this takes a large amount of time. Am I right?
    Before +0:
    SELECT STATEMENT, GOAL = ALL_ROWS               Cost=162787Cardinality=1380965Bytes=328669670
    SORT GROUP BY               Cost=162787     Cardinality=1380965     Bytes=328669670
      HASH JOIN               Cost=16773     Cardinality=1380965     Bytes=328669670
       TABLE ACCESS FULL     Object owner=PI_AMES_BIG     Object name=EXPT_FOLDER_DETAILS     Cost=29Cardinality=4038Bytes=387648
       HASH JOIN               Cost=16730     Cardinality=1380965     Bytes=196097030
        TABLE ACCESS FULL     Object owner=PI_AMES_BIG     Object name=AMES_PLATE_TYPES     Cost=2Cardinality=6Bytes=192
        HASH JOIN               Cost=16715     Cardinality=1380965     Bytes=151906150
         TABLE ACCESS FULL     Object owner=PI_AMES_BIG     Object name=HISTORY_CONTROL_LOG     Cost=2Cardinality=40Bytes=880
         HASH JOIN               Cost=16694     Cardinality=2002400     Bytes=176211200
          HASH JOIN               Cost=59     Cardinality=8076     Bytes=282660
           TABLE ACCESS FULL     Object owner=PI_AMES_BIG     Object name=EXPT_FOLDER_SOLVENTSCost=2Cardinality=3Bytes=51
           TABLE ACCESS FULL     Object owner=PI_AMES_BIG     Object name=CONTROLSCost=56Cardinality=8078Bytes=145404
          TABLE ACCESS FULL     Object owner=PI_AMES_BIGObject name=EXPT_FOLDER_PLATESCost=16584Cardinality=5499657Bytes=291481821After +0:
    SELECT STATEMENT, GOAL = ALL_ROWS               Cost=1655     Cardinality=138     Bytes=45954
    HASH JOIN               Cost=1655     Cardinality=138     Bytes=45954
      HASH JOIN               Cost=1625     Cardinality=138     Bytes=33672
       HASH JOIN               Cost=1569     Cardinality=414     Bytes=96462
        MERGE JOIN CARTESIAN     Cost=4          Cardinality=18     Bytes=630
         TABLE ACCESS FULL          Object owner=PI_AMES_BIG     Object name=EXPT_FOLDER_SOLVENTSCost=2Cardinality=3Bytes=30
         BUFFER SORT          Cost=2     Cardinality=6     Bytes=150
          TABLE ACCESS FULL          Object owner=PI_AMES_BIG     Object name=AMES_PLATE_TYPESCost=1     Cardinality=6Bytes=150
        VIEW               Object owner=PI_AMES_BIG     Object name=TEST_PLATE_STATSCost=1564Cardinality=138Bytes=27324
         SORT GROUP BY               Cost=1564     Cardinality=138     Bytes=10350
          TABLE ACCESS BY INDEX ROWID     Object owner=PI_AMES_BIGObject name=EXPT_FOLDER_PLATESCost=39Cardinality=3Bytes=159
           NESTED LOOPS               Cost=1563     Cardinality=138     Bytes=10350
            TABLE ACCESS FULL     Object owner=PI_AMES_BIG     Object name=HISTORY_CONTROL_LOG     Cost=2Cardinality=40Bytes=880
            INDEX RANGE SCAN     Object owner=PI_AMES_BIG     Object name=EXPT_CONTROL_ID_INDEXCost=5Cardinality=248     
       TABLE ACCESS FULL     Object owner=PI_AMES_BIG     Object name=CONTROLSCost=56     Cardinality=8078Bytes=88858
      TABLE ACCESS FULL     Object owner=PI_AMES_BIG     Object name=EXPT_FOLDER_DETAILS     Cost=29     Cardinality=4038Bytes=359382Thanks again,
    Gary
    P.S. looks like the explain plan's made the post horribly wide again ;) sorry. I'll keep it this way though otherwise the plan is hard to read.

  • Can any body explain me this query?   select 'alter index '||index_name||' monitoring usage' as index_monitor from user_indexes where index_name='EMP';

    Initially i've a put an index of emp table in monitoring state..
    later i've got this query
    select 'alter index '||index_name||' monitoring usage' as index_monitor from user_indexes where index_name='EMP';
    can any body explain me what is the meaning of this query...
    and how do that query in the strings of projection area works....
    i'm totally confused
    thank you in advance.

    This is referred to as SQL generating SQL.  It is most useful when you  need to generate SQL statements for all indexes or indexes for one user.  After generating the text you then would execute it in SQLPlus or the tool of your choice.  If you combine this with a spool statement, SPOOL MyGeneratedScript.SQL you can run it with @MyGeneratedScript in SQLPlus.  I combine this into a script which generates the file, calls the editor so you can look it over and then executes it.  Here is an example of moving indexes to a different tablespace.
    -- UTL_Move_Indexs_To_New_TableSpace_Script.SQL
    /* This script will grab all the tables out of the specified source tablespace
    ** and move them into the specified target tablespace.  Ensure the the target
    ** exists and has sufficient room.  You must be logged in as the table owner.
    ACCEPT v_source_tablespace_name PROMPT 'Enter source tablespace name: '
    ACCEPT v_target_tablespace_name PROMPT 'Enter target tablespace name: '
    SET HEADING OFF
    SET FEEDBACK OFF
    SET TERMOUT OFF
    SET ECHO OFF
    SPOOL _move_index.SQL
    SELECT    'ALTER INDEX '
           || ndx.owner
           || '.'
           || ndx.index_name
           || CHR (10)
           || 'REBUILD '
           || CHR (10)
           || 'TABLESPACE '
           || UPPER ('&v_target_tablespace_name')
           || ';'
             sql_statement
    FROM   dba_indexes ndx
    WHERE      ndx.tablespace_name = UPPER ('&v_source_tablespace_name')
           AND ndx.index_type <> 'LOB'
    ORDER BY ndx.owner,
             ndx.index_name;
    SPOOL OFF
    --Edit the move script
    EDIT _move_index
    --Reset parameters.
    SET TERMOUT ON
    PAUSE Hit Ctrl+C to ABORT, any key to CONTINUE,
    -- Run the move script
    SPOOL  Move_Indexs_To_New_TableSpace.LOG
    @_move_index
    SPOOL OFF
    --Reset parameters.
    SET TERMOUT on
    SET FEEDBACK on
    SET HEADING on
    Marcus Baocn

  • Minus and - not working in query

    Hi all,
    I am operating on 10G R/2.
    I have thsi query where thi sstatement <pre>(COUNT(W_O) - COUNT(W_I))</pre> TOTAL is returning 0.Why is the minus and '-' not working out in this query?.
    <Pre>
    SELECT
    TRUNC(DT) week_start ,
    next_day (TRUNC( DT) - 7, 'Sunday' ) + 6 week_end ,
    to_number(to_char(DT,'FMWW'))wk_no ,
    'I_'||W_I AS IO ,
    COUNT(W_I) TOTAL
    FROM TABLE_A
    WHERE W_I IS NOT NULL
    GROUP BY TRUNC(DT),
    next_day (TRUNC( DT) - 7, 'Sunday' ) + 6,
    to_number(to_char(DT,'FMWW')),
    'I_'||W_I
    UNION ALL
    SELECT
    TRUNC(DT) week_start ,
    next_day (TRUNC( DT) - 7, 'Saturday' ) + 6 week_end ,
    to_number(to_char(DT,'FMWW'))wk_no ,
    'O_'||W_O AS IO,
    (COUNT(W_O) - COUNT(W_I)) TOTAL
    FROM TABLE_A
    WHERE W_O IS NOT NULL
    GROUP BY
    TRUNC(DT),
    to_number(to_char(DT,'FMWW')), 'O_'||W_O
    </pre>
    Edited by: CrackerJack on Jun 14, 2011 8:06 PM

    basic maths
    SQL> select count(object_name), count(owner), count(object_name) - count(owner)
      2    from all_objects;
    COUNT(OBJECT_NAME) COUNT(OWNER) COUNT(OBJECT_NAME)-COUNT(OWNER)
                 52658        52658                               0
    1 row selected.if you take away a number from itself you will get zero. I think you may mean SUM() rather than COUNT()

  • Work Order Query

    Hello Experts,
    I have a query for work order.
    1) if parts have been reserved in a work order, what is the method of converting those parts to confirmations?
    2) Is there any report which shows parts that have been reserved on work orders ? Or any way to see this?
    Regards
    Himanshu

    Hi,
    For reservation confirmations got to IW42, it will automatically take movement type 261.
    For reservations, goto IW40 and select layout view, there you will get option for Reservations.
    Hope it is helpful.
    Thanks

  • Selection screen field not working in Query

    Hi Gurus!
    I have a small problem with one of my query that I just created for finding status of our customers. I have a code section which handles it all . The problem is that I ahve a user field called "Check date" which I ahve used in selection screen as well as the layout, when I put a value in this field in the selection screen the report dosent give any output " NO data to display" but when I leave it open it does give me the out put with the saem check date as I ahd entered earlier in my selection screen.
    I am not sure where my selection code is working wrong . Could anyone please help me out please.
    DATA: ls_vakpa LIKE vakpa.
    DATA old_date LIKE sy-datum.
    old_date = key_date - num_days.
    status = 'ACTIVE'.
    check_date = old_date.
    * (If I entere this field (check_date) with any date
    *  and run it does not give me output and without
    * entry it dioes give output.
      SELECT SINGLE * FROM vakpa INTO ls_vakpa
          WHERE kunde = kna1-kunnr
       AND audat > old_date.
          IF sy-subrc <> 0.
        SELECT SINGLE * FROM vakpa INTO ls_vakpa
            WHERE kunde = kna1-kunnr
          AND audat < old_date.
          IF sy-subrc = 0.
          ls_audat = ls_vakpa-audat.
          ls_vbeln = ls_vakpa-vbeln.
        ELSE.
          CLEAR ls_audat.
          clear ls_vbeln.
        ENDIF.
        status = 'INACTIVE'.
      ELSE.
        ls_audat = ls_vakpa-audat.
        ls_vbeln = ls_vakpa-vbeln.
      ENDIF.
    Edited by: Rob Burbank on Apr 7, 2010 12:08 PM

    DATA: ls_vakpa LIKE vakpa.
    DATA old_date LIKE sy-datum.
    old_date = key_date - num_days.
    status = 'ACTIVE'.
    check_date = old_date.
    if old_date is initial.
       old_date = key_date - num_days.
       check_date = old_date.
    endif.
      SELECT SINGLE * FROM vakpa INTO ls_vakpa
          WHERE kunde = kna1-kunnr
    *      AND audat > old_date.
        AND audat > check_date.
      IF sy-subrc <> 0.
        SELECT SINGLE * FROM vakpa INTO ls_vakpa
            WHERE kunde = kna1-kunnr
    *        AND audat < old_date.
          AND audat < check_date.
        IF sy-subrc = 0.
          ls_audat = ls_vakpa-audat.
          ls_vbeln = ls_vakpa-vbeln.
        ELSE.
          CLEAR ls_audat.
          clear ls_vbeln.
        ENDIF.
        status = 'INACTIVE'.
      ELSE.
        ls_audat = ls_vakpa-audat.
        ls_vbeln = ls_vakpa-vbeln.
      ENDIF.

  • Date object doesn't work in query filters

    I'm trying to create a universe object called Next Biweekly Pay End Date.  Some background: there is an end date for our biweekly payrolls every 14 days, and the logic behind the object is basically that if there was a biweekly pay end date 7 days ago, the next one is 7 days from today (that is, sysdate + 7), etc.</p>
    I have it working so that it displays the correct date when used in a WebI report.  However, when I use it in a query filter in a WebI report (like, Pay End Date = Next Biweekly Pay End Date), I don't get an error, but I also don't get any data.  Somehow my object doesn't work in a query filter.  The purpose of the object is for use in query filters, so I need to get this to work.</p>
    My best guess about why it doesn't work in a query filter is due to some issue with the data type.  Pay End Date has a data type of date in the universe.  I gave Next Biweekly Pay End Date a data type of date also, but the query filter still doesn't work; I get "no data to fetch."</p>
    We're using XI 3.1.6 and Oracle 10.  Any ideas about how to get this to work?</p>
    If it helps, here is the definition of Next Biweekly Pay End Date.  The logic is that it takes today's date, subtracts Oct. 31, 2009 (a biweekly pay end date), divides by 14, and looks at the remainder.  If the remainder is 0, then today is a pay end date and the next one is 14 days from now.  If the remainder is 1, yesterday was a pay end date and the next one is 13 days from now, etc.</p>
    case</p>
      when mod((trunc(sysdate)) - (to_date('31/10/2009')),14) = 0 then (sysdate + 14)</p>
      when mod((trunc(sysdate)) - (to_date('31/10/2009')),14) = 1 then (sysdate + 13)</p>
      when mod((trunc(sysdate)) - (to_date('31/10/2009')),14) = 2 then (sysdate + 12)</p>
      when mod((trunc(sysdate)) - (to_date('31/10/2009')),14) = 3 then (sysdate + 11)</p>
      when mod((trunc(sysdate)) - (to_date('31/10/2009')),14) = 4 then (sysdate + 10)</p>
      when mod((trunc(sysdate)) - (to_date('31/10/2009')),14) = 5 then (sysdate + 9)</p>
      when mod((trunc(sysdate)) - (to_date('31/10/2009')),14) = 6 then (sysdate + 8)</p>
      when mod((trunc(sysdate)) - (to_date('31/10/2009')),14) = 7 then (sysdate + 7)</p>
      when mod((trunc(sysdate)) - (to_date('31/10/2009')),14) = 8 then (sysdate + 6)</p>
      when mod((trunc(sysdate)) - (to_date('31/10/2009')),14) = 9 then (sysdate + 5)</p>
      when mod((trunc(sysdate)) - (to_date('31/10/2009')),14) = 10 then (sysdate + 4)</p>
      when mod((trunc(sysdate)) - (to_date('31/10/2009')),14) = 11 then (sysdate + 3)</p>
      when mod((trunc(sysdate)) - (to_date('31/10/2009')),14) = 12 then (sysdate + 2)</p>
      when mod((trunc(sysdate)) - (to_date('31/10/2009')),14) = 13 then (sysdate + 1)</p>
    end

    Thanks for the suggestions.
    I did some more testing, and there seems to be something more complicated going on.  I ran the following code in SQL*Plus:
    SELECT distinct M_PYDW1.PYSTATUS.DW_OWNER,
    case
    when to_date(sysdate, 'dd/mm/yyyy hh24:mi:ss') >= to_date('01/01/2010','dd/mm/yyyy hh24:mi:ss') then To_Date((sysdate - 2),'dd/mm/yyyy')
    else to_date(sysdate +2, 'dd/mm/yyyy')
    end
    FROM M_PYDW1.PYSTATUS
    The condition should be true, because the sysdate (today is Jan. 20) is greater than 1/1/2010, so I should get a result of sysdate - 2 (Jan. 18).  But the result I get is Jan. 22 (sysdate +2).  It seems that the comparison is failing even though I'm formatting both sysdate and 1/1/2010 as dates with a timestamp.  What could cause that?
    One more mystery: when I run the same code as above in a WebI report (using custom SQL), I get the error ORA-1830, date format picture ends before converting entire input string.

  • Meaning only field does not work when querying

    Hi
    I am working with Designer 6i R4.11
    In my generated forms I have columns/fields based on "domains/lovs". The domain property "dynamic list" is set to yes and I have all my values in a cg_ref_codes table.
    Now when I am doing a query in my form and I use the lov-button of the "domain-field", the query will work fine. When I just type in the value in the field without using the lov, the query will always return all values.
    There is no trigger or code generated to fill in the database-column value in query-mode, so form a form builder point of view it makes sense.
    I have the impression this used to work years ago. Is there a property I didn't set or am I missing something?
    Thanks in advance for your help.
    Karine

    Seems to me that you need to set the display width to be wide enough for all possible meanings in the LOV, rather than wide enough for the field itself. But I may have misunderstood the question. or misremembered the answer - it has been a while.

  • Key date not work in query on infoset

    hi experts,
    i have a infoset, which includes a time-dependent infoobject eg.0employee and an ods eg. ods1
    i set the ods time-dependent by setting from ods1-field1 to ods2-field2, and link the 0employee to ods1.
    then i create a query on the infoset and set a key date in the query, eg20061231.
    but the query result goes wrong, the key date doesn't work, the result shows below:
    employ1 1000.12.31-2008.01.01   $123 (this record is right,because i want the key date to be 20061232)
    employ1 2008.01.02-9999.12.31   $123 (but this record should not be displayed)
    i haven't set any field in infoset to be key date, just set the "from" and "to".
    pls help and thanks a lot!

    Hi
    Check the link.
    http://help.sap.com/saphelp_nw04/Helpdata/EN/11/723c3b35703079e10000000a114084/content.htm
    Chandu.

  • Can You Explain This SQL Query - Inline View Included

    The query is taken from "Oracle Database 10g: SQL Fundamentals II" page 3-7 (chapter 3)
    I do not fully understand the following query:
    SELECT a.last_name, a.salary, a.department_id, b.salavg
    FROM   employees a, (SELECT   department_id,
    AVG(salary) salavg
    FROM     employees
    GROUP BY department_id) b
    WHERE  a.department_id = b.department_id
    AND    a.salary > b.salavg;
    The inline view can return several records. Can you please tell me in step by step how does this work. I understand the concept of join tables and aliases, etc. I just need to know the mechanism of this code.
    Thanks

    user11164565 wrote:
    The query is taken from "Oracle Database 10g: SQL Fundamentals II" page 3-7 (chapter 3)
    I do not fully understand the following query:
    SELECT a.last_name, a.salary, a.department_id, b.salavg
    FROM   employees a, (SELECT   department_id,
    AVG(salary) salavg
    FROM     employees
    GROUP BY department_id) b
    WHERE  a.department_id = b.department_id
    AND    a.salary > b.salavg;
    The inline view can return several records. Can you please tell me in step by step how does this work. I understand the concept of join tables and aliases, etc. I just need to know the mechanism of this code.
    The query is returning the last name, salary , department and average salary of all the departments where salary is greater than the average salary.
    HTH
    Aman....

  • Explain plan for query with variables

    Trying to Explain plan for some sql in sql*plus. The query has a variable in it. How do I do this ?
    I did look into explain plan and dbms_xplan but could not find anything with variables

    use sqlplus bind variables:
    SQL> --define variable
    SQL> var x varchar2
    SQL> -- notice the colon prefixing the variable
    SQL> explain plan for select * from customer where cid = :x;
    Explained.
    SQL> select * from table( dbms_xplan.display );
    PLAN_TABLE_OUTPUT
    Plan hash value: 1709312366
    | Id  | Operation                   | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |          |     1 |    67 |     2   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| CUSTOMER |     1 |    67 |     2   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | CID      |     1 |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("CID"=:X)
    14 rows selected.the variable does not need to be set to explain the query, since explain does not actually execute.
    Edited by: shoblock on Nov 6, 2008 4:51 PM

  • Explain plan for Query performance

    Hi Gurus,
    I need to improve the performance of a procedure. The procedure has the below QUery. I dont have Idea on how to imrpove the perf by seeing the explain plan. Can anyone please help me to explain where I need to change the code.
    The below are the code and Explain plan for the same.
    -----------Code----------------------------
    SELECT IV_STORECODE AS STORECODE,
                                   TO_CHAR(RD.ITEMCODE) AS ITEMCODE,
                                   C.ITEMCATEGORYNAME,
                                   ISUB.ITEMSUBCATEGORY1NAME
                              FROM RECEIPTS R
                             INNER JOIN RECEIPTDETAILS RD
                                ON R.RECEIPTID = RD.RECEIPTID
                             INNER JOIN ITEMCOMPANY IC
                                ON IC.ITEMCODE = RD.ITEMCODE
                             INNER JOIN ITEMCATEGORY C
                                ON IC.ITEMCATEGORY = C.ITEMCATEGORYID
                             LEFT OUTER JOIN ITEMSUBCATEGORY1 ISUB
                                ON ISUB.ITEMSUBCATEGORY1ID = IC.ITEMSUBCATEGORY1
                               AND ISUB.ITEMSUBCATEGORY1ID IN
                                   (SELECT ITEMSUBCATEGORY1ID
                                      FROM ITEMSUBCATEGORY1
                                     WHERE ITEMCATEGORYID = IV_ITEMCATEGORY)
                             INNER JOIN STORE SE
                                ON SE.STORECODE = R.STORECODE
                             WHERE R.STORECODE = IV_STORECODE
                               AND SE.HOSPITALID = IV_HOSPITALID
                               AND TRUNC(R.CREATEDDATE) BETWEEN V_FROMDATE AND
                                   V_TODATE
                               AND R.STATUSID NOT IN (99, 5)
                                  AND
                                   (IV_DRUGTYPE IS NULL OR
                                   IC.DRUGTYPECATEGORYID = IV_DRUGTYPE)
                            UNION
                            SELECT IV_STORECODE AS STORECODE,
                                   TO_CHAR(STD.ITEMCODE) AS ITEMCODE,
                                   C.ITEMCATEGORYNAME,
                                   ISUB.ITEMSUBCATEGORY1NAME
                              FROM STOCKTRANSACTION ST
                             INNER JOIN STOCKTRANSACTIONDETAILS STD
                                ON ST.STOCKTRANSACTIONID = STD.STOCKTRANSACTIONID
                             INNER JOIN ITEMCOMPANY IC
                                ON IC.ITEMCODE = STD.ITEMCODE
                             INNER JOIN ITEMCATEGORY C
                                ON IC.ITEMCATEGORY = C.ITEMCATEGORYID
                              LEFT OUTER JOIN ITEMSUBCATEGORY1 ISUB
                                ON ISUB.ITEMSUBCATEGORY1ID = IC.ITEMSUBCATEGORY1
                               AND ISUB.ITEMSUBCATEGORY1ID IN
                                   (SELECT ITEMSUBCATEGORY1ID
                                      FROM ITEMSUBCATEGORY1
                                     WHERE ITEMCATEGORYID = IV_ITEMCATEGORY)
                             INNER JOIN STORE SE
                                ON SE.STORECODE = ST.STORECODE
                             WHERE ST.STORECODE = IV_STORECODE
                               AND SE.HOSPITALID = IV_HOSPITALID
                               AND TRUNC(ST.CREATEDDATE) BETWEEN V_FROMDATE AND
                                   V_TODATE
                               AND ST.STATUS <> 99
                               AND STD.ITEMCODE NOT LIKE '%#%'
                               AND                   
                                   (IV_DRUGTYPE IS NULL OR
                                   IC.DRUGTYPECATEGORYID = IV_DRUGTYPE)
                            UNION
                            SELECT D.STORECODE,
                                   TO_CHAR(D.ITEMCODE) AS ITEMCODE,
                                   C.ITEMCATEGORYNAME,
                                   ISUB.ITEMSUBCATEGORY1NAME
                              FROM DAILYINVENTORY D
                             INNER JOIN ITEMCOMPANY IC
                                ON IC.ITEMCODE = D.ITEMCODE
                             INNER JOIN ITEMCATEGORY C
                                ON IC.ITEMCATEGORY = C.ITEMCATEGORYID
                              LEFT OUTER JOIN ITEMSUBCATEGORY1 ISUB
                                ON ISUB.ITEMSUBCATEGORY1ID = IC.ITEMSUBCATEGORY1
                               AND ISUB.ITEMSUBCATEGORY1ID IN
                                   (SELECT ITEMSUBCATEGORY1ID
                                      FROM ITEMSUBCATEGORY1
                                     WHERE ITEMCATEGORYID = IV_ITEMCATEGORY)
                             INNER JOIN STORE SE
                                ON SE.STORECODE = D.STORECODE
                             WHERE D.STORECODE = IV_STORECODE
                               AND SE.HOSPITALID = IV_HOSPITALID
                               AND TRUNC(D.UPDATEDDATE) <= V_TODATE
                               AND D.QTY > 0
                               AND D.ITEMCODE NOT LIKE '%#%'
                               AND C.ITEMCATEGORYID = IV_ITEMCATEGORY
                                  AND (IV_DRUGTYPE IS NULL OR
                                   IC.DRUGTYPECATEGORYID = IV_DRUGTYPE)
                               AND (IV_SUBITEMCATEGORY IS NULL OR
                                   ISUB.ITEMSUBCATEGORY1ID = IV_SUBITEMCATEGORY) Will post the explain plan ..
    Thanks in advance..

    Ensure you also include all the other information people will need to help you, e.g. database version, table structures/relationships and cardinalities, row counts etc.
    See the two threads linked to in the FAQ: {message:id=9360003}

  • General queries regarding explain plan and query

    Hello Oracle buddies,
    I have few badly formed queries with plenty of nested loops, merge join cartesian , plenty of sorting and in the query so many sub queries and all.. The cost of the queries are high like anything.
    some even has 130Crore of cost .
    When I got the chance to look into those quries I test them in Non Prod systems and which almost have 90-95% similar data as it was refresh by PROD few weeks back.
    I found few queries are having the same explain plan but cost is less like anything. for example 5000 or 6000.
    When I check for the possibilities of wrong statistics I found they just collect with default setting...
    In Non prod I saw only the auto stat job is ran and most of the tables are having the stats which are of last analyzed on the day of refresh.
    Now what could be so differentiating factor that drives a queries' cost lesser than Prod systems, when the data is almost same. Also if prod ssystem is gather by only gather_schema_stat('SCHEMA_NAME') then it should carry the same stat in non prod while refreshing. I know ppl do not gather stat on test only auto job is running ...
    I need to have clear prove before I can have a clear understanding..
    Please help me to know what factors could be differentiating?
    -Regards,
    J_DBA_Sourav

    j_DBA_sourav wrote:
    Hello Jonathan,
    Thanks for the reply. The team refreshed it, by expdp/impdp method where by default statistics are included. In that case?
    Is this problem probable to happen due to statistics only or anything else is also responsible. Even the explain plan is same.
    Please through some light on it.
    Auto job is on as I stated earlier but in test systems most of the tables are showing refreshed date as last_analyzed
    -Regards
    JDS
    Anything that puts the stats out of sync with each other may be sufficient to cause problems. Any queries that depend on sysdate may cause a problem.
    As a simple check:  select table_name, last_analyzed from user_tables on the two systems, with some order by clause (e.g. table_name), and see how many tables were analysed at different times - anything on either system after the exp/imp could be part of your problem.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    Now on Twitter: @jloracle

Maybe you are looking for

  • Pegasus2 Promise with Mac Pro

    Is it safe to say that purchasing one of the units as an external HD component to the new Mac Pro alleviates the need to upgrade the internal HD to more GBs when purhcasing the Mac Pro? I would make the RAID my primary storage source, with a 3 TB Tim

  • Generating dynamic Attachments between bpel process activities

    Dear Experts, Please suggest me that how to handle dynamic attachments in BPEL process with JDeveloper. The requirement was need to send an attachment between activities in same BPEL process and not sending an attachment through mail. For Instance co

  • Hidden files in application support folder

    It appears that some of the folders that should be in application support are either hidden or are not there....that would include address book as well as data and image files in other applications....The applications work but I'd like to find my dat

  • Layer Style Keyboard zoom bug

    When using  CS5 and I have the Layer Style dialog box open, using keyboard zoom (command -/+), zooming in triggers 3 zooms instead of one, and zooming out triggers 2 zooms. If I leave the dialog open and switch to another program and  back it behaves

  • IPad suddenly rejects WiFi connection

    Hi, I have an iPad 3 which recently decided to refuse to connect to my home Wi-Fi. When I tap the connection name in Wi-Fi Settings, it connects to the network, but then immediately disconnects again, then reconnects, then disconnects and so on. I to