Query to identify every Wednesday between 2 dates

Hello

I have this code that works well, but I thought it was very ugly.  Optimization or simplifications advice?

select to_date(:startdate, 'YYYY-MM-DD') + rownum -1 as Date_
      from all_objects
     where rownum <=  to_date(:enddate, 'YYYY-MM-DD')-to_date(:startdate, 'YYYY-MM-DD')+1
having to_char(to_date(:startdate, 'YYYY-MM-DD') + rownum -1,'D')='4'   --4 = Wednesday 
group by to_date(:startdate, 'YYYY-MM-DD') + rownum -1
order by to_date(:startdate, 'YYYY-MM-DD') + rownum -1

Thank you

Hugo

Hi, Hugo.

Here's one way:

WITH the settings THAT

(

SELECT TO_DATE (: start_date, "YYYY-MM-DD") AS start_date

, TO_DATE (: end_date, "YYYY-MM-DD") AS end_date

OF the double

)

SELECT the LEVEL - 1 AS dt + start_date

OF parameters

WHERE TO_CHAR (start_date + LEVEL - 1

, "fmDY".

'NLS_DATE_LANGUAGE = ENGLISH'

) = 'SEA '.

CONNECT BY LEVEL<= 1="" +="" end_date="" -="">

;

The key is to lose the GROUP BY.  GROUP BY is to take groups of input lines and the production of 1 line output from them.  You don't do something like that in this problem.

