Query to select records between 2 different times

Hi all,
With trap_store table as (trap_id number,trap_received date))
and trap_time table as (from_time varchar2(10),to_time varchar(10))
How to i select records from trap_store table where time part of trap_received is between from_time and to_time of trap_time table.
Need to retrive records from trap_store table between 2 times. data in from_time and to_time(varchar columns) are stored in format HH24:MI:SS
from_time and to_time range can span over 2 days ie; from_time can be 23:00:00 and to_time can be 01:00:00
Thanks in advance,
Sreekeshava S

Hi,
Here's one way:
WITH     got_received_time     AS
     SELECT  trap_id, trap_received
     ,     TO_CHAR (trap_received, 'HH24:MI:SS')     AS received_time
     FROM     trap_store
SELECT     trap_id, trap_received
FROM     trap_store     s
WHERE     EXISTS (
                SELECT  1
             FROM        trap_time
             WHERE   (    from_time  <= to_time
                     AND     s.received_time  BETWEEN  from_time
                                  AND       to_time
             OR        (    from_time  >  to_time
                     AND  (   s.received_time <= from_time
                              OR  s.received_time >= to_time
;If you'd care to post CREATE TABLE and INSERT statements for a little sample data, and the results you want from that data, then I could test this.

Similar Messages

  • Select Records between Begin Date/Time and End Date/Time

    Hi, I need to select records from table GLPCA where the CPUDT and CPUTM are between a START DATE/TIME and END DATE/TIME. 
    I have the below logic from an SAP Solution, but it doesn't seem to be working right in my opinion.  It is picking up records earlier than the date ranges.  Can anyone tell me how I might be able to accomplish this?  I'm hoping this is an easy one for the ABAPPERs... 
    Thanks,
    START DATE 20091022
    START TIME 125736
    END DATE 20091022
    END TIME 135044
    CPUDT 20091022
    CPUTM 100257
          SELECT * FROM GLPCA
             WHERE ( CPUDT >= STARTDATE AND ( CPUTM >= STARTTIME OR ( CPUDT <= ENDDATE AND CPUTM <= ENDTIME ) ) ).

    Thank you all!  I ended up using the following:
    SELECT * FROM GLPCA
              WHERE RYEAR IN L_R_RYEAR
                AND ( ( CPUDT = STARTDATE AND CPUTM >= STARTTIME ) OR CPUDT > STARTDATE )
                AND ( ( CPUDT = ENDDATE   AND CPUTM <= ENDTIME )   OR CPUDT < ENDDATE ).
    This child was born from the following thread that was found:
    update date and time of client record

  • Query to get records between a range...............

    Hi,
    Is there any way in oracle to get records between the records 20-30.
    As far as i know in oracle you can put where rownum < (some integer)
    But is it possible to getsomething between the records 20-30
    Thanks

    Is there any way in oracle to get records between the
    records 20-30.No you can't do it.
    The reason why it's not possible is because oracle has no internal ordering of the records.
    http://www.oracle.com/technology/oramag/oracle/06-sep/o56asktom.html
    How ROWNUM Works
    ROWNUM is a pseudocolumn (not a real column) that is available in a query. ROWNUM will be assigned the numbers 1, 2, 3, 4, ... N, where N is the number of rows in the set ROWNUM is used with. A ROWNUM value is not assigned permanently to a row (this is a common misconception). A row in a table does not have a number; you cannot ask for row 5 from a table—there is no such thing.

  • Selecting records based on different fields

    Post Author: timg
    CA Forum: General
    I have three groups which I study quite often, the blues (as identified in field 1with codes), the reds (identified in field 2 with codes), and the greens (identified in field 3 with certain codes).
    I want to be able to run one report which, through a parameter field, I can select the group (red, green, or blue) for which I can select records from the database and analyze. Stated another way, if I select "Blue" in the parameter field, how can I get CR to pull certain records in the correct field with the correct codes.

    Post Author: yangster
    CA Forum: General
    dunno what your codes are but something like this will work if you put it in the section expertif ?para = "BLUE" then field1 in &#91;a, b, c&#93; elseif ?para = "RED" then field2 in &#91;d, e, f&#93; elseif ?para = "GREEN" then field3 in &#91;g, h, i&#93; 

  • Simple Select query with 'where', 'and', 'between' clauses takes time

    Hi,
    I have a select query as below
    SELECT * FROM (SELECT a.*,ROWNUM currentStartRecord From (select ai_inbound.ai_inb_seq tableseq,'AI_INBOUND' tablename,'INBOUND' direction,ai_inbound.appl,ai_inbound.ai_date datetime,ai_inbound.ic_receiver_id pg_id,ai_inbound.ic_sender_id tp_id,ai_inbound.session_no,ai_inbound.ic_ctl_no,ai_inbound.msg_set_id msg_type,ai_inbound.appl_msg_ctl_no reference_no,ai_inbound.fg_version version,ai_inbound.msg_status status,ai_inbound.input_file_name,ai_inbound.output_file_name,ai_inbound.ack_file_name from ai_inbound where ai_inbound.appl = ? and ai_inbound.ai_date between ? and ? )a where ROWNUM <= 49)where currentStartRecord >= 0
    The above query takes longer time through application than expected when the date fields are passed whereas it works fine when no date fields are passed. We are using oracle9.2 version of the database. All the indexed columns and partitioned indexed columns are rebuild.
    Kindly let me know how can i tune up the query to improve the performance.
    Thanks

    Hi,
    I have a select query as below
    SELECT * FROM (SELECT a.*,ROWNUM currentStartRecord From (select ai_inbound.ai_inb_seq tableseq,'AI_INBOUND' tablename,'INBOUND' direction,ai_inbound.appl,ai_inbound.ai_date datetime,ai_inbound.ic_receiver_id pg_id,ai_inbound.ic_sender_id tp_id,ai_inbound.session_no,ai_inbound.ic_ctl_no,ai_inbound.msg_set_id msg_type,ai_inbound.appl_msg_ctl_no reference_no,ai_inbound.fg_version version,ai_inbound.msg_status status,ai_inbound.input_file_name,ai_inbound.output_file_name,ai_inbound.ack_file_name from ai_inbound where ai_inbound.appl = ? and ai_inbound.ai_date between ? and ? )a where ROWNUM <= 49)where currentStartRecord >= 0
    The above query takes longer time through application than expected when the date fields are passed whereas it works fine when no date fields are passed. We are using oracle9.2 version of the database. All the indexed columns and partitioned indexed columns are rebuild.
    Kindly let me know how can i tune up the query to improve the performance.
    Thanks

  • Select Record Between Date Gap-Oracle 11g, Windows 2008 server

    hello everyone,
    I have a sql query where I need to select only records with an 18 month gap between max(date) and previous date( no dates between max(date)
    and 18 month gap date), when I run the below query it should only select supid 130, not 120 (even though 120 does contain an 18 month gap date it also has a date that is less then the 18 month gap( '25-NOV-2012','DD-MON-YYYY').
    how would get the query to look back 18 months for the next date and evaluate the month_between.
    any help is greatly appreciated.
    example:
    create table supply(supID number(8), supply varchar2(20), supdate Date,supamount number(13,2));
    insert into supply values(100,'Tapes',to_date('01-AUG-2013','DD-MON-YYYY'),50.00);
    insert into supply values(100,'TV',to_date('01-APR-2013','DD-MON-YYYY'),250.00);
    insert into supply values(100,'Discs',to_date('25-DEC-2012','DD-MON-YYYY'),25.00);
    insert into supply values(120,'Tablets',to_date('25-AUG-2013','DD-MON-YYYY'),15.00);
    insert into supply values(120,'Paper',to_date('25-NOV-2012','DD-MON-YYYY'),35.00);
    insert into supply values(120,'Clips',to_date('20-NOV-2010','DD-MON-YYYY'),45.00);
    insert into supply values(120,'Binders',to_date('28-FEB-2012','DD-MON-YYYY'),25.00);
    insert into supply values(130,'Discs',to_date('25-JUL-2013','DD-MON-YYYY'),75.00);
    insert into supply values(130,'Calc',to_date('25-JAN-2012','DD-MON-YYYY'),15.00);
    insert into supply values(130,'Pens',to_date('15-DEC-2011','DD-MON-YYYY'),55.00);
       select * from supply p where to_char(p.supdate,'yyyy')='2013'
       and p.supid in(select s.supid from supply s where months_between(s.supdate,p.supdate)<-18)
         SUPID SUPPLY               SUPDATE    SUPAMOUNT
           120 Tablets              25-AUG-13         15
           130 Discs                25-JUL-13         75

    Something like this?
    select
    from (
    select
      supid
    , supply
    , supdate
    , supamount
    , lead(supdate) over (partition by supid order by supdate desc) ldate
    from supply
    where
    months_between(supdate,ldate) >= 18
    SUPID
    SUPPLY
    SUPDATE
    SUPAMOUNT
    LDATE
    130
    Discs
    07/25/2013
    75
    01/25/2012
    Ok. i see you want only he diff to max date.
    select
    from (
    select
      supid
    , supply
    , supdate
    , supamount
    , lead(supdate) over (partition by supid order by supdate desc) ldate
    , row_number() over (partition by supid order by supdate desc) rn
    from supply
    where
    months_between(supdate,ldate) >= 18
    and
    rn = 1
    Message was edited by: chris227
    extended

  • Bex query. Select single values in variable time out.

    I have created a variable on characteristic 0profit_ctr which works fine for all queries on all Infoproviders except for one.  With this particular Infoprovider, which is a DSO when the option to show u201CSingle Valuesu201D is selected in the variable screen the query just hangs and eventually time-outs. I have tried including the DSO in a mult-provider but still have the same issue. The variable works on other DSOu2019s with exactly the same settings. This DSO has less data than the other DSOu2019s which work fine.
    I know that 0profit_ctr is compounded with 0co_area which I have tried restricting with no change in the result.
    I would be grateful of any ideas.
    Thanks
    Jenny

    Hi Durgesh.
    I checked the settings and although they were the same as other infoproviders I changed the query filter value to use the values in the master data table and this has solved my problem.
    Thanks for your tip.
    Regards
    Jenny

  • How to develop this report/Query that selects records with MAX Value

    Hi,
    My requirment is to develop a report to show all emp whose policy is going to expire ith in the user selected date intreval...
    Emp_ID--App_Date-Policy_Strt_Date--Policy_End_Date--App_Status
    101.01.2007---BlankBlank--
    NEW   (New application for a Medical Insurance policy raised for employee)
    101.01.2007---01.02.200730.05.2007--
    COMPLETE (policy issued for emp with strt & end dates)
    115.05.2007---01.02.200730.05.2007--
    RENEWAL  (a application is raised to renew emp policy)
    115.05.2007---01.06.200731.12.2007--
    COMPLETE  (policy issued for emp with strt & end dates)
    115.12.2007---01.06.200731.12.2007--
    RENEWAL  (a application is raised to renew emp policy)
    115.12.2007---01.01.200831.05.2008--
    COMPLETE  (policy issued for emp with strt & end dates)
    115.05.2008---01.01.200831.05.2008--
    RENEWAL  (a application is raised to renew emp policy)
    115.05.2008---01.06.200831.05.2009--
    COMPLETE  (a application is raised to renew emp policy)
    So EMP 1 got valid policy untill 31.05.2009.
    When a user executes a query to show all employees whose policy expiry date intreval (01.05.2008 to 31.05.2008)
    it shouldn't show Emp 1 as he got  valid policy untill 31.05.2009  but currently it is showing Emp 1....
    How can i achieve this
    Thanks

    Hi
    Thanks for the update
    I created variable on Plc End end
    If user enter show all emps whose policy is expiring in MAY (01.05.2008---31.05.2008) it is displaying EMp 1 as well but emp 1 has a policy which expires in 2009
    Thanks

  • How to calculate the difference between 2 different times being input.

    import java.io.*;
    import java.util.*;
    public class ClockingInOut
    public static void main(String[] args) throws IOException
    BufferedReader keyboard = new BufferedReader (new InputStreamReader (System.in));
    String input, input1, input2;
    int num1, num2, answer;
    System.out.println ("\t\t\tEMPLOYEE CLOCKING IN AND OUT SYSTEM!");
    do
    System.out.print ("\nWould you like to clock in and out? yes (y), no(n), ?: ");
    input = keyboard.readLine();
    if (input.equals("y"))
    System.out.print ("Please enter the hours you clocked in: ");
    num1 = Integer.parseInt (input1 = keyboard.readLine());
    System.out.print ("Please enter the minutes you clocked in: ");
    num2 = Integer.parseInt (input2 = keyboard.readLine());
    System.out.print ("Now Please enter the hours you clocked out! ");
    num1 = Integer.parseInt (input1 = keyboard.readLine());
    System.out.print ("And please enter the minutes you clocked out!: ");
    num2 = Integer.parseInt (input2 = keyboard.readLine());
    Hi people, i think my coding may be wrong. I would like the user to input the hours and then minutes of the time they clocked in and out of work. and then i want the program to be able to calculate the hours worked and print the mesage in the Command Prompt window.
    It's really confusing and hard, please help and provide me with the correct soure code if you can.
    Also, like in html how the notepad file has to have the opening and closing brackets, does java coding have something like this.
    Please reply. Thank You.

    hi
    check this java class
    import java.sql.Time;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    public class util
        public static void main(String[] args)  throws Exception
            long t1 = getTimeOnlyLong();
            Thread.sleeo(2000);
            long t2 = getTimeOnlyLong();
            System.out.println(differenceBetween2Times(t1,t2));
        public static long getTimeOnlyLong()
            Date d = new Date();
            return d.getTime();       
        public static String differenceBetween2Times(long l1 , long l2)
            long diff = l1 - l2;
            System.out.println("differ =  " + diff);
            Date d = new Date();
            d.setTime(diff);
            SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
            return sdf.format(d.getTime());       
    }

  • Select records based on the closest given time

    Dear SQL gurus,
    I have a table T1:
    Name Null? Type
    ID NOT NULL NUMBER(5)
    MOMENT NOT NULL DATE [DD.MM.YYYY HH24:MI]
    MEASUREMENT NOT NULL NUMBER(8,3)
    Example (ID, MOMENT, MEASUREMENT)
    -- START OF EXAMPLE --
    9380 18.11.2000 03:45 17.6
    9380 18.11.2000 04:30 17.3
    9380 18.11.2000 05:45 16.8
    9380 18.11.2000 06:15 16.8
    9380 18.11.2000 07:00 16.2
    9380 18.11.2000 07:30 16.2
    9380 18.11.2000 08:15 16
    9380 18.11.2000 08:45 15.7
    9380 18.11.2000 09:30 15.4
    9380 18.11.2000 10:00 15.4
    9380 18.11.2000 11:15 15.4
    9380 18.11.2000 11:45 15.4
    9380 18.11.2000 12:30 15.4
    9380 18.11.2000 13:00 15.4
    9380 18.11.2000 13:45 15.4
    --- END OF EXAMPLE --
    How to select records based on the:
    - time period specified by the day only [DD.MM.YYYY] - CONDITION 1
    - with values for 6AM only, and if not available, with values closest to 6AM - CONDITION 2
    (if the time gap in MOMENT field is too big, lets say > 5h then choose the average between the value before 6AM (ex. 4:15AM) and the value after the 6AM (ex. 9:45AM))
    CONDITION 1 (something like): moment between '01.01.2005' and '31.12.2004' - this is OK
    CONDITION 2: I do not know how to formulate, especially if 6AM value is not availabe, and I have to find the closest available value, or get the avergae from the two adjacent values.
    Maybe cursor magic??? Thanks a lot for your help.
    Rado

    About condition two, would the following select be of use to you? Picking the first record could be achived by rownum, analytic function, etc.
    WITH t1 AS (SELECT 9380 id, TO_DATE('18.11.2000 03:45', 'dd.mm.yyyy hh24:mi') moment,  17.6 measurement
                  FROM dual
                 UNION 
                SELECT 9380 id, TO_DATE('18.11.2000 04:30', 'dd.mm.yyyy hh24:mi') moment,  17.3 measurement
                  FROM dual
                 UNION
                SELECT 9380 id, TO_DATE('18.11.2000 05:45', 'dd.mm.yyyy hh24:mi') moment,  16.8 measurement
                  FROM dual
                 UNION
                SELECT 9380 id, TO_DATE('18.11.2000 06:15', 'dd.mm.yyyy hh24:mi') moment,  16.8 measurement
                  FROM dual
    SELECT id, moment, measurement, diff
      FROM (SELECT id, moment, measurement,
                   moment - TO_DATE(TO_CHAR(moment, 'dd.mm.yyyy ') || '06:00', 'dd.mm.yyyy hh24:mi') diff
              FROM t1
    ORDER BY abs(diff) asc, SIGN(diff) desc;
      C.

  • Select records across multiple pages

    i have a resultset of 100 records. 10 records are displayed and pagination is displayed for the users to navigate to other pages. All this is accomplished using jstl.
    if the user selects 2 records on page 1, navigates to page 2 and selects 2 more records, only the records from page 2 get selected. how can the records from page 1 and page 2 get selected? how can i retain selected records between pages?
    can anybody please point me to some code snippets?
    Thanks,
    Jayashree.

    u have to store some where the index of the selected records..
    Shanu

  • Select Query Fetching same records multiple time

    Hi ABAPers,
    I have an issue where the select query is fetching the same records more than one time for particular sale order.
    Kindly help to solve the issue.
    Thanks in advance..
    Here is the Select Query:-
    SELECT  VBAK~VKORG VBAK~VTWEG VBAK~VBELN VBAK~KUNNR
                   VBAK~ERDAT VBAK~LIFSK VBKD~INCO1 VBKD~INCO2
                   VBAP~MATNR VBAP~ARKTX VBAP~MATKL VBAK~BSTNK
                   VBAK~BSTDK VBAK~KNUMV VBAP~UEPOS VBAP~POSNR
                   VBAP~KWMENG VBAK~VDATU VBAP~VRKME VBAK~ERNAM VBAK~WAERK
      INTO CORRESPONDING FIELDS OF TABLE IT_PENDING FROM VBAK
      INNER JOIN VBAP ON VBAK~VBELN = VBAP~VBELN
      INNER JOIN VBKD ON VBAK~VBELN = VBKD~VBELN
      WHERE
      VBAK~VBELN IN SO_VBELN AND
      VBAK~ERDAT IN SO_ERDAT AND
      ( AUART EQ 'OR' OR AUART EQ 'ZEO' OR AUART EQ 'TA' OR AUART EQ 'LP' OR AUART EQ 'ZFOC' ) AND
      VKORG IN SO_VKORG AND
      VTWEG IN SO_VTWEG AND
      SPART IN SO_SPART AND
      KUNNR IN SO_KUNNR AND
      MATNR IN SO_MATNR AND
      MATKL IN SO_MATKL AND
      ABGRU EQ '' AND LIFSK <> '35'.
    Edited by: Suhas Saha on Jan 14, 2012 3:42 PM

    Hello Suhale,
    On retrospection, I found the query in my above response STILL HAS ONE ISSUE. When we are making a left outer join on vbkdposnr = vbapposnr we are only fetching vbkdinco1 and vbkdinco2 values where item level entries exist in VBKD which match with vbkdposnr = vbapposnr.
    Actually we should bring inco1 and inco2 from vbkd when a matching entry exists in vbkd where vbkdposnr = vbapposnr and if there is no entry matching vbkdposnr = vbapposnr, then we should fetch inc01 and inco2 from VBKD where posnr = '000000' (i.e., from header).
    This is how SAP behaves when you open an item in VA03 and look at inco1 and inco2. They come from the item if an entry corresponding to that item exists in VBKD otherwise they come from VBKD header record (where vbkd~posnr = '000000')
    We can't use VBKD in the joins and still be able to do the above. So we need to fetch inco1, inco2 from VBKD separately like below.
    FIELD-SYMBOLS: <fs_pending> LIKE LINE OF it_pending.
    SELECT vbak~vkorg vbak~vtweg vbak~vbeln vbak~kunnr
           vbak~erdat vbak~lifsk "vbkd~inco1 vbkd~inco2
           vbap~matnr vbap~arktx vbap~matkl vbak~bstnk
           vbak~bstdk vbak~knumv vbap~uepos vbap~posnr
           vbap~kwmeng vbak~vdatu vbap~vrkme vbak~ernam vbak~waerk
      INTO CORRESPONDING FIELDS OF TABLE it_pending
        FROM vbak INNER JOIN vbap
          ON vbak~vbeln = vbap~vbeln
            WHERE vbak~vbeln IN so_vbeln AND
                  vbak~erdat IN so_erdat AND
                ( vbak~auart EQ 'OR' OR vbak~auart EQ 'ZEO' OR
                  vbak~auart EQ 'TA' OR vbak~auart EQ 'LP' OR
                  vbak~auart EQ 'ZFOC' ) AND
                  vbak~vkorg IN so_vkorg AND
                  vbak~vtweg IN so_vtweg AND
                  vbak~spart IN so_spart AND
                  vbak~kunnr IN so_kunnr AND
                  vbap~matnr IN so_matnr AND
                  vbap~matkl IN so_matkl AND
                  vbap~abgru EQ '' AND
                  vbak~lifsk NE '35'.
      LOOP AT it_pending ASSIGNING <fs_pending>.
        SELECT SINGLE inco1 inco2
          FROM vbkd
            INTO (<fs_pending>-inco1,<fs_pending>-inco2)
              WHERE vbkd~vbeln = <fs_pending>-vbeln AND
                    vbkd~posnr = <fs_pending>-posnr.
        IF sy-subrc NE 0.
          SELECT SINGLE inco1 inco2
            FROM vbkd
              INTO (<fs_pending>-inco1, <fs_pending>-inco2)
                WHERE vbkd~vbeln = <fs_pending>-vbeln AND
                      vbkd~posnr = '000000'.
        ENDIF.
      ENDLOOP.
    Best regards,
    Vishnu Tallapragada.

  • Query with different parameter take different time to execute.

    Hi,
    I am a C/C++ programmer and newbie to database. I find weird case to my company database. oracle 10g.
    I have a query (below). When I set GENRE_ID value to 20, query execution time only take *5* seconds. But when I change to 10, it take *54* seconds! The same query but different values GENRE_ID (20 or 10) -- it also happen to other GENRE_ID values.
    on below query
    WHERE substr(GENRE_ID,0,2) = 10 and GENRE_ID != 10) take 54 seconds
    WHERE substr(GENRE_ID,0,2) = 20 and GENRE_ID != 20) take 5 seconds
    The explain plan give exact same result for both queries.
    I have follow Re: 3. How to  improve the performance of my query? / My query is running slow. for optimizer but the problem still there.
    And we have rebuilt all indexes.
    Anyone can help me? I need any advises for this problem.
    Note:
    Song table only have 570K records and Song_vod table 1100 records.
    Query:
    select *
    from(
    select rownum rowno, a.*
    from(
    select a.SONG_VOD_ID, a.SONG_ID, a.VOD_TITLE, a.ALBUM_ID, a.ARTIST_ID, a.VOD_ISSUE_DATE, a.VOD_ORDER_ISSUE_DATE, a.VOD_ADULT_YN, a.VOD_L_IMG_PATH, a.VOD_M_IMG_PATH, a.VOD_S_IMG_PATH, a.RECOMMEND_CNT, a.OPPOSE_CNT, get_song_name(a.SONG_ID) SONG_NAME, get_album_name(a.ALBUM_ID) ALBUM_NAME, get_artist_name(a.ARTIST_ID) ARTIST_NAME, VOD_ISSUE_DATE vodIssueDate
    from SONG_VOD a inner join SONG b on a.SONG_ID = b.SONG_ID
    where a.LC_STATUS_CD = 'CS0006'
    AND (b.GENRE_ID
    in (
    select GENRE_ID
    from MD_GENRE
    WHERE substr(GENRE_ID,0,2) = 10
    and GENRE_ID != 10)
    OR b.GENRE_ID
    in (
    select GENRE_ID
    from MD_GENRE
    WHERE substr(GENRE_ID,0,2) = '40'
    and GENRE_ID != '40'
    ) order by a.REG_DATE desc, a.SONG_VOD_ID desc
    ) a WHERE rownum <= 0 + 30
    Thank you,
    Regards
    -=Rika Chaniago=-

    907814 wrote:
    I am a C/C++ programmer and newbie to database. I find weird case to my company database. oracle 10g.
    I have a query (below). When I set GENRE_ID value to 20, query execution time only take *5* seconds. But when I change to 10, it take *54* seconds! The same query but different values GENRE_ID (20 or 10) -- it also happen to other GENRE_ID values.This is to be expected. Even an IDENTICAL query can (and often will) have DIFFERENT execution times.
    The typical reason is how fast the query process can get to the data block(s) containing the relevant row(s). Is that data block still on disk and require expensive and slow physical I/O to move it into the buffer cache for use? Is that data block already cached for much faster logical I/O access? If in memory, is there any contention in getting a latch for the chain the data block hangs off from (how hot is that block)? Etc.
    The run-time environment is not static. Thus execution times of queries (called cursors in Oracle) is not static. Execution times are expected to vary.
    Some basics. SQL code is source code. SQL code needs to be parsed and converted into a set of instructions that the server can execute. So it is similar to C/C++. SQL source code needs to be compiled. This executable code in Oracle is called a cursor.
    Like your code, the cursor can be executed with different input variables (bind variables). However, that code would have been compiled using certain assumptions about the data. And that executable code may work fine for some input data, and work not so okay for other input data. As the input parameter values are not not equal. E.g. there are a 1000 rows to process when employee type parameter is "employee" and only 10 rows when it is "manager". The code could have been compiled with the assumption that 10 rows would be the average for all input parameters - the Cost Based Optimiser needs to base its decision on the best execution path for that SQL source code on certain assumptions about the data. These may not always be correct. (usually due incorrect or stale stats about the data)
    Thus you also need to look at what the execution plan is (the URL for which has already been supplied).
    The Oracle® Database Performance Tuning Guide is at http://www.oracle.com/pls/db112/portal.all_books

  • Help to write query to get records from specified time TO specified time?

    I have a table which has large data and the table is updated every min,
    Suppose the Table comp(timeid date,sessions varchar2,sid varchar2)
    Here time needs to be checked
    So now i have to write a query which displays records that have been in the table
    for every 5 mins
    default timeframe is sysdate-5 then the lower and upper bound is multiple of 5 i.e
    Suppose now Time and sysdate: 12-sep-2007 1:22:00pm
    From sysdate: 12-sep-2007 1:15:01pm TO sysdate: 12-sep-2007 1:20:00pm
    So i need a query to get the records from 1:15:01pm to 1:20pm.
    Message was edited by:
    user594721

    Explanation is not clear.Please give sample data and expected o/p.
    If you need the data of previous five minutes, do like this...
    SQL> select id, to_char(time,'dd/mm/yyyy hh:mi:ss') time
      2  from test;
            ID TIME
             1 13/09/2007 10:29:55
             1 13/09/2007 10:29:22
             1 13/09/2007 10:20:28
    SQL> select id, to_char(time,'dd/mm/yyyy hh:mi:ss') time,
      2             to_char(sysdate,'dd/mm/yyyy hh:mi:ss') current_time
      3  from test
      4  where time between (sysdate - (5/24/60)) and sysdate;
            ID TIME                CURRENT_TIME
             1 13/09/2007 10:29:55 13/09/2007 10:32:45
             1 13/09/2007 10:29:22 13/09/2007 10:32:45                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Selecting records from multiple dates but specific time

    Hi:
    I've to select records of multiple dates but the time should be 00:00:00 to 06:00:00 (i.e. 12 AM - 6 AM)
    For date part this can be done:
    WHERE
    START_TIME BETWEEN TO_DATE('04-01-2012', 'MM-DD-YYYY') AND TO_DATE('04-05-2012', 'MM-DD-YYYY')
    But how can I fix the time mentioed above.
    Please let me know.
    Thanks/Tanvir

    WHERE
    START_TIME BETWEEN TO_DATE('04-01-2012', 'MM-DD-YYYY') AND TO_DATE('04-05-2012', 'MM-DD-YYYY')
    and start_time - trunc(start_time) between 0 and 6/24start_time - trunc(start_time) will give you the fraction of a day. So 6/24 means 06:00.
    (When you use to_char(trunc(sysdate,'hh'),'hh24') between 0 and 6 you will also retrieve records with start_time 06:01 for example. So this would not meet your requirements as far as I understood.)
    Edited by: hm on 10.04.2012 01:26

Maybe you are looking for

  • Creative Cloud updates fail for Photoshop/CC U44M1P7

    Hi, I'm having problems updating my Creative Cloud applications - error code U44M1P7. PROBLEM: I still can't update Photoshop or most of the other CC apps. - I am running Application Manager 6.2 (7.0.0.189) and Extension Manager 6.04 - MacPro 3.1, OS

  • S.M.A.R.T. someiimes says my HD is bad other time it doesnst and sometimes...

    ... even find it ! When I use  Everest to analyse the SMART when it says my HD is bad ,  it tells me that the HD failed at the Spin Up Time test . Should I change my HD?My mobo is a K8tNeo2 FIsr

  • How to append a picture in a mail?

    Hello! How to append a picture which like gif file in a e-mail? Like OutlookExpress append picture,but not just append attach file.. I want it look like a part of htm. Not look like a attach file. Please help~ Excuse me,I am not good in English. Best

  • SAP PI: the quality of service EO vs. EOIO

    Hello all, I have a service (File -> XI -> RFC). If i use the quality of service "EOIO" in the file sender channel, the data from xml file could not be imported in backend system per RFC-call. If i use "EO"-Settings then the data could be saved in ba

  • Composite primary key on very large tables...

    Hello So I'm building a database where one of the tables will eventually have > 1 billion rows and was wondering about the primary key. The table will have 3 columns (sample_id, object_id, value) and so I was thinking instead of creating a surrogate