Function to move all dates to previous monday

Here is what I have:
create or replace
FUNCTION ToPreviousMonday
(DATE_FIELD IN date)
RETURN date
AS
BEGIN
IF TO_DATE(DATE_FIELD,'DAY')='SUN' THEN (DATE_FIELD)-6;
ELSE trunc(DATE_FIELD,'D')+1;
END IF;
END ToPreviousMonday;
Won't compile.
Basically what I want to accomplish is in a SELECT statement say something like (SELECT ToPreviousMonday(MyDateField) FROM MyTable) and cause the data to comeback as the date of the previous monday. NLS_TERRITORY is and will be for all sessions going to have Sunday as weekday 1.
Any pointers?

select trunc(next_day(sysdate, 'PIRMDIENA'))-7 from dual
Pirmdiena as you definitely know is Latvian for Monday ;)
Gints Plivna
http://www.gplivna.eu
oh, somebody got even more elegant solution :)
Edited by: gintsp on Oct 14, 2010 6:04 PM

Similar Messages

  • Exp move all data

    Hello,
    I would like to move all data from one database (10.2.0.1 32 bit) to the fresh environment 10.2.0.4 on 64 bit architecture. So I have some questions:
    - Can I use for this migration EXP / IMP utility ? All data contains about 10GB, and I can make downtime of database for exp and imp.
    - Should I use a full (FULL=Y) export with system user, and import to new enviroment ?
    - Do I need to create any tablespaces, roles, schemas on new database ?
    Can you give some hints about this kind of migration?
    Thank you a lot,
    Jimmy,

    If I understand, you don't recommend to use EXP with FULL=Y option. Why?
    Actually A full database export and import can be used in all Oracle version to transfer a database across platforms. IMP full=y + ignore=Y
    Anyway when you use imp ...full = y + ignore=Y , that might make more time than import each of schemasOn the target database I should first create all tablespaces, with temp tablespaces, create all users and use IMP utility with option FROMUSER=XXX TOUSER=XXX to import
    if you use FROMUSER=XXX TOUSER=XXX
    You have to create tablespaces, roles , profile , users and grant anything like source databaseWhat about roles? Is this possible to export only roles using EXP utility? Should I export anything else from source database?
    DBA or sysdba roles ,that can export full=y
    You should export full from source database...
    after that you can import full or each of schemas.You have a lot of schema, I think You should use exp/imp full=Y... this might good solution.
    1. create target database
    2. get tablespaces name from dba_tablespaces on source database and then create tablespaces on target database.
    3. export FULL from source database
    exp system/password FULL=y FILE=exp_full.dmp LOG=exp_full.log 4. transfer binary dump file to target database
    5. import full=y + ignore=y
    imp system/password FULL=y FILE=exp_full.dmp LOG=imp_full.log IGNORE=y remark: you can use DATA PUMP, that faster EXP/IMP

  • How to move all data to another drive?

    I've just upgraded to Tiger and simultaneously installed two internal Seagate 325GB drives in mirror RAID configuration. I plan to keep the original 80GB drive for OSX and applications only, and move all documents, photos and music to RAID. But I'm not sure how to link the applications (iPhoto, iTunes, Word, Entourage etc) so they know where to find existing data and where to save new data. I can't find specific instructions anywhere. Could someone walk me through the steps?

    Allan: I do appreciate your spending so much time to try to make sure I understand your real concerns about RAID as a backup. Since first questioning your explanation I have re-read most of the discussion threads on the topic, and noted that over the years, you have been passionately warning about mirrored RAID arrays for private and amateur people like me, on the perfectly reasonable grounds that we are not fully protected. I also noted that you are/were an IBM IT professional and bring that experience and viewpoint to the discussion. I suggest that explains our different perspectives. For the last five years I have been running without hard drive backup of any kind; relying on burning my most important data - photos and movies - to disk, until I could figure out the best way to use my machine's capabilities. Heeding warnings of the inevitabile end of my one internal drive, I decided to install twin drives in the available bays and configure them in a mirrored RAID to insure against main drive failure. That is my priority. In 26 years use of PCs and Macs, I have not found accidental deletion, application quits or keyboard mistakes to have been a noticeable, let alone significant problem. (I did lose a whole chapter of a book once, but that was because I forgot to enable Auto-save. Neither RAID nor backup would have protected against that!) I did also notice that in the forum discussions, nobody could report problems with their RAID setups or with recovery in the case of a failed drive. (I know, absence of evidence is not evidence of absence but at least there doesn't seem to be a great problem). So for a home user, I've concluded that the RAID setup is both the most appropriate for my needs, and the best value for money. I guess we'll have to disagree, but thank you for explaining your point of view. I do hope that our discussions has set out the pros and cons of RAIDs clearly, for the benefit of other readers.
    Geoffrey
    Powermac G4 Quicksilver Dual 800/ iBook G3 700   Mac OS X (10.4.9)  
    Powermac G4 Quicksilver Dual 800/ iBook G3 700   Mac OS X (10.4.9)  

  • Move all data from one database to other using oracle expdp and impdp tool

    I need to move all of the data from one database to another. For that I am using oracle expdp and impdp tool.
    I have the full database export dump file. I moved that dump file to my other database.
    Now when I try to use impdp tools it gives lots of error regarding path mismatch,user not exists, role not exists.
    As my datafile path of source database does not match with the target database path , also the users are not there in target database. I dont want to create all the tablespaces that in my source database as there are 82 tablespaces.Is there any way by which I can move my all data without using remap option for tablespaces or users and grants.

    The FULL parameter indicates that a complete database export is required. The following is an example of the full database export and import syntax.
    The user must have the privielge of EXP_FULL_DATABASE
    expdp system/password@db10g full=Y directory=TEST_DIR dumpfile=DB10G.dmp logfile=expdpDB10G.log
    impdp system/password@db10g full=Y directory=TEST_DIR dumpfile=DB10G.dmp logfile=impdpDB10G.logGO through below linkfor more details...
    http://www.oracle-base.com/articles/10g/OracleDataPump10g.php
    Regards
    Umi
    Edited by: Umi on Feb 4, 2011 2:27 AM

  • Can I move all data and programs from Tungsten C to a Pre?

    I love my Tungsten C and I want to get a Pre as soon as it hits Verizon.  Will I be able to move all my data and programs easily over to the Pre?  (I know I have to get the Classic app to run old Palm programs.)   I can synch to either a Vista or XP computer.  I don't synch email or with Outlook contacts.
    Thanks so much. I hope I posted in the right subforum.
    -Miss Bert
    Post relates to: Tungsten C

    Hello Miss Bert and welcome to the Palm forums.
     As you know, the Pre and Palm webOS are all new offerings from Palm.  You are correct in that you will need MotionApps Classic to run your old Palm OS 5 application on the Pre.  What you should know is that Classic does not sync to Palm Desktop/Outlook.  When you get your Pre, regardless of what carrier it is on, you will be breaking the ties with Palm Desktop and the HotSync Manager.
     There are a few options for migrating your data from the Tungsten C to the Pre.  To learn about those options, check out Palm's Pre Migration web page.
    Alan G

  • What is the best way to move all data and apps from an old ipad to a newq ipad air?

    What is the best way to convert (update) from an original ipad to a new ipad air?

    How to Transfer Everything from an Old iPad to New iPad
    http://osxdaily.com/2012/03/16/transfer-old-ipad-to-new-ipad/
    iOS: Transferring information from your current iPhone, iPad, or iPod touch to a new device
    http://support.apple.com/kb/HT2109
    Moving Content to a New iPad
    http://tinyurl.com/qzk2a26
    Transferring your prepaid cellular data account depends on your carrier. AT&T lets you move it yourself when you go to Cellular Data in Settings and log into your account with your previous AT&T user name and password. For iPads with Sprint service, you can set up an account on the new iPad and contact Sprint Customer Care (888-211-4727 and go through the menus) to deactivate the old plan and get credit for unused service. For Verizon, call the company’s customer service number for mobile broadband support (800-786-8419) and ask to have your account transferred.
     Cheers, Tom

  • Can I move all data from time machine backup to another external drive & work from it?

    Hi all, the harddrive on my macbook died (2nd time in a year) & I had a new one put in that's much smaller than the old one.  Can I move everything from my time machine backup onto a seperate external drive and work directly from that on my laptop/imac?  At the mo. I don't think time machine will recognise my computer as it's a new drive etc.  Thanks Jenny.

    What exactly do you want to do?
    Is it that you wish to extract an older version of some documents to edit, but leave the original intact?
    You can Restore an older version from TM and choose not to replace the current one.
    Or, do you wish to install the OS on your new drive, and migrate all the information from the TM backup to the new isntallation?
    EDIT: Ok, re-reading your question, I think macjack probably has the right idea.
    However, see Pondini's Time Machine FAQ # 16

  • How can I transfer all data in ATV to my new computer(HDD)?

    Last week, my macbook broke and replaced new HDD. All data in previous HDD has gone but some musics and pictures are still in ATV luckily. Please advise how I fetch the data from ATV to my new HDD just installed to my macbook.

    takky wrote:
    Thanks for your adivse. reg 2), how do I hack my apple TV?
    Not really something that can be discussed here in detail.
    Did you have Time Machine running? If so you may be able to pull back iTunes files.
    what is SSH? please adivse.
    If you don't know I think hacking might prove daunting for you.
    I've not hacked my AppleTVs so can't offer advice one way or another but I suggest you do not update your AppleTV to 2.2 yet, and you must not sync AppleTV to a new itunes library or it'll trash the exisiting content.
    Google 'AwkwardTV' and 'AppleTV hacks'.
    Personally I'd say that your safest option is probably to dismantle the AppleTV and connect the internal drive to a Mac via a USB or Firewire enclosure then manually track down the files - copy them only and don't alter anything on the drive. This would of course void any warranty - depends how important that stuff on AppleTV is.
    It also emphasises the importance of backing up stuff regularly though in practice we may not do so as often as we'd like.
    It also highlights two things:
    1 - There really should be a method of accessing stuff from AppleTV by manual drag and drop. I really don't understand why they don't implement it as your kind of issue is very frequent and you'd really thank Apple if that feature were available.
    2 - Currently AppleTV must not be regarded as external storage or a backup copy of iTunes files/photos. It is not designed to be a backup but with a little software enablement it could clearly to this. I suspect connection via USB would be frowned upon as people might try and access system files, but a 'rescue mode' via iTunes perhaps accessed via the diagnostics/system restore/reboot menu would be ideal.
    AC

  • Date function to pull back dates of the year?

    is there a built in function for returning all dates (whatever format) between to dates ?
    Example:
    Select functionname('2009/06/01', 'yyyy/mm/dd), ('2009/06/05', 'yyyy/mm/dd')
    from dual
    Wanted results
    2009/06/02
    2009/06/03
    2009/06/04

    Hi,
    user11210446 wrote:
    Here is what I'm trying to do,
    There is a start date and an end date. I have US holidays for current year in a table so for example christmas 12/25/2009
    I want to show dates between the start date and end date, and if there is a holiday on that date it will not show.
    make sense
    so if a user puts 12/23/2009 for start and 12/29/2009
    it would show
    12/24/2009
    12/26/2009
    12/27/2009
    12/28/2009Yes, that's very clear.
    I would actually do that with a NOT IN sub-query
    SELECT  TO_DATE ('&start_date', 'MM/DD/YYYY') + LEVEL - 1
    FROM     dual
    WHERE   TO_DATE ('&start_date', 'MM/DD/YYYY') + LEVEL - 1 NOT IN
            SELECT  appropriate_column
            FROM    holiday
    CONNECT BY LEVEL <= 1 + (TO_DATE ('&end_date', 'MM/DD/YYYY') - TO_DATE ('&start_date', 'MM/DD/YYYY'));where &start_date and &end_date are substitution variables in MM/DD/YYYY format. You could use bind variables just as well.
    This assumes the DATEs in holdiay are all midnight. If not, use TRUNC (appropriate_column).
    Edited by: Frank Kulash on Jun 4, 2009 12:59 PM
    There's nothing like clicking that "Save" button to give you better ideas!
    MINUS is a little simpler than NOT IN:
    SELECT  TO_DATE ('&start_date', 'MM/DD/YYYY') + LEVEL - 1
    FROM     dual
    CONNECT BY LEVEL <= 1 + (TO_DATE ('&end_date', 'MM/DD/YYYY') - TO_DATE ('&start_date', 'MM/DD/YYYY'));
    MINUS
    SELECT  appropriate_column     -- or TRUNC (appropriate_column)
    FROM    holiday
    ORDER BY 1;

  • Function to retrieve all days of the previous month.

    Hi,
    Yes, it's a monthly report i've been given the task to achieve.
    So, all I need is all days of previous month (even if there is no data for this day)
    I've been instructed to use the following code, but it does not return any value:
    DECLARE
       CURSOR CUR_LAST_DAY IS
          SELECT TO_CHAR (LAST_DAY (ADD_MONTHS (SYSDATE, -1) ), 'DD')
            FROM DUAL;
       VVA_LAST_DAY   VARCHAR2 (2);
       VNU_JOUR       NUMBER       := 0;
    BEGIN
       OPEN CUR_LAST_DAY;
       FETCH CUR_LAST_DAY
        INTO VVA_LAST_DAY;
       CLOSE CUR_LAST_DAY;
       WHILE VNU_JOUR <= TO_NUMBER (VVA_LAST_DAY) - 1
       LOOP
          VNU_JOUR := VNU_JOUR + 1;
       END LOOP;
    END;
    --CLOSE CUR_LAST_DAY
    --DEALLOCATE CUR_LAST_DAY-----
    On the other end, i've developped this code:
    SELECT TO_CHAR(SYSDATE,'dd')
    FROM DUAL
    WHERE TO_CHAR(SYSDATE,'dd') >= to_char(to_date(to_char(ADD_MONTHS(SYSDATE, -1),'yyyy-mm')||'-01'),'yyyy-mm-dd')
    AND TO_CHAR(SYSDATE,'dd') < to_char(LAST_DAY(to_date(to_date(to_char(ADD_MONTHS(SYSDATE, -1),'yyyy-mm')||'-01'),'yyyy-mm-dd')));Which is returning a null value. :(
    Regards

    Hello,
    You want to retrieve complete days of last month from one query...so here it is..
    SELECT
    TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY') COMP_DATE,
    TO_CHAR(TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY'),'DD') ONLY_DD,
    TO_CHAR(TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY'),'MM') ONLY_MM,
    TO_CHAR(TO_DATE(LEVEL||'-'||TO_CHAR(ADD_MONTHS(SYSDATE,-1),'MON-YY'),'DD-MON-YY'),'YY') ONLY_YY
    FROM DUAL
    CONNECT BY LEVEL <= TO_NUMBER(TO_CHAR(LAST_DAY(ADD_MONTHS(SYSDATE,-1)),'DD'))I am not at database machine so therefore not tested.
    But one thing keep in mind that this forum only for reports there is separate forum for sql and pl/sql.
    Function to retrieve all days of the previous month.
    -Ammad
    Edited by: Ammad Ahmed on Apr 22, 2010 10:53 PM
    Spelling Mistake

  • Moving LR5 catalog (Irdata & Ircat) to a new hard drive and photos. Lost all meta data - How do I move meta data along with catalog?

    I moved LR5 catalog (Irdata & Ircat) to a new hard drive and photos. Lost all meta data - How do I move meta data along with catalog?
    The meta data for each image is missing.
    I have over 2,000 images. I don't want to go back through each image and add meta data.
    Is there some way to move everything?

    No, do not re-import your images. I assume you can see the thumbnails in the library module, just cannot access the full images, right? If this is the case there should be an exclamation mark in the top right corner of every one of your pictures and you only have to tell LR where the images are now.
    Click the exclamation mark of one of the images and a dialog window should pop-up, telling you that LR cannot find the file, but with an option to locate it. Press "Locate" and navigate to the folder on your new HD where the file is. If in the new external HD you kept the same folder structure that you had on the internal disk, LR will be able to find all your images and re-link them to the database without further intervention.

  • How to move all app data from one user to another? (One mac)

    Hi. I've been having this problem for a while. So recently, I've made a new account for myself, since I was using my mom's user account. I don't want to keep all of my files, emails, and icloud on her user, since it's used by everyone in my family. I use iMail now because hotmail blocked my email because "Someone hacked me" and they kept it locked for all these months, and I can't give enough proof to show it was mine, since I forgot every email I've sent now.
    And iMail is pretty cool, adding your own rules and stuff. Except you don't need a password to log in. I just deactivate my iMail via system preferences as a log-out, and then re-activate it as a log-in.
    So, back to the question.
    How can I move ALL app data from my mom's user account to my new one? Her acount also has pictures of our germany vacation. So not every file.
    You see, I game on my mac mostly because steam is really complicated, using internet just to play a game that doesn't need internet and stuff.
    And steam doesn't have a lot of casual games.
    So I want to move my game data, save files and every little piece of application info that my games have on my mom's account to mine. I've asked this question on Yahoo answers, and all I got was an answer of "File IS data, or datum itself, You are wrong. I cannot give you an answer." -.-
    I'm not experienced with terminal either, so I'll need a ton of explanation of how to use it if that's how it can be done. It really really confuses me and I'll just give up.
    Thanks in advance.
    Oh and, side question, When will OS X Mavericks be open to public and how much will it cost?

    Nour j wrote:
    Oh and, side question, When will OS X Mavericks be open to public and how much will it cost?
    http://www.apple.com/osx/preview/
    Will be released sometime in the fall.  Cost unknow at this time as Apple has not released this info to the public.

  • I bought a new iMac today. I'm using migration assistant to move all my software, but the time just keeps getting longer. It says connect an Ethernet cable for faster data transfer. I did, but that doesn't seem to help. Any ideas?

    I bought a new iMac today. I'm using migration assistant to move all my software, but the time just keeps getting longer. It says connect an Ethernet cable for faster data transfer. I did, but that doesn't seem to help. Any ideas?

    m1doc,
    Are you migrating from a Mac or a MS Window machine? Either way you probably should be in touch with AppleCare, you have 90 days of free AppleCare telephone support. They can usually help on issues like this. If you don't know the phone number please use http://support.apple.com/kb/HE57 to help find the number in your country.

  • I have an Iphone 4 which I just updated with the latest software, which put in it in Recovery Mode. It has the picture of the plug with Itunes, I downloaded it now its saying its in Recovery Mode, how do I save all of my previous data without Restoring?

    I have an IPhone 4 which I just updated with the latest software, which put in it in Recovery Mode. It has the picture of the plug with ITunes, I downloaded it now its saying its in Recovery Mode, how do I save all of my previous data without Restoring?
    I updated the phone before backing it up on iTunes, now the update wanted me to connect the phone with iTunes and it says the phones in recovery mode and it must be restored before its used with iTunes. I go to click restore and it says it will reset it to factory default and I'll lose all my current data. I have all my sons pictures and videos along with this notes. I can't lose all of this data! Please help!

    You have to restore the iPod, no ifs, ands, or buts...
    After iOS is installed you will be asked if you what to set it up as a new iPod or if you want to restore from a backup.
    If you have a good backup you can restore that and you're good to go.
    If you don't have a good backup, then you end up with a "clean" iPod....

  • How do you transfer iTunes music and movies from an old PC to a new PC.  I have all data svaed on an external hard drive.

    How do you transfer iTunes music and movies from an old PC to a new PC.  I have all data svaed on an external hard drive.

    This article should outline the options
    http://support.apple.com/kb/HT4527

Maybe you are looking for