How to get a week number  for the year using oracle sql query?

hi everyone,
i have the requirement to find the week number for the calender..
so that week number should start with 01 when the year starts and it should end with week end date(that is first saturday of the january month).. so next week number starts with sunday and ends with saturday ,continously.. in the end date of the year it should not be 'saturday' but week number should end with last date of the year.. again in the next year it should start with '01'.
for example:
01-JAN-13 tuesday 01
02-JAN-13 wednesday 01
03-JAN-13 thursday 01
04-JAN-13 friday 01
05-JAN-13 saturday 01
06-JAN-13 sunday 02
07-JAN-13 monday 02
26-DEC-13 thursday 52
27-DEC-13 friday 52
28-DEC-13 saturday 52
29-DEC-13 sunday 53
30-DEC-13 monday 53
31-DEC-13 tuesday 53
01-JAN-14 wednesday 01
02-JAN-14 thursday 01
how can i achieve this, can anyone please help me out on this..
i have a query that starts with 01 when year starts but it gives problem in the end of the year .. described below with a query..
select mydate,
to_char(mydate,'day') as weekday,
to_char(next_day(mydate,'sunday'),'iw') as week_num
FROM ( SELECT TRUNC (SYSDATE, 'yy') - 1 + LEVEL AS mydate
FROM dual
CONNECT BY LEVEL <= (SELECT TRUNC (ADD_MONTHS (SYSDATE, 24), 'yy')
- TRUNC (SYSDATE, 'yy')
FROM DUAL))
this query gives date, weekday and week_num for 2 years 2013 and 2014,
when i run this query ,at the end of the 2013 it gives the result as,
26-DEC-13     thursday      52
27-DEC-13     friday      52
28-DEC-13     saturday      52
29-DEC-13     sunday      01
30-DEC-13     monday      01
31-DEC-13     tuesday      01
01-JAN-14     wednesday     01
02-JAN-14     thursday      01
for dates 29 ,30,31st it should give 53 .. how can i achieve that using this this query .. can any one help me out on this please...
thanks,
pradeep

I tried with the IW ...
it is giving week_id for the year.
select
mydate,
to_char(mydate,'day'),
case when mydate between trunc(mydate,'yyyy') and next_day(trunc(mydate,'yyyy'),'saturday')
then to_number(to_char(mydate,'yyyy')||to_char(trunc(mydate,'yyyy'),'iw'))
when mydate between next_day(trunc(mydate,'yyyy'),'saturday') and trunc(add_months(trunc(mydate,'yyyy'),12)-1,'d')-1
then to_number(to_char(mydate,'yyyy')||to_char(next_day(mydate,'sunday'),'iw'))
when mydate between trunc(add_months(trunc(mydate,'yyyy'),12)-1,'d') and add_months(trunc(mydate,'yyyy'),12)-1
then to_number(to_char(mydate,'yyyy')||to_char(trunc(add_months(trunc(mydate,'yyyy'),12)-1,'d')-1,'iw')+1) end as WEEK_ID
FROM ( SELECT TRUNC (SYSDATE, 'yy') - 1 + LEVEL AS mydate
FROM dual
CONNECT BY LEVEL <= (SELECT TRUNC (ADD_MONTHS (SYSDATE, 24), 'yy')
- TRUNC (SYSDATE, 'yy')
FROM DUAL
))

