need records from last month

Hi, using Oracle 11 g R2.

The last day of every month of every year, I would like to query the data of a table in the last month. For example, if today is December 31, 2013, I would like to query only the records with a settlement_dt between the two (and including) 1 December 2012 and 31 December 2012. My process will run automatically at the end of each month, so I cannot hardcode the date values. I developed the following solution, but I was wondering if anyone had other ideas.

To_char (io.settlement_dt, 'LUN') | To_char (io.settlement_dt, "YYYY") =

TO_CHAR (SYSDATE, 'LUN') | TO_CHAR (SYSDATE, 'YYYY')

Thank you!

Hello

The most effective way is

IO.settlement_dt > = TRUNC (SYSDATE, 'MONTH')

AND io_settlement_dt<  add_months="" (trunc="" (sysdate,="" 'month'),="">

This will allow the optimizer to use an index on io.settlement_dt.  In addition, it involves only 3 function calls, regardless of the number of lines is in the table (in other words, no function should be called for each line).

Tags: Database

Similar Questions

  • Search mail finds only mails from last month

    Suddenly my mail search is only to find mails from last month. The other mail that is in the Inbox however dose search not find it.

    Suggestions of what is going wrong here. It used to work fine.

    Thanks for any help!

    You can see the old mails in folder to archive.

  • Programming logic needed to retrieve the records for the last month/week

    Hi all

    I need assistance in programming SQL logic.

    Oracle database version: 10.2.0.3.0

    Requirement

    In an environment of DW, I need to program to weekly and monthly automated batch insert the data from Data_tbl to Reporting_tbl to generate reports. Descriptions of paintings are given below.

    Table 1 - Data_tbl (Source of table - this table is updated daily).

    Record_dt first name last name


    Table 2 - Reporting_tbl_ (the target table)

    Cycle_dt first name last name

    1. monthly report

    In the SQL query, I where clause conditions.

    Where Record_dt > = 1 November 08 ' and record_dt < = 30 November 08 '

    Using the above condition in development, I'm pulling over the last months data source table data. This will be repeated every month, and it should be automated.
    that is, if I run this report at any time in December 2008, he should choose documents dates from Nov 01 to November 30, 2008. If I run this report at any time in January 2009, he should choose documents dates to Dec. 01 to December 31, 2008.
    Date values must be assigned for the last month. Value of Cycle_dt in the target table must be the date of the end of last month as on November 30, 2008, 31-dec-2008.


    2 weekly Report

    In the SQL query, I where clause conditions.

    Where Record_dt > ='01-dec-08' and record_dt < ='' 07-dec-08

    Monday week start date and end date is Sunday.
    If I run the report between the 08 Dec-14 Dec, it should make records of the dates of Dec. 01 to December 7, 2008.
    On 15 December, he should seek from 08 Dec-14 Dec.
    Value of Cycle_dt in the target table must be the date of last weekend, as on December 7, 2008, December 14, 2008.
    Please help me with the logic for both monthly and weekly reports.

    Thank you

    Hello

    TRUNC (dt, 'W') is the beginning of the week, which may be different days, according to the NLS parameters in your session. Unless you want something that varies from one session to the next, you should stick with the weeks of ISO.

    TRUNC (SYSDATE + 1, 'IW') - 1
    

    is the Sunday of the week underway Sunday to Saturday, which starts and ends in 1 day before the ISO week.
    To find the precedent of the week from Sunday to Saturday:

    WHERE   record_dt >= TRUNC (SYSDATE - 6, 'IW') - 1
    AND     record_dt <  TRUNC (SYSDATE + 1, 'IW') - 1
    

    If you were interested in a week from Saturday to Friday (either 2 days earlier than the ISO week):

    TRUNC (SYSDATE + 2, 'IW') - 2
    
  • Select the last record of each month

    Hello

    to select the last docnumber and qty of every month

    Structure

    Name Null?    Type

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

    PRODUCTCODE NUMBER

    NUMBER NUMBER

    DATE OF PLANFORMONTH

    NUMBER OF CLEXPECTEDQTY

    NUMBER OF CLCONFIRMQTY

    NUMBER OF CLFGBUFFERQTY

    NUMBER OF CLTOTPRINTBUFFER

    in this select query if I take the sum he required all records where, as I want the last record of each month

    SELECT productcode docnumber MAX (Number), planformonth, SUM (clexpectedqty) clexpectedqty (planformonth) MAX.

    SUM (clconfirmqty) clconfirmqty, SUM (clfgbufferqty) clfgbufferqty, cltotprintbuffer OF FGSALESPLAN of the SUM (cltotprintbuffer)

    GROUP BY productcode, (planformonth)

    Sandy

    Hello

    Thanks its working now the code is written as below:

    SELECT * FROM

    (SELECT

    e.*,

    ROW_NUMBER() OVER (partition by PRODUCTCODE by DOCNUMBER DESC order) r

    Of

    E FGSALESPLAN)

    WHERE r = 1 AND

    entryvalid = 'Y '.

    order by Number

    Sandy

  • remove the last record from the plsql table

    TYPE r_LOOPElement IS RECORD (TermID   NUMBER 
                                          );
    
    TYPE t_LOOPType IS TABLE OF r_LOOPElement INDEX BY BINARY_INTEGER;
    i_CustomerLoop      t_LOOPType ;
    
    i_CustomerLoop(1).TermID=1;
    i_CustomerLoop(2).TermID=2;
    i_CustomerLoop(3).TermID=3;
    Under certain conditions, I need to remove the last record from i_CustomerLoop

    whichi s the best way to do it. because I sometimes get duplicates for TermID in this plsql table.

    Hello

    See [removing items from Collection (DELETE method) | http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/collections.htm#CJAFGFIG]

    Kind regards

  • What version of windows 7 (prof. or last month), I need to purchase to install the desktop built House. Thank you.

    What version of windows 7 (prof. or last month), I need to purchase to install on my sub computer built House. Thank you.

    Take a look at this link as it will show you the differences.

    http://Windows.Microsoft.com/en-CA/Windows7/products/compare#T1=tab01

    I hope this helps.

  • After worsening in the last month that I finally drop with Firefox - 2 hours trying to get today and still not satisfactory - what happens?

    It is impossible for me to put in operation these days and get an instant response. The faster this last month has been an hour - after will disappear and return at intervals. It seems to go better after 08:00 but that it no good for one early don't like me - I should be able to connect at any time, but I can't. As I'm not technically mind I pay someone to come and fix this - and they seem to do it but then it would be when they visit later in the day - but as soon as they are out of the door he's back. I was recommended to use Firefox as it is no longer compatible for my use and served for three years, but now I'm going back to what I've already used on the need, of despair and frustration. Shockwave flash may be busy... plugins does not respond. I am happy to see the back of all this, but such a shame really.

    You seem to be using a very old Firefox profile folder.

    For example, your system details list shows security.enable_ssl2: True and SSL2 did not had been in charge for a while now (Firefox 8 +), so it might be a good reason (opportunity) to start with a fresh profile, through a refresh or through the Profile Manager.

    Reset is not too difficult and requires to open help > troubleshooting information page.
    This page has a reset button to reset Firefox and create a new profile.

    Another possibility is to hold down the SHIFT key pressed when Firefox starts with a double click on the shortcut on the desktop.

    This gives the Safe Boot Mode dialog box that also has a button Reset Firefox.

    When you reset Firefox and a new profile is created and some personal data (bookmarks, history, cookies, passwords, data form) are automatically imported and the current profile folder will be moved on the desktop to a folder "Old data Firefox".

    Installed extensions and other customizations (toolbars, Pref.) that you have made are lost and must be redone.

    It is possible to recover more data from the old profile, but be always careful not to copy the files corrupted to avoid transporting on the problem.

  • Bought a 750D (Rebel T6i) last month - all overexposed images

    I bought a Canon D 750 last month and used during my trip to South Africa. I shot in raw in different modes - Av, Tv, car, etc., but all my pictures are superexposed and all my memories of travel are in ruins. I tried to get a lot of pictures by adjusting the specificities and exhibition in Lightroom, but many photos are so white they are ruined forever.

    Since I've been doing photography for a few years, I'm sure that's not on the settings I used. Can someone let me know what could be the problem. I'm uploading some photos converting them to JPEG such what (i.e. without any balance white or the exposure setting) - you can see what happened.

    I also tried all the setting of compensation, as mentioned on various forums and take more photos, but they are always overexposed.

    Please help me - I need to get this fixed as soon as I'm on a trip to Mexico soon.

    Here's your biggest mistake.

    «... for the most part in AV mode with auto OF...» »

    I suggest you select an ISO and stay with it until you feel it is necessary to change.  I don't like leaving the use of the camera an ISO floating and I never use it.   All the photos you shared have no real opening value requirement. What is your reasoning? These shots could be easily made using P (program mode) and an ISO set to 100.

    On issues of sweetness, you're probably there with the kit lens.  You could modify your own technique and help a little.  Avoid the apertuers largest and smallest.

    The sky is always a problem.  It is different from what your topic is usually many stops.  You can try different Styles of picture in the menu.  You can make your own to bring out the sky better.  But these are usually only for jpg.

    RAW indicates you want TO publish processes, jpg said that you do not want.  If you want to contunue to use RAW, I'm afraid that you like better work "tiring" of the edition of all your shots.  Do you know how to use the predefined settings?  A course of Lightroom is perhaps in order.

  • I bought last month, a computer model laptop sony vaio SVE151D11M. I did a recovery of the value. How to get

    Dear...

    I bouight last month a Sony vaio laptop. Model SVE151D11M

    I did a recovery of the value.

    Now, the computer no longer starts and demand for recovery disks.

    But I do not have such a set.

    How can I get a recovery set, so I start from my laptop again.

    Please help me and thanks in advance,

    Kind regards

    Down Jonker

    Hello, I need a cover for my Sony Vaoi SVE151D11M model

    Thank you

    Kind regards

    Down Jonker

  • Range of dates - last month

    Hello community,

    first: I am new to Oracle databases...

    I need query our database of the ERP system and to select the data for the last month every time I run the query.

    that is today (March 4th), the query selects all records between February 1 and February 28.

    I'm playing with Sysdate-1 etc., but can´t to find a solution.

    Thank you

    Heiko

    bzzt. the OP wants the previous calendar month, not for the last 30 days.

    Heiko, have you tried your_date_column > = add_months (trunc (sysdate, 'LUN'),-1) and your_date_column< trunc(sysdate,="">

  • I am in the last month of my annual subscription of students creative cloud and I don't want to renew.

    I am in the last month of my annual subscription of students creative cloud and I don't want to renew it. I don't want to prematurely cancel.

    Yes, I you I need to contact a human being to check that it is in fact me and that I am allowed to change my subscription.

    But you are making it difficult for me because your cat of 9 to 5 support is not available at the time I write this (09:30). I'm at work right now so I won't be able to use the phone and your phone support stops at the moment wherever I get home from work.

    And I'm not ready to hang on the phone for more than 90 minutes. Yes, I looked in the forum for this issue.

    While I was writing this cat went online an hour late. But they told me to post on the forum while I wait, so here I am, led evacuation.

    Fact. Who's fast, contrary to my expectations.

    Hope this works when the contract is completed.

  • Help: Last month last day until 12:00

    Hello people,
    I'm trying to get the last months last day in the query for a report. I tried the code below
       TRUNC (SYSDATE, 'MONTH') - 1  
    but he returned
    11/30/2009 12:00:00 AM
    but I need to get the data until 12:00. Can someone please shed some light on this. Thank you

    Hello

    Since it is currently some time in December 2009.

    TRUNC (SYSDATE, 'MONTH') - 1
    

    Returns 30 November 2009 00:00:00 (i.e. midnight or midnight).
    If you want really 12 PMor noon, just soustraire.5 days from the beginning of the month:

    TRUNC (SYSDATE, 'MONTH') - .5
    

    It will be on November 30, 2009 12:00.

    If you use this in conditions, such as:

    WHERE     entry_date     BETWEEN      start_date
                   AND      TRUNC (SYSDATE, 'MONTH') - 1
    

    where the goal is to get data only up to the end of last month, then you won't be midnight (00:00:00) or 12:00 (12:00:00); you want the last point in the day, 23:59:59 (23:59 min 59 s)
    You can get that by saying:

    WHERE     entry_date     BETWEEN      start_date
                   AND      TRUNC (SYSDATE, 'MONTH') - (1 / (24 * 60 * 60))
    

    but I find it easier and clearer to say:

    WHERE     entry_date     >= start_date
    AND     entry_date     <  TRUNC (SYSDATE, 'MONTH')     -- NOTE: strictly <, not =
    
  • Options set for the windows and tabs from last time

    Hello

    I put "Options/général" to display the tabs from last time. very suddenly earlier this week Firefox (I use Version 31) stop n apparent reason and since my tabs are is no longer registered despite article in the 'general' still reading of "save windows and tabs from last time '. How can I fix this? I tried one of the suggestions - remove the tick in the box next to 'do not load the tabs until you have chosen', but this made no difference. What I need to change something in the ' subject: config ' file?

    As well as to happen, my favorites have changed as well. Initially, the Bookmarks imported from Internet Explorer, and those created in Firefox was in a continuous string. There is now a separate file containing bookmarks to Internet Explorer. Is it possible to combine the two sets of bookmarks in a game as they were before?

    I know that the 31 Version has been updated, but the reason that I have not updated my current setup is that whenever I update Firefox something unexpected or undesirable occurs.

    It is best to not double-click the .js files: flowing through a shell script from Windows with potentially unpredictable consequences. To display as text, you can right-click > edit the .js file. (However, these files contain data which are difficult to interpret.)

    When the restoration of previous Session is grayed out, it can mean that Firefox (1) already restored your previous session or Firefox (2) did not find a historic session file. In this case, it seems that the #1 is more likely.

    The session history works in real time? I mean, if you right click on a link and open it in a new window, then close this window, the menu history lists it as a window, you can restore?

    So if you exit Firefox and restart it upward, is the closed window still listed in the history as a window menu, you can restore?

  • Why Firefox "display windows and tabs from last time", regardless of the options settings?

    I uninstalled and reinstalled Firefox because Firefox does not open home pages that have been defined in the Setup program.
    After you have reinstalled Firefox 'shows windows and tabs from last time' whatever the definition of boot options.
    What can I do to fix this?

    Hello

    The reset Firefox feature can solve a lot of problems in restaurant Firefox to its factory default condition while saving your vital information.

    Note: This will make you lose all the Extensions and preferences.

    • Sites Web open is not recorded in less than 25 versions of Firefox.

    To reset Firefox, perform the following steps:

    For Firefox 29,0 and above:

    1. Click the menu button

      click Help

      and select troubleshooting information. Now, should open a new tab containing your troubleshooting information.

    2. At the top right of the page, you should see a button that says "Reset Firefox"

      . Click on it.

    3. Firefox will close and reset. After Firefox is finished, it will display a window with the imported information. Click Finish.
    4. Firefox opens with all the default settings applied.

    Information can be found in the article Firefox Refresh - reset the settings and Add-ons .

    This solve your problems? Please report to us!

    Thank you.

  • Show my windows and tabs from last time does not not in 14.0.1

    Last week, the functionality of Firefox to display the tabs from last time has stopped working. He can't have worked earlier.
    I can't find any reference to what is a matter of news, but according to the existing guidelines and what I tried, it should work.
    Any ideas?

    It is possible that there is a problem with the sessionstore.js and sessionstore.bak files in the Firefox profile folder.

    Delete the sessionstore.js file possible sessionstore-# .js files with a number and sessionstore.bak in the Firefox profile folder.

    Delete sessionstore.js will cause App Tabs and tab groups and opened and closed the tabs (back) to get lost, so you will need to create them again (take note or bookmarks).

Maybe you are looking for

  • Extras IMessage in IOS 10

    Hi all. I just upgraded to IOS 10 and hate the new iMessage extras. Balloons, stickers... Is it possible to disable the part of the user interface? Just like the keyboard of predictive text?

  • behavior of folder

    (1) using an iMac 2009 El cap 10.11.4 running and (the fool that I am) can not "for the life of me" "" how to remove the column on the right side of the folder window? looked at. System Preferences preferences from the Finder and CLICKED RIGHT folder

  • Columns of burning on the Windows Media Player software.

    I am trying to burn my own CD of music using Windows Media Player 11, but the columns of information (name, composer, etc.) will not the library on CD transfer. Only the track number and the time will transfer. How to make ALL the columns of the CD?

  • Incompatible print cartridge Photosmart C4780

    Bought a printer Photosmart C4780 USA and brought it to UK Used 60XL (CC644WN) print cartridges in the United States United Kingdom bought real HP 300XL black print cartridge (CC64EE UUS) Laid out, cartridge black HP 300XL but printing gives the inco

  • HP M476dw out of Memory

    Hello Quite recently I bought the HP M476dw I get an Out of Memory, even when you print pages 1 documents sometimes! What is going on, I thought that it was a printer of class business, why I'm out of memory? How can I fix?