Rather than repeat several times in the same query, a function call (for example, you used

TO_DATE (: startdate, ' YYYY-MM-DD "")

5 times in the query you posted), you can do it once, in a subquery and use the result as many times as you need in a Super application.

CONNECTION BY a 1 row table (or, in this case, the result set) is much more effective than to ROWNUM of object.  In addition, there are a finite number of lines in object.  This number is probably thousands, but there is always a limit.  CONNECT BY works for millions, or more if you need it.

I find TO_CHAR (some_date, 'DY') easier to debug and maintain than TO_CHAR (some_date, 'd').  I can get confused and think "3" means Wednesday, but I am not very inclined to believe that "Mar" means Wednesday, no matter how little coffee I've had.

In addition, it had "format depends on the setting of your NLS_TERRITORY, you can not control within the query. '" " DY"depends on the NLS_LANGUAGE, which you can substitute by passing an argument to TO_CHAR 3rd.  The above query will always look for Wednesday, though they are called Onsdag Mittwoch in your session, and regardless of the question of if she thinks it's the 3rd or the 4th day of the week.

Tags: Database

Similar Questions

  • Need to query to find missing months between two dates.

    A bank customer a monthly overview of databases (in the tens of millions of accounts)

    The data are sent with a line per account each month.  It is stored in a table called "ACCOUNTS_TAB".

    Fields on registration, which

    Column

    Description

    Example of format.

    * YRMTH-1

    Year and month of the snapshot

    6-character numeric, 4-digit year added to months of 2 digits, example 201301, 201311

    * AccountID

    Unique identifier for an account.

    Integer, example 100098322

    Opening balance - 1

    Initial account balance at the closing of the previous month

    $30000

    Closing balance - 1

    The account balance at the end of the month of closing

    $34200

    Class-1 relative to investments

    .....

    ...

    .....

    ......

    .....

    Many more columns, two favorites (*) columns are alone, that you will need for the query. There are no columns to tell when an account is closed, or has just opened, and not separate "master account" - you use this single table for your query that results.

    The table was in place from 200301, so many accounts have dozens of lines, if they have been open for many years and other only 1 or 2 ranks, if new.

    Write a query to give just a list of accountDs that meet the following criteria.

    1. 1) has a record for specific 201503
    2. 2) was also a record for the month specific 201602
    3. 3) missing one or several months between these two records.

    A good account which was opened from 201503 to 201602 inclusive would of course have lines for

    201503

    201504

    201505

    201506

    201507

    201508

    201509

    201510

    201511

    201512

    201601

    201602

    It's good to hardcode the month of departure (201503), end of month (201602) and the actual number of months between them (10 exclusive or 12 inclusive) as part of your query.

    Once again the account must meet all 3 criteria to be an account issue.  If only, they have a partial set of these documents but do not have the month of departure, or is not the end of the month, it is not a problem, only when they have so specified and end early and not a full between game.


    Help, please!

    Maybe this...

    -----

    -The Dataset for the test begins

    WITH dataset (ACCOUNT_NO, DATES)

    AS (SELECT 100, DOUBLE 201503

    UNION ALL

    SELECT 100, DOUBLE 201504

    UNION ALL

    SELECT 100, DOUBLE 201505

    UNION ALL

    SELECT 100, DOUBLE 201506

    UNION ALL

    SELECT 100, DOUBLE 201507

    UNION ALL

    SELECT 100, DOUBLE 201508

    UNION ALL

    SELECT 100, 201509 OF THE DOUBLE

    UNION ALL

    SELECT 100, DOUBLE 201510

    UNION ALL

    SELECT 100, 201511 OF THE DOUBLE

    UNION ALL

    SELECT 100, DOUBLE 201512

    UNION ALL

    SELECT 100, 201601 DOUBLE

    UNION ALL

    SELECT 100, DOUBLE 201602

    UNION ALL

    SELECT 200, DOUBLE 201503

    UNION ALL

    SELECT 200, DOUBLE 201504

    UNION ALL

    SELECT 200, DOUBLE 201505

    UNION ALL

    SELECT 200, DOUBLE 201506

    UNION ALL

    SELECT 200, DOUBLE 201508

    UNION ALL

    SELECT 200, DOUBLE 201509

    UNION ALL

    SELECT 200, DOUBLE 201510

    UNION ALL

    SELECT 200, DOUBLE 201511

    UNION ALL

    SELECT 200, DOUBLE 201512

    UNION ALL

    SELECT 200, 201601 DOUBLE

    UNION ALL

    SELECT 200, DOUBLE 201602

    UNION ALL

    SELECT 300, DOUBLE 201503

    UNION ALL

    SELECT 300, DOUBLE 201504

    UNION ALL

    SELECT 300, DOUBLE 201505

    UNION ALL

    SELECT 300, DOUBLE 201506

    UNION ALL

    SELECT 300, DOUBLE 201507

    UNION ALL

    SELECT 300, DOUBLE 201508

    UNION ALL

    SELECT 300, DOUBLE 201509

    UNION ALL

    SELECT 300, DOUBLE 201510

    UNION ALL

    SELECT 300, DOUBLE 201511

    UNION ALL

    SELECT 300, 201601 DOUBLE

    UNION ALL

    SELECT 300, DOUBLE 201602

    UNION ALL

    SELECT 400, DOUBLE 201504

    UNION ALL

    SELECT 400, DOUBLE 201505

    UNION ALL

    SELECT 400, DOUBLE 201506

    UNION ALL

    SELECT 400, DOUBLE 201507

    UNION ALL

    SELECT 400, 201508 DOUBLE),

    -The Dataset to test ends

    -Hand with clause begins

    ResultSet

    AS (SELECT account_no,

    CASE

    WHEN COUNT)

    CASE WHEN dates IN (201503, 201602) THEN 1 END)

    COURSES (PARTITION BY account_no) = 2

    AND (COUNT (DISTINCT SUBSTR (dates, 4)))

    COURSES (PARTITION BY account_no) = 12

    OR COUNT (DISTINCT SUBSTR (dates, 4))

    COURSES (PARTITION BY account_no)<>

    AND COUNT (DISTINCT SUBSTR (dates, 1, 4))

    (PARTITION BY account_no) > 1

    THEN

    « Y »

    ON THE OTHER

    « N »

    END

    FLG

    THE dataset---> replace with your table name

    GROUP BY account_no, dates)

    SELECT DISTINCT Account_no

    FROM THE result set

    WHERE flg = 'Y ';

    -Hand with the ends of the clause

    ACCOUNT_NO

    -----------------------

    100

    300

    200

    See you soon,.

    Manik.

  • Between specific dates by month SQL

    All,
    I'm creating a query I need to shoot between certain dates for each month. If it was a thing of the time, I could do the simple between the call, but... What I'm trying to do, is to have a request from our system to run at the end of each month to shoot the pay period dates. For example, for a pay period executed between January 24, 2012 and February 23, 2012 the query would be shooting these dates at the end of February and the same for the end of MARCH that withdrawing between February 24, 2012 and March 23, 2012.
    and so on and so forth.

    CREATE TABLE ps_paycal
    (emplid NUMBER KEY PRIMARY (6)
    , name VARCHAR2 (12)
    date of frozen_dt
    );

    INSERT INTO ps_employees (emplid, name, date)
    VALUES (111111, "JOHN DOE", JANUARY 24, 2012 ');

    INSERT INTO ps_employees (emplid, name, date)
    VALUES (111111, "JOHN DOE", FEBRUARY 23, 2012 ');
    INSERT INTO ps_employees (emplid, name, date)
    VALUES (111111, "JOHN DOE", FEBRUARY 24, 2012 ');
    INSERT INTO ps_employees (emplid, name, date)
    VALUES (111111, "JOHN DOE", MARCH 23, 2012 "");
    INSERT INTO ps_employees (emplid, name, date)
    VALUES (111111, "JOHN DOE", MARCH 24, 2012 "");
    INSERT INTO ps_employees (emplid, name, date)
    VALUES (111111, "JOHN DOE", 23 APRIL 2012 "");

    Hope it makes sense. In any case, it is Oracle 11 g.

    Thanks for the help!

    Karsten

    Hi, Karsten,.

    Karsten Hilton wrote:
    ... How do you get to create, insert, select in the post to look like your answer? I put quotes around it?

    As you have noticed, this site normally does not display multiple spaces in a row.
    Whenever you post the text formatted (such as formatting queries) on this site, type the 6 characters:

    \

    (small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.  Everything between the \
    

    tags appear in a police fixed-width.

  • Need help with query between 2 dates

    Hello

    I did not SEE in a long time and need help with a simple query.

    I have a table of DB access with 3 fields, name, date and number

    What I want is to create a query to retrieve all the names between 2 dates

    When I ask the date field, the results are showing in this formats 2013-07-12 00:00:00

    Here's my query

    < cfquery datasource = 'mydb' name = 'test' >

    SELECT name from myTable

    where edate between ' 2011-01-01 00:00:00 ' AND ' 2013-01-01 00:00:00 '

    < / cfquery >

    < cfoutput query = 'test' >

    #name #.

    < / cfoutput >

    What I get is this error

    ODBC = 22005 (assignment error) error code

    [Microsoft] [ODBC Microsoft Access driver] Type mismatch of data in the expression of the criteria.

    Don't know what I'm doing wrong here.

    Please let me know.

    Thank you

    SELECT ename

    FROM MyTable

    WHERE edate BETWEEN

    AND

    #ename #.

  • query to identify bad data

    Oracle version: 10g
    Hi all
    I need help with the query to identify the data in the wrong order:

    correct the order = ready for submission-> valid--> order

    in the example below id 1 is in the right order, but id 2 is a mess because ready for submission came after validation.
    ID 3 is not valid because ID ordered came forward, ready to be submissive and valid.

    basically anything with bad state order must be reported
    /* Formatted on 2010/04/22 16:10 (Formatter Plus v4.8.8) */
    WITH t AS
         (SELECT 1 AS ID, 'ready for submission' status,
                 SYSDATE - 8 AS status_date
            FROM DUAL
          UNION ALL
          SELECT 1 AS ID, 'validated' status, SYSDATE - 7 AS status_date
            FROM DUAL
          UNION ALL
          SELECT 1 AS ID, 'ordered' status, SYSDATE - 6 AS status_date
            FROM DUAL
            union all 
            SELECT 2 AS ID, 'ready for submission' status,
                 SYSDATE - 8 AS status_date
            FROM DUAL
          UNION ALL
          SELECT 2 AS ID, 'validated' status, SYSDATE - 9 AS status_date
            FROM DUAL
          UNION ALL
          SELECT 2 AS ID, 'ordered' status, SYSDATE - 7 AS status_date
            FROM DUAL
            union all 
            SELECT 3 AS ID, 'ready for submission' status,
                 SYSDATE - 5 AS status_date
            FROM DUAL
          UNION ALL
          SELECT 3 AS ID, 'validated' status, SYSDATE - 4 AS status_date
            FROM DUAL
          UNION ALL
          SELECT 3 AS ID, 'ordered' status, SYSDATE - 6 AS status_date
            FROM DUAL)
    SELECT *
      FROM t
      order by id, status_date
    required results
    ID:
    2
    3


    Thank you

    devarade wrote:
    Hi, request almost works great... but there is a small problem.

    WITH t AS
         (SELECT 1 AS ID, 'ready for submission' status,
                 SYSDATE - 8 AS status_date
            FROM DUAL
          UNION ALL
          SELECT 1 AS ID, 'validated' status, SYSDATE - 7 AS status_date
            FROM DUAL
          UNION ALL
          SELECT 1 AS ID, 'ordered' status, SYSDATE - 6 AS status_date
            FROM DUAL
            union all
            SELECT 2 AS ID, 'ready for submission' status,
                 SYSDATE - 8 AS status_date
            FROM DUAL
          UNION ALL
          SELECT 2 AS ID, 'validated' status, SYSDATE - 9 AS status_date
            FROM DUAL
          UNION ALL
          SELECT 2 AS ID, 'ordered' status, SYSDATE - 7 AS status_date
            FROM DUAL
            union all
            SELECT 3 AS ID, 'ready for submission' status,
                 SYSDATE - 5 AS status_date
            FROM DUAL
          UNION ALL
          SELECT 3 AS ID, 'validated' status, SYSDATE - 4 AS status_date
            FROM DUAL
          UNION ALL
          SELECT 3 AS ID, 'ordered' status, SYSDATE - 6 AS status_date
            FROM DUAL
          UNION ALL
          SELECT 4 AS ID, 'ready for submission' status, SYSDATE - 6 AS status_date
            FROM DUAL
          UNION ALL
          SELECT 5 AS ID, 'validated' status, SYSDATE - 6 AS status_date
            FROM DUAL
          UNION ALL
          SELECT 6 AS ID, 'ordered' status, SYSDATE - 6 AS status_date
            FROM DUAL
         )
    SELECT  id,
            status,
            status_date
      FROM  t
      WHERE id in (
                   SELECT  id
                     FROM  (SELECT  id,
                                    case status
                                      when 'ready for submission' then 1
                                      when 'validated' then 2
                                      when 'ordered' then 3
                                      else 0
                                    end status_seq,
                                    row_number() over(partition by id order by status_date) rn,
                                    count(*) over(partition by id) cnt
                              FROM  t
                           )
                     WHERE rn != status_seq
                       AND cnt > 1
                  )
      ORDER BY id,
               status_date
    / 
    
            ID STATUS               STATUS_DA
    ---------- -------------------- ---------
             2 validated            13-APR-10
             2 ready for submission 14-APR-10
             2 ordered              15-APR-10
             3 ordered              16-APR-10
             3 ready for submission 17-APR-10
             3 validated            18-APR-10
    
    6 rows selected.
    
    SQL> 
    

    SY.

  • to get the last date of every month between year 2000 to 2100

    Hi all

    How we can make this last list date of every month between 2000 and 2100

    Thanks and greetings
    Vivek

    You must use the LAST_DAY() function:

    WITH months AS
    (
         SELECT      TO_DATE('01/01/2000','MM/DD/YYYY') AS dt1
         ,     TO_DATE('12/31/2100','MM/DD/YYYY') AS dt2
         FROM     DUAL
    )
    SELECT LAST_DAY(ADD_MONTHS(dt1,level-1)) LST_DAY_MONTHS
    FROM     months
    CONNECT BY LEVEL <= MONTHS_BETWEEN(dt2,dt1)+1
    

    Sample of results (too many to display):

    LST_DAY_MONTHS
    -------------------
    01/31/2000 00:00:00
    02/29/2000 00:00:00
    03/31/2000 00:00:00
    04/30/2000 00:00:00
    05/31/2000 00:00:00
    06/30/2000 00:00:00
    07/31/2000 00:00:00
    08/31/2000 00:00:00
    09/30/2000 00:00:00
    10/31/2000 00:00:00
    11/30/2000 00:00:00
    12/31/2000 00:00:00
    01/31/2001 00:00:00
    02/28/2001 00:00:00
    03/31/2001 00:00:00
    04/30/2001 00:00:00
    05/31/2001 00:00:00
    06/30/2001 00:00:00
    07/31/2001 00:00:00
    08/31/2001 00:00:00
    09/30/2001 00:00:00
    10/31/2001 00:00:00
    11/30/2001 00:00:00
    12/31/2001 00:00:00
    01/31/2002 00:00:00
    02/28/2002 00:00:00
    03/31/2002 00:00:00
    
  • Problem link DB between active Data Guard and reports application database

    My version of the 11.2.0.2.0 and OS database is Oracle Solaris 10 9/10.
    I am facing a problem in my custody of data Active data base for purposes of tax. Active Data guard information is as below.

    SQL > select name, database_role, open_mode from v$ database;

    NAME DATABASE_ROLE OPEN_MODE
    --------- ---------------- --------------------
    ORCL PHYSICS READ SHALL ONLY APPLY

    Detail of the problem is less than
    ------------------------------
    I have created a db link (name: DATADB_LINK) between active data guard and report of application of data base for purposes of tax.
    SQL > create database DATADB_LINK link to connect to HR identified by HR using 'DRFUNPD ';
    Database link created.

    But when I run a query using db link to my database of enforcement report I got this error below.

    ORA-01555: snapshot too old: rollback segment number 10 with the name ' _SYSSMU10_4261549777$ ' too small
    ORA-02063: preceding the line of DATADB_LINK

    Then I see logfile named database alart Active Data Guard and get below error

    ORA-01555 caused by the following SQL statement (SQL ID: 11yj3pucjguc8, time of request = 1 sec, SNA: 0x0000.07c708c3): SELECT "A2". "' BUSINESS_TRANSACTION_REFERENCE ', 'A2 '. "' BUSINESS_TRANSACTION_CODE ', MAX (CASE 'A1'. "TRANS_DATA_KEY"WHEN "feature' AND 'A1'." " END OF TRANS_DATA_VALUE"), MAX (CASE 'A1'. "TRANS_DATA_KEY" WHEN 'otherFeature' THEN 'A1' '. "" END OF TRANS_DATA_VALUE")

    But the interesting point if I run the query report directly in the Active Data Guard database, I got never error.

    So it's a problem of link DB between active Data Guard and other databases?

    Fazlul Kabir Mahfuz wrote:
    My version of the 11.2.0.2.0 and OS database is Oracle Solaris 10 9/10.
    I am facing a problem in my custody of data Active data base for purposes of tax. Active Data guard information is as below.

    SQL > select name, database_role, open_mode from v$ database;

    NAME DATABASE_ROLE OPEN_MODE
    --------- ---------------- --------------------
    ORCL PHYSICS READ SHALL ONLY APPLY

    Detail of the problem is less than
    ------------------------------
    I have created a db link (name: DATADB_LINK) between active data guard and report of application of data base for purposes of tax.
    SQL > create database DATADB_LINK link to connect to HR identified by HR using 'DRFUNPD ';
    Database link created.

    But when I run a query using db link to my database of enforcement report I got this error below.

    ORA-01555: snapshot too old: rollback segment number 10 with the name ' _SYSSMU10_4261549777$ ' too small
    ORA-02063: preceding the line of DATADB_LINK

    Then I see logfile named database alart Active Data Guard and get below error

    ORA-01555 caused by the following SQL statement (SQL ID: 11yj3pucjguc8, time of request = 1 sec, SNA: 0x0000.07c708c3): SELECT "A2". "' BUSINESS_TRANSACTION_REFERENCE ', 'A2 '. "' BUSINESS_TRANSACTION_CODE ', MAX (CASE 'A1'. "TRANS_DATA_KEY"WHEN "feature' AND 'A1'." " END OF TRANS_DATA_VALUE"), MAX (CASE 'A1'. "TRANS_DATA_KEY" WHEN 'otherFeature' THEN 'A1' '. "" END OF TRANS_DATA_VALUE")

    But the interesting point if I run the query report directly in the Active Data Guard database, I got never error.

    So it's a problem of link DB between active Data Guard and other databases?

    Check this statement that applies to your environment

    * ORA-01555 on Active Data Guard Standby Database [1273808.1 ID] *.

    also

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:8908307196113

  • days between two dates, excluding Saturday and Sunday

    Hello
    I have an obligation as: there are two entries in the query 1) startdate and 2) end date when the end user enter the start date and end date of the sql query to retrieve the number of days between given dates of beginning and end, and it should be retrivied with two condition 1) every Sunday between the above dates excluded 2) second and fourth Saturday of the month between the start dates and should be excluded.
    example of start date: 01-May-09
    end date: 16-May-09

    release date: 13

    SELECT COUNT (*)
    (SELECT TO_DATE('01-may-09') + LEVEL - dates 1)
    OF THE DOUBLE
    CONNECT BY LEVEL<= (to_date('16-may-09')="" -="" to_date('01-may-09'))="" +="" 1)="">
    WHERE ((TO_CHAR (inner.dates, 'd') = 7
    AND TO_CHAR(inner.dates, 'W') NOT IN (2, 4)
    )
    GOLD TO_CHAR (inner.dates, 'd.') not in (1.7)
    );

  • Dynamic calculation of the number of days between two dates in a table

    Hello

    I'm working on request where I dynamically calculate the number of days between two dates in a table.

    The calculation must be dynamic, i.e., when I recover the Start_date and End_date and move to the field following (call_duration) in the same row, the difference must be calculated dynamically in this area and make sure the field read-only.

    APEX version: 5.0

    Hi BO123,

    BO123 wrote:

    Hello

    I'm working on request where I dynamically calculate the number of days between two dates in a table.

    The calculation must be dynamic, i.e., when I recover the Start_date and End_date and move to the field following (call_duration) in the same row, the difference must be calculated dynamically in this area and make sure the field read-only.

    APEX version: 5.0

    one of the way to do this by calling ajax on change of end_date.

    See the sample code given below to fetch the resulting duration and making the field read only after calculation

    Step 1: Change your page

    under CSS-> Inline, put the code below

    .row_item_disabled {
      cursor: default;
      opacity: 0.5;
      filter: alpha(opacity=50);
      pointer-events: none;
    }
    

    Step 2: Create on demand Ajax process I say CALC_DURATION

    Please check Procces Ajax, see line 6.7 How to assign a value to the variable sent by ajax call

    Declare
      p_start_date  date;
      p_end_date    date;
      p_duration number;
    Begin
      p_start_date  := to_date(apex_application.g_x01);
      p_end_date    := to_date(apex_application.g_x02);
    
       --do your calculation and assign the output to the variable p_duration
      select p_end_date - p_start_date into p_duration
        from dual;
    
      -- return calculated duration
      sys.htp.p(p_duration);
    End;
    

    Step 3: Create the javascript function

    Change your page-> the function and the declaration of the Global Variable-> put the javascript function

    You must extract the rowid in the first place, for which you want to set the time, see line 2

    assuming f06, f07 and f08 is the id of the start date, and end date columns respectively, and duration

    See no line no 8 how set the value returned by the process of ajax at the duration column

    Replace your column to the respective column identifiers in the code below

    function f_calulate_duration(pThis) {
      var row_id  = pThis.id.substr(4);
      var start_date = $('#f06_'+row_id).val();
      apex.server.process ( "CALC_DURATION", {
      x01: start_date,x02: $(pThis).val()
    }, { success: function( pData ) {
    // set duration to duration column
    $('#f08_'+row_id).val(pData);
    // disable duration column
    $("#f08_" + row_id).attr("readonly", true).addClass('row_item_disabled'); }
    });
    }
    

    Step 4: choose the end date call the javascript function

    Go to report attributes-> edit your Date column end-> column-> Attrbiutes element attributes-> put the code below

    onchange="javascript:f_calulate_duration(this);"
    


    hope this helps you,

    Kind regards

    Jitendra

  • Number of Saturdays between two dates

    Hello

    How can I get number of Saturdays between two dates, including the two dates?

    for example number of Saturdays between 09/05/2014 and 10/05/2014 is five

    Help, please

    I use oracle 10g

    SQL> with t
      2  as
      3  (
      4  select to_date('05/09/2014 ', 'dd/mm/yyyy') from_dt
      5       , to_date('05/10/2014 ', 'dd/mm/yyyy') to_dt
      6    from dual
      7  )
      8   select to_char(from_dt + (level-1), 'fmDay') day_
      9        , count(*) cnt
     10     from t
     11  connect
     12       by level <= to_dt - from_dt + 1
     13    group
     14       by to_char(from_dt + (level-1), 'fmDay');
    
    DAY_             CNT
    --------- ----------
    Saturday           5
    Thursday           4
    Tuesday            4
    Friday             5
    Wednesday          4
    Monday             4
    Sunday             5
    
    7 rows selected.
    
    SQL>
    
  • Backup between two dates

    Hello

    I am new to oracle dba.

    Week on the Sunday backup last (June 16) is not from my 8.1.7.2.1 oracle database, today 19 June he has been identified.

    Now, I want to take backup of my database from June 10 to June 15.

    Please let me know if it is possible to perform a full backup of all the files (datafiles, redologs, control file) between 10 and 15 June.

    If Yes, please provide me with the syntax or the example.

    My database is in ARCHIVE.

    You cannot take the full backup just between 2 dates. You just need to take full backup of your database. And if you have all the records recorded after June 10, you can recover your database to any point in time by using the backup from 10 June.

    Documentation and syntaxes for your backup:

    http://www.Oracle-base.com/articles/8i/Recovery-Manager-8i.php

  • Calculate the hours between two dates

    Hello

    I have a requirement to count the hours with 2 given timestamps, something like:
    SQL> select ((to_date('22-oct-2012 13:00:00','dd-mon-yyyy hh24:mi:ss') - to_date('20-oct-2012 13:00:00','dd-mon-yyyy hh24:mi:ss'))*24) B from dual ;
    
             B
    ----------
            48
    However, I wish it would be that simple. I just need to count the hours between two timestamps for the hours of work for example, 08:00 - 17:00, MONDAY to Friday (excluding weekends).
    So lets say I have to count the hours between two dates above the result should be 18 hours not 48 (4 hours on 20/oct, 9 hours on 21/oct to 5 hours 22/oct).
    How can I achieve this? Any idea will be useful.

    Thank you

    My query generates a list of all the hours between the start and end time, filters on the hours that are outside of the hours of work and then account for the remaining lines. Change that to partial hours must just be a case of replace the two occurrences of 1/24 with 24/01/60, then - as say you - Division COUNT (*) by 60.

    There may be performance issues using techniques of generation of line like this, if you put this in a query involving the joining of several lines of other tables (for example where the dates of beginning and end are derived from several employees?) or in several days. If you don't find it then count the number of whole days (taking weekends into account) between dates and work on the partial days after that it could be better. This would probably involve a lot of statements of case (which I don't have time to test it now).

    Ben

  • How do the time difference between two dates?

    Hi all

    I use this query to get the time difference between two dates.

    Select to_timestamp ('2012-10-03 12:00 ',' YYYY-MM-DD hh)-to_timestamp ('2012-10-03 11:00 ',' YYYY-MM-DD hh) as double diff;

    but do not get the correct result.

    Thank you

    Left KEY... Left Padding of tanks.

  • How to caluclate tat between two dates of a timestamp field

    Hello
    could help to caluclate days between two dates and unique timestamp filed with this
    query
    Select * from m_activity_transaction where actn_opp_id in)
    Select actn_opp_id in the m_activity_transaction where ACTN_ACTV_ID = 218
    Actn_opp_id group
    view count (*) > 1) and ACTN_ACTV_ID = 218
    order of actn_performed_on
    IAM get output is

    ACTN_ID ACTN_OPP_ID ACTN_PERFORMED_ON
    319415 95831 JANUARY 27, 12 AM 11.06.20.000000
    315249 95831 8 FEBRUARY 12 05.32.54.000000 PM
    301927 103509 20 DECEMBER 11 04.01.43.000000 PM
    301458 103509 19 DECEMBER 11 04.51.03.000000 PM
    294841 115840 10 JANUARY 12 03.20.12.000000 PM
    312062 115840 11 JANUARY 12 05.17.06.000000 PM

    Normand to caluclate number days between two dates like January 27, 12 AM 11.06.20.000000 and I 05.32.54.000000 8 February 12 PM where actn_id is unique AND ACTN_OPP_ID IS NOT UNIQUE.
    Thanks in advance,
    VVR.

    In this way.

    with data as
    (
    select 315249 a, 95831 b, to_date('27-JAN-12 11.06.20 AM', 'DD-MON-RR HH.MI.SS AM') dt from dual union all
    select 319415, 95831, to_date('08-FEB-12 05.32.54 PM', 'DD-MON-RR HH.MI.SS AM') from dual union all
    select 301927, 103509 , to_date('20-DEC-11 04.51.03 PM', 'DD-MON-RR HH.MI.SS AM') from dual union all
    select 301458 , 103509 , to_date('19-DEC-11 04.01.43 PM', 'DD-MON-RR HH.MI.SS AM') from dual union all
    select 363810 , 144656 , to_date('27-JUN-12 12.43.28 PM', 'DD-MON-RR HH.MI.SS AM') from dual union all
    select 363500 , 144656 , to_date('26-JUN-12 11.41.50 AM', 'DD-MON-RR HH.MI.SS AM') from dual union all
    select 363354 , 144656 , to_date('25-JUN-13 12.41.13 PM', 'DD-MON-RR HH.MI.SS AM') from dual
    )
    select a, b, diff_in_days
      from (
            select a, b, trunc(dt - lag(dt) over (partition by b order by dt, a)) diff_in_days
              from data
           ) tab
     where tab.diff_in_days is not null;
    
    A                      B                      DIFF_IN_DAYS
    ---------------------- ---------------------- ----------------------
    319415                 95831                  12
    301927                 103509                 1
    363810                 144656                 1
    363354                 144656                 362
    
  • Request for between two dates.

    Hello

    I have a date column and I want to choose the records between two dates, the output of this column is: 19/08/2003-02:11

    My query is:

    SELECT THE POINT DTM
    WHERE DTM BETWEEN JULY 1, 2012 "-JULY 15, 2012"

    Help, please.

    Thank you

    >
    I have a date column and I want to choose the records between two dates, the output of this column is: 19/08/2003-02:11

    My query is:

    SELECT THE POINT DTM
    WHERE DTM BETWEEN JULY 1, 2012 "-JULY 15, 2012"

    Help, please.
    >
    Help with what? You do not have a question or indicate if you have a problem any.

    Do you need to know how to use TO_DATE instead of literals in the WHERE clause?

    SELECT DTM FROM ITEM
    WHERE DTM BETWEEN TO_DATE('07/01/2012', 'MM/DD/YYYY') AND TO_DATE('07/15/2012', 'MM/DD/YYYY');
    

Maybe you are looking for