Similar Messages

  • I downloaded a Trial version of Adobe Acrobat XI.  Now the trial has runout and I've signed up for a subscription.  However, my software still needs a serial number.  How can I get a serial number for the installed software?

    I downloaded a Trial version of Adobe Acrobat XI.  Now the trial has runout and I've signed up for a subscription.  However, my software still needs a serial number.  How can I get a serial number for the installed software?

    There is no serial number and you don't need one. What you need for a subscription is to SIGN IN within Acrobat, so it knows the subscriptions you own.

  • How canI get my serial number for Elements 11?

    How canI get my serial number for Elements 11?  Does anyone know how to help me.  I did puchase it sometime ago but lost all computer data and had to replace computer.  Hope someone can help.
    Thanks
    Steve

    If you have no record of it at your end, the only place you might find it is at Adobe's end via logging into your Adobe account and seeing if it is listed there.  If you registered the software it should be.
    Beyond that your only hope might be to have Adobe support check your information to see if the software/serial number is available and if it can be given to you.  Try contacting them by chat or telephone.
    Here is a link to a page with options to help make contact:
    http://www.adobe.com/support/download-install/supportinfo/

  • How  to  crate a spool number for the abap program

    hi
    how  to  create a spool number for the abap program

    Hi,
    Check this thread
    how to create a spool requset for 'z program'.
    Regards,
    Satish

  • Where do I get my serial number for the free edu edition of dreamweaver

    where do I get my serial number for the free edu edition of dreamweaver?

    I've never heard of Adobe offering a "free educational version" of DW.
    They do offer a free 30 day trial or you can purchase a reduced price education subscription (of the full CC suite of programs) if you qualify.
    https://creative.adobe.com/plans
    Click on the Students and Teachers tab for pricing.

  • My dad has itunes on his PC. I don't have my own but I recently have an iPad mini and an iPod. I don't know how to get songs onto itunes on the PC, using a different account or at least private/ separate..

    My dad has itunes on his PC. I don't have my own but I recently have an iPad mini and an iPod. I don't know how to get songs onto itunes on the PC, using a different account or at least private/ separate..
    So how do I create a separate I tunes on a PC which already has itunes... Or if not can I plug my iPad to the PC and use itunes on my iPad, and drag mp3s from a computer.
    I'm not sure what the equivalent of a desktop is on the iPad.. And I don't actually know how to use the icloud either...
    Can anyone start me off, given it have a iPad and use of a PC - not mine with existing iplayer
    I do have spotify soundcloud so I could potentially use these.. If there is a route of getting either mp3's etc to end up on my iPad or iPod.
    Kind Regards

    iTunes 11
    If you  have iTunes 11 turn on the Sidebar.  Go to iTunes>View and click on Show Sidebar. You can also do a Crtl+S to show the sidebar. The sidebar is where Devices appears. and Control+B to show the Menu bar
    To import music into your iTunes library on the computer go to iTunes>Help>iTunes Help>Add items to iTunes and follow the instructions
    To sync to your iPod go to iTunes>Help>iTunes Help>Sync your iPod....>Sync You Device and follow the instructions.

  • How to get ISO week number?

    hi,
    I need to interact with a server that expects to be passed the ISO week number. The Calendar class doesn't seem to support this though (although the documentation claims that it is ISO 8601 compliant).
    For instance the web page here gives today (Jan 10th 2005) as being in Week 2
    http://personal.ecu.edu/mccartyr/isowdcal.html
    but this code snippet returns "Week 3"
    import java.util.*;
    public class WeekOfYear {
         public static void main(String[]arg) {
              Calendar c = Calendar.getInstance();
              System.out.println("Week "+c.get(Calendar.WEEK_OF_YEAR));
    }does anyone know a correct way of getting the ISO 8601 Week number without reimplenting a lot of delicate code?
    thanks,
    asjf
    ps. of course for now, and the rest of 2005, i'm going to hard code subtracting 1 as a gratuitous hack :o)

    hi,
    thanks - i did check the docs :)
    the problem is that Calendar's idea of what the first week in the year is differs from the ISO standard
    the problem is that the ISO standard defines the first week of the year as that containing the first Thursday (ie some days may become part of the previous year's weeks)
    and Calendar defines it as the docs state - so to change the value returned would mean you having to change the "FirstDayOfWeek" or the "MinimalDaysInFirstWeek" - which (without checking recently) I think the ISO standard also defines so you can't safely change these
    I might raise a RFE against Calendar about this in a week or two since it seems quite important?
    thanks,
    asjf

  • How to get an online number for Brazil

    I would like to get an online number for Brazil but I can't get it and I don't know why. I'm living in Sydney - Australia and I wanted to have an online number for my family in Brazil call me any time. 

    Hi,
    Unfortunately, Online Numbers are no longer available in Brazil.
    Please see also: https://support.skype.com/en/faq/FA269
    If my answer helped to fix your issue, mark it as a Solution to help others.
    Thank You!
    Please send private messages only upon request.

  • How to get an RSS feed into the phone using Nokia ...

    Is it possible to get an RSS feed into the phone using the Nokia PC Suite? RSS is mentioned in several places in the help files, but I can't find a place that describes how to set it up.

    just as they said in the help:
    "On the Bookmarks section, you can define bookmark and RSS feed synchronisation details. Bookmarks and RSS feeds can be synchronised between a Nokia mobile phone and a supported web browser. Note that bookmark and RSS feed synchronisation is not available for all phone models. "
    What's the law of the jungle?

  • How to add style(color) info for the color used in ALV tree nodes

    I have an object for CL_GUI_ALV_TREE and I have added nodes to the tree and has set color for the nodes using 'STYLE' parameter. Now if I have to add the style info to the style(color) then how do I do it using the object I have?
    Edited by: Sujay V Koparde on Feb 20, 2008 4:27 AM

    Yes Eshwar, its similar to what you have written but my problem was that the style has already been assigned in the code and now I want to assign the style info(tooltip text) to the style(colour). I have an object of class cl_gui_alv_tree as of now and I am not able to find out as to how do I proceed to assign style information

  • Getting the schema using Oracle SQL Developer 1.5.1

    I need to generate a report in CSV/XLS format using Oracle SQL Developer 1.5.1 to get the schema details
    in the below format.
    Table Name: XXXXXXXXX
    Table Space Name: XXXXXXXXXXXXXXX
    Structure :
    Field Name Data Type Size
    Xxxxxxxx xxxxxx xxxxx
    Xxxxxxxx xxxxxx xxxxx
    Xxxxxxxx xxxxxx xxxxx
    Xxxxxxxx xxxxxx xxxxx
    Field level constraint:
    Xxxxxxxxxxxxxxxxxx
    Table Level Constraint:
    Xxxxxxxxxxxxxxxxxx
    Indexes:
    Index Name Column Name(s) Table space name
    Xxxxxxxx xxxxxxxxx xxxxxxxxxxxx
    Xxxxxxxx xxxxxxxxx xxxxxxxxxxxx
    Xxxxxxxx xxxxxxxxx xxxxxxxxxxxx
    Sequence Number:
    Xxxxxxxxxxxxxxxx
    Triggers:
    Xxxxxxxxxxxxxxxxxx
    I am using a query to do that, but I cannot run more than one queries in the Create Report Dialog.
    I went to the Menu->View->Reports. In that, I chose User Defined Reports, created a new folder called Schema Detail and in that a report named Schema Detail. I right click on that report, choose Edit option, Create Report Dialog opens.
    In the Create Report Dialog, I chose the option Script for Value of Style.
    In the SQL column I enter a query "select * from table_names". But, if I enter another query after that, it does not run and reports an error "SQL Error: ORA-00933: SQL command not properly ended
    00933. 00000 - SQL command not properly ended" Cause:    Action: "
    I end the first query with a semi colon, but it does not work.
    The queries run fine in a SQL Worksheet. There, I can terminate the first query with a semi colon and enter the second query. Then, I run both of them together so that result-set of second query appears after the second.
    Am I doing something wrong? Can someone please advise on how to get the information I need?
    Thanks a lot.

    You can do it in SQL Worksheet because you are running a script. You could run the script in SQL*Plus, and even start it from a bat/cmd file.
    Or if you want this as a User Defined Report, you might make it a PL/SQL style report. Here, all output is done through DBMS_OUTPUT.PUT or DBMS_OUTPUT.PUT_LINE. You can output HTML tags or plain text. I have an example in my paper for ODTUG Kaleidoscope 2009.

  • How to auto assign a number to some data using PL/SQL

    Hi,
    Assume that i have a few lines of data...
    How do i auto assign number to the data without hardcoding it?
    In this instance, i want p_id to be auto-generate...
    create or replace procedure insert_file
    p_id number,
    p_file_type varchar2,
    p_file_name varchar2
    )as
    geor MDSYS.SDO_GEORASTER;
    begin
    insert into nyp_images values( p_id, p_file_type, sdo_geor.init('NYP_IMAGES_RDT') );
    select image into geor from nyp_images where image_id = p_id for update;
    sdo_geor.importFrom(geor, NULL, p_file_type, 'file', p_file_name);
    update nyp_images set image = geor Where image_id = p_id;
    end insert_file;
    Thanks and regards,
    Esther

    In this case you could slightly change your procedure to
    create or replace procedure insert_file (
      p_file_type     varchar2,
      p_file_name     varchar2,
      p_id        out number
      )as
      geor MDSYS.SDO_GEORASTER;
    begin
      insert into nyp_images values( your_seq.nextval, p_file_type, sdo_geor.init('NYP_IMAGES_RDT') )
         returning image_id into p_id;
      select image into geor from nyp_images where image_id = p_id for update;
      sdo_geor.importFrom(geor, NULL, p_file_type, 'file', p_file_name);
      update nyp_images set image = geor Where image_id = p_id;
    end insert_file;I highly reccommend you to take classes in this SQL and PL/SQL stuff or look for some external ressources that can guide you.

  • How to get/view document number for KP06 Planning upload

    Hi,
    I have uploaded excel for Cost center/cost element Planning in KP06 using exccel planning.Now i want the document number which for which i have posted in KP06-Plan values using excel upload.
    Kindly advice me how to get the document number for CO-OM(Cost center/Cost element planning) in KP06?
    Thanks
    Supriya

    Hello,
    Please execute report KSBL. It should be useful.
    Regards,
    Ravi

  • How to get a case number for license transfer?

    Dear all,
    I would like to transfer my Creative Suite CS6 Production Premium license to a new owner. After some internet searching I already found the instructions at
    http://helpx.adobe.com/de/x-productkb/policy-pricing/transfer-product-license.html#main_Li cense_transfer_process
    Now I got stuck at the point to obtain a case number. Every time I click on "Contact us", the only option I can choose is, to write to the Adobe community forums.
    Can anybody give me some detailed instructions how I can get a case number?
    Thanks in advance!

    For the link below click the Still Need Help? option in the blue area at the bottom and choose the chat option...
    http://helpx.adobe.com/x-productkb/global/service1.html ( http://adobe.ly/1aYjbSC )

  • How to get FI Doc number for a MM posted document number

    Hi Friends,
    I need info on how to retrieve FI Document number that gets generated for a MM posted document.
    MM Posted document is available in table RBKP-BELNR and FI document number created for this is in table BKPF-BELNR but for a given RBKP-BELNR how to find BKPF-BELNR. I need the relation.
    Any help on this is highly appreciated.
    Thanks,
    Simha

    hi,
    you can get accounting details from  material document in this way.
    DATA: BEGIN OF it_rbkp OCCURS 0,
          belnr LIKE rbkp-belnr,
          bldat LIKE rbkp-bldat,
          xblnr LIKE rbkp-xblnr,
          gjahr LIKE rbkp-gjahr,
          awkey LIKE bkpf-awkey,
          END OF it_rbkp.
    DATA: BEGIN OF it_bkpf_we OCCURS 0,
          belnr LIKE bkpf-belnr,
          awkey LIKE bkpf-awkey,
          END OF it_bkpf_we.
    DATA: BEGIN OF it_mkpf OCCURS 0,
          mblnr LIKE mkpf-mblnr,
          blart LIKE mkpf-blart,
          bldat LIKE mkpf-bldat,
          mjahr LIKE mkpf-mjahr,
          awkey LIKE bkpf-awkey,
          END OF it_mkpf.
      IF NOT it_ekbe[] IS INITIAL.
        SELECT mblnr
               blart
               bldat
               mjahr
               INTO TABLE it_mkpf
               FROM mkpf
               FOR ALL ENTRIES IN it_ekbe
               WHERE mblnr = it_ekbe-belnr
               AND   blart = c_we.
      ENDIF.
      LOOP AT it_mkpf.
        CONCATENATE it_mkpf-mblnr it_mkpf-mjahr INTO it_mkpf-awkey.
        MODIFY it_mkpf TRANSPORTING awkey.
      ENDLOOP.
    IF NOT it_rseg[] IS INITIAL.
        SELECT  belnr
                bldat
                xblnr
                gjahr
                INTO TABLE it_rbkp
                FROM rbkp
                FOR ALL ENTRIES IN it_rseg
                WHERE belnr = it_rseg-belnr.
                  ENDIF.
      LOOP AT it_rbkp.
        CONCATENATE it_rbkp-belnr it_rbkp-gjahr  INTO it_rbkp-awkey.
        MODIFY it_rbkp TRANSPORTING awkey.
      ENDLOOP.
      IF NOT it_mkpf[] IS INITIAL.
        SELECT belnr
               awkey
               INTO TABLE it_bkpf_we
               FROM bkpf
               FOR ALL ENTRIES IN it_mkpf
               WHERE awkey = it_mkpf-awkey.
      ENDIF.

Maybe you are looking for

  • DDIC ACTIVATION error while uploading the patch sapkb70009

    hi when uploading the patch of sap basis in ides , m facing an error of ddic activation and transport error 8 . pls suggest the reasons after this and help me into it . Thx & Regards Shilpa

  • Has anyone seen this problem? :(

    Hey Everyone, I picked the new white 30 gb ipod video up yesterday. I opened it set it up and transfered all my vids and music. Now my problem is the clickwheel. It scrolls about 200 (literally songs at a time and is not acurate with the amount of co

  • Sap.m.TableSelectDialog multiSelect behaviour in non multiSelect mode

    Hi All, I am using sap.m.TableSelectDialog in my application and i can see that Ok button is only provided when multiSelect property is set to true. Moreover, in non mulltiSelect mode as soon as an item selection(item click) is made, dialog closes. W

  • How to remove tlb search

    Tlb search male ware unfortianatily entered my mac. I can't find a method to remove it.

  • Need I tunes recovery

    I just bought a new computer how do I get my i tunes music on to it from my old computer