write an analytical function custom to get the current time

Hi all
I want to write a custom analytical function to get to the current week.
for example if it is today, January 13, 2012 then during week 2 the analytical function must return true.

I have an existing analytical function for the passage of time, written by someone else as below.

Decode (connect_by_root (LASTDATE) - trunc (sysdate),-1, 1, 0)

here last date it receives from the other query. This function returns me if the current date is passed or not.

So can someone please tell me how to write a custom function to get the current week.


Thank you
Prateek

Published by: 804658 on January 13, 2012 02:10

I have an existing analytical function for the passage of time, written by someone else as below.
Decode (connect_by_root (LASTDATE) - trunc (sysdate),-1, 1, 0)

Is not an analytic function.

I guess (because we don't know) that you need a function analytical, because you have a start date, but no end date and so an analysis as an ADVANCE or a DELAY can help you get the end_date.

If so, then maybe this shows you in the right direction.
I limited to 5 weeks to keep the short output.
I chose a start date of January 3, 2012.

SQL> WITH my_cal AS
  2  (select ROWNUM week_no
  3   ,      TO_DATE('03-JAN-2012','DD-MON-YYYY') + (ROWNUM-1)*7 start_date
  4   FROM   DUAL
  5   CONNECT BY  ROWNUM <= 52)
  6  SELECT *
  7  FROM   my_cal
  8  WHERE  week_no <= 5;

   WEEK_NO START_DAT
---------- ---------
         1 03-JAN-12
         2 10-JAN-12
         3 17-JAN-12
         4 24-JAN-12
         5 31-JAN-12

SQL>  WITH my_cal AS
  2   (select ROWNUM week_no
  3    ,      TO_DATE('03-JAN-2012','DD-MON-YYYY') + (ROWNUM-1)*7 start_date
  4    FROM   DUAL
  5    CONNECT BY  ROWNUM <= 52)
  6  SELECT week_no
  7  ,      start_date
  8  ,      LEAD(start_date) OVER (ORDER BY start_date) - 1 end_date
  9  FROM   my_cal
 10  WHERE week_no <= 5;

   WEEK_NO START_DAT END_DATE
---------- --------- ---------
         1 03-JAN-12 09-JAN-12
         2 10-JAN-12 16-JAN-12
         3 17-JAN-12 23-JAN-12
         4 24-JAN-12 30-JAN-12
         5 31-JAN-12

SQL> WITH my_cal AS
  2  (select ROWNUM week_no
  3   ,      TO_DATE('03-JAN-2012','DD-MON-YYYY') + (ROWNUM-1)*7 start_date
  4   FROM   DUAL
  5   CONNECT BY  ROWNUM <= 52)
  6  SELECT *
  7  FROM (
  8   SELECT week_no
  9   ,      start_date
 10   ,      LEAD(start_date) OVER (ORDER BY start_date) - 1 end_date
 11   FROM   my_cal)
 12  WHERE  TRUNC(SYSDATE) BETWEEN start_date AND end_date;

   WEEK_NO START_DAT END_DATE
---------- --------- ---------
         2 10-JAN-12 16-JAN-12

SQL> 

Tags: Database

Similar Questions

  • How to get the current time in GMT?

    I've seen countless examples online, but I can't understand why it does not work:

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String eventDateString;
    
    Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT")); // GMT will always be supported by getTimeZone
    eventDateString = dateFormat.format(calendar.getTime());
    System.out.println(eventDateString);
    
    Calendar calendarLocal = Calendar.getInstance();
    eventDateString = dateFormat.format(calendarLocal.getTime());
    System.out.println(eventDateString);
    

    This translates into this output:

    2009-03-10 19:58:06
    2009-03-10 19:58:06

    I expect the premiera either 4 hours in advance since the device that I use is estimated

    Did I miss something on the functioning of these methods?

    Thank you.

    I'm a big * beep *...

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); //e.g. 2008-06-03T12:15:03Z        Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));        c.setTime(new Date(System.currentTimeMillis())); //now        String formattedDate = dateFormat.format(c, new StringBuffer(), null).toString(); //formatted in UTC/GMT time        System.out.println(formattedDate);
    

    See this thread: http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=4714&query.id=610...

  • How to write a simple select query to get the data of the table as an XML.

    How to write a simple select query to get the data of the table as an XML. In the query, I'm just adding items below which i need be there in the XML document
    select '<test_tag>'||EMP_NAME||'</test_tag>','<date>'||sysdate||'</date>' 
    from temp_table where id_num BETWEEN 1 AND 10;
    I have need to add the root tag as well in the beginning and the end of < root > < / root > this xml file. Please advice if this is possible with the select query
    without using XMLGEN, XMLQUERY or any other packages built and function?

    I need to URL escapes with the UTF-8 code points that we have already achieved using the utl_http package. Please help how to do that without using the utl_http package.

    What is wrong with him?

    At present, the only way I can think of to avoid a call to UTL_HTTP. SET_BODY_CHARSET is to write your own little wrapper.
    In this way, you can specify the Boolean parameter or omit it if you choose to use named parameters:

    SQL> create or replace function my_url_escape (url in varchar2)
      2  return varchar2
      3  deterministic
      4  is
      5  begin
      6   return utl_url.escape(url, false, 'AL32UTF8');
      7  end;
      8  /
    
    Function created
    
    SQL> select my_url_escape('http://some.uri.com/param?lang=fr&text=contrôle') from dual;
    
    MY_URL_ESCAPE('HTTP://SOME.URI
    --------------------------------------------------------------------------------
    http://some.uri.com/param?lang=fr&text=contr%C3%B4le
     
    
  • By using the Microsoft XPS document Writer print driver, I no longer get the XPS files indexed.

    By using the Microsoft XPS document Writer print driver, I no longer get the XPS files indexed.
    Open the file "print" with the XPS Viewer XPS and while trying to search inside, I get this message:

    The XPS Viewer has finished searching for the document. The search item was not found.
    There is no searchable text in this document.

    I have 'print' some of my pages on the Bank, internet bank that every now and then I get a searchable history on disk, and opening a XPS I created in April (2011), the text is perfectly accessible, and I can select text with the mouse. However, the next printed file may, the entire document more like a picture. Nothing can be selected, and the message shown above, appears when you try to search for in the document.

    What could be the error? Can I change something to get back to normal "text printing" or is this a deliberate, change that has been installed from Windows update or even?

    Hello

    1. what changes have been made to your machine before the problem?

    I suggest that you follow the steps below and check if the problem persists.

    Step 1:

    Refer to this document to ensure that the settings are correct for Microsoft XPS Document Writer.

    See also: print in Microsoft XPS Document Writer

    Step 2:

    Perform the System Restore to the point that your XPS Document Writer worked very well.

  • Get the current language settings in the Custom Validation rule?

    Hello

    I read the book from Guide JDevelopers
    "In 26.9' custom application Validation rules.
    I ran the example to create custom Validation rules
    I ran my validation rule for English and Italian language using 'Message Bundles'
    I had EntityImplMsgBundle and EntityImplMsgBundle_it for the Italian language
    The Question is:
    Is it possible to get the current settings of the language used "get of in my custom validation class?
    I need to know if the current language is 'in' or 'it '.

    When I test my Applicaton of Module I can choose the configuration name: English EntityLocal and EntityLocalIT for the Italian language
    Can I access this validation custome bean?

    Kind regards.

    Hello

    Yes, you can access the local current in your validation rule by accessing the current session through the source of the entity object DBTransaction object. This is done by calling:

    ((EntityImpl)valCtx.getSource()).getDBTransaction().getSession().getLocale()
    

    HTH,
    Patrik

  • Get 15 minutes back in time from the current time (pls help write request)

    Hi all

    I need to write a query that gives time 15 minutes before the current time.
    I need to calculate visits to a Web site for the last 15 minutes.
    Kindly help to write this query.

    Best regards, Imran

    Select sysdate - 15 /(60*24)
    Double;

    Concerning
    Asif Kabir

  • Get the current value of a control of the ring

    I have a control of the ring that has the following values. See attacment. I need to get the current value of this one and use it as input for another function, but First I would like to get the current value and save ina text file. I tried this

    if (event == EVENT_LEFT_CLICK_UP) || (event == EVENT_LEFT_CLICK_DOWN)
    {
        int p;
        GetCtrlVal (panelHandle, PANEL_RINGSLIDE_1, &p);
        FILE *OutFile = fopen("C:\\Users\\Student\\Desktop\\ringtest.txt","w");
        fprintf(OutFile,p);
        fclose(OutFile);
    
    }
    

    I need to get the current value of the ring (& p) to write to the file ringtest.txt.

    Also, I need to use this value (& p) as another entry in the same program.

    IE value of & p must be used in

    b = c * 5; where c is the value of the current & p.

    Can any 1 help?

    You're right: EVENT_LEFT_CLICK_DOWN is not a valid event for the CVI. Valid events are listed in the userint.h file, and are the only events that can be caught in the trap in a point of order. On the other hand, you're assuption on EVENT_VAL_CHANGED is correct: you can trap forget the EVENT_CLICK_UP event.

    According to the second question, looking at the definition for fprintf you must pass a string format as the second parameter to the function, then the value to write to the file. In your case, the correct syntax is:

    fprintf (OutFile, "%d", p);

  • Creating a rule entry time custom to read the start time and the stop as entry time

    Hello world

    I hope this is the right forum to post this question.
    We are putting in place the time and work package, and we need to write a few rules of the time for this entry.

    The first of them is to have a rule that validates the start time and the stop time has entered the entry-level feature Self Service scorecard.
    So, I created a formula to achieve this objective. This formula eventually calls a PL/SQL function that checks for card points, the Start and Stop time values stored in the database.

    However, this is not what I intend to achieve. What I have to do is to get the value of time as she walked and apply the Validation

    This expansion in a scenario:

    1. the employee connects via the Self Service and access the timesheet feature to make a time entry
    2. on August 20, he entered 13:00 as the start time and stop time 20:00
    3. click on the button

    When he clicks on the button Save, (assume 20:00 is an incorrect time), an error message should be displayed to the user informing him of this

    ----------------
    Now, I have to spend the early hour 13:00 and the 20:00 in the formula stop time so that I can post it.
    This is where I run on issues that I don't know how to get these start and stop within the formula time

    Grateful if someone could help with this.
    It's quite urgent given the lead times for completion on that.

    Thks in advance folks
    Ravi

    l_timecard_info: = hxc_self_service_time_deposit.get_building_blocks;
    l_building_block_attr_info: = hxc_self_service_time_deposit.get_block_attributes;

    However, I do not understand this:
    If there are no parameters that are passed to these calls, then how the correct score card to be recognizable? I'm assuming that there is something like a Timecard_Id or setting Timecard_Ovn that allows to identify the correct sheet when reading this info.

    Pls advise me on this point, because I'm just not understand this bit.

    You do not need to pass all parameters. The overall picture of pl/sql is filled for the session before the rule of time entry. If you want to restrict, the formula will be an id_ressource of entry which is an employee self-service Person_Id. and compare this value against id_ressource in l_timecard_info.resource_id

    If this isn't an inconvenience for you, I want to understand how these function calls to keep the start time and stop time, and to access these variables, I would need to loop as a table through?

    The l_time_card_info of pl/sql table is filled exactly the same as how is stored in HXC_TIME_BUILDING_BLOCKS when save is saved / submitted. It's just that the pl/sql is here filled.

  • How can I get the current state "onto the Pixels?

    Hello community,

    Here's the function that creates a switch that handles "snap to Pixels":

    index.html:

    <div id="STP_input" onclick="switchOnOff(this)">
         ...
    </div>
    

    main.js:

    $("#STP_input").click(function () {
         var a = switchOnOff(this);
         if (a) {
              csInterface.evalScript('switchSTP(true)');
         } else {
              csInterface.evalScript('switchSTP(false)');
         }
    });
    

    HostScript.jsx:

    function switchSTP(checkBTN) {
        'use strict';
        
        var condition;
        if (checkBTN === true) {
            condition = true;
        } else {
            condition = false;
        }
    
        var idsetd = charIDToTypeID( "setd" );
        var desc26 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref6 = new ActionReference();
            var idPrpr = charIDToTypeID( "Prpr" );
            var idtoolsPreferences = stringIDToTypeID( "toolsPreferences" );
            ref6.putProperty( idPrpr, idtoolsPreferences );
            var idcapp = charIDToTypeID( "capp" );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idTrgt = charIDToTypeID( "Trgt" );
            ref6.putEnumerated( idcapp, idOrdn, idTrgt );
        desc26.putReference( idnull, ref6 );
        var idT = charIDToTypeID( "T   " );
            var desc27 = new ActionDescriptor();
            var idtransformsSnapToPixels = stringIDToTypeID( "transformsSnapToPixels" );
            desc27.putBoolean( idtransformsSnapToPixels, condition );
        var idtoolsPreferences = stringIDToTypeID( "toolsPreferences" );
        desc26.putObject( idT, idtoolsPreferences, desc27 );
        executeAction( idsetd, desc26, DialogModes.NO );
    
        return;
    }
    

    But when I hide the Panel and show once again, that the switch back to the default state, turn on my Panel, not "hook to Pixels" PS settings setting. Is it possible to get the current status 'Hang the pixels' setting? How?

    Best regards.

    See post 8 in this thread:

    Re: Need someone to update or create script: "snap to grid of pixels.

  • How to get the current value of db in backing bean

    Hello

    I use jdeveloper 11.1.2.3.0

    I would like to know how I could access the old value of an attribute in backing bean.
    I know I can get it in terms of EntityImpl with the getPostedAttribute function,
    but as I see that I'm not allowed to access this function in the ViewImpl.
    I get this error:
    Error (151,33): getPostedAttribute (int) has protected access to oracle.jbo.server.EntityImpl.

    Could you help her?
    What is the right way to get the current value on db in backing bean?

    Thank you very much!

    You can add a transitional attribute to the entity object to hold the old value of the desired attribute, then you can add this attribute to the view object.
    Check [url http://www.youtube.com/watch?v=iKVIiK0FBXI] retrieve the previous value of an attribute ADF BC

  • How to get the current folio of inside a folio with reading sdk

    Hello

    I am currently trying to get the current folio and its value of filter in the reading sdk (custom Navigation).

    Section 2.31 there is a "ReadingService" with "currentfolio" (Adobe DPS - reading SDK 2.31: adobeDPS-ReadingService: JsDoc reference).

    However, this Service has disappeared to 2.32. "Folio", itself is difficult.

    My question is: How can I get the current folio and its filter?

    I tried with adobeDPS.Folio / adobeDPS.Folio () filter and so on but nowhere.

    Best regards

    Andy

    Just use in any case, it's probably an error of generation of paper when we have updated the docs with the Windows platform tags. I'll ask the team to take a look.

    Neil

  • How to get the current selected action.

    Hello

    I would get the currently selected action.

    Please refer to the image below. Vignette (selection) is selected.

    Is there a script that I could use to get the which?

    Your help is very appreciated.

    Untitled-1.jpg

    getSelectedAction()
    function getSelectedAction(){
        var ref = new ActionReference();
        ref.putEnumerated( charIDToTypeID("Actn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
        try{
            var desc = executeActionGet(ref);
        }catch(e){ return; } // no action selected
        var selectedName = desc.getString(charIDToTypeID("Nm  "));
        var selectedIndex = desc.getInteger(charIDToTypeID("ItmI"));
        var parentName = desc.getString(charIDToTypeID("PrNm"));
        var parentIndex = desc.getInteger(charIDToTypeID("PrIn"));
        if(isActionSet( parentIndex, parentName )){
            var setName = parentName;
            var actionName = selectedName;
        }else{
            var setName = findAction(parentIndex, parentName );
            var actionName = parentName;
        }
        return [setName,actionName];
    };
    function isActionSet( parentIndex, parentName ){
       var res = false;
       try{
          var ref = new ActionReference();
          ref.putIndex( charIDToTypeID( "ASet" ), parentIndex );
          var setName = executeActionGet( ref ).getString(charIDToTypeID("Nm  "));
          if(setName == parentName) res = true;
       }catch(e){}
       return res;
    };
    function findAction(parentIndex, parentName ) {
      var i = 1;
      var found = false;
      while (!found) {
        var ref = new ActionReference();
        ref.putIndex(charIDToTypeID('ASet'), i);
        var desc;
        try {
          desc = executeActionGet(ref);
        } catch (e) {
          break;
        } finally {
        }
        if (desc.hasKey(charIDToTypeID('Nm  '))) { ;
          var setName = desc.getString(charIDToTypeID('Nm  '));
            var ref = new ActionReference();
            ref.putIndex(charIDToTypeID('Actn'), parentIndex);
            ref.putIndex(charIDToTypeID('ASet'), i);
            try{
            var adesc = executeActionGet(ref);
            var actName = adesc.getString(charIDToTypeID('Nm  '));
            if(actName==parentName) return setName;
            }catch(e){}
          }
        i++;
        }
    };
    
  • get the current event (name) of a field - possible / how to?

    Hello

    I wonder if it is possible to get the name of a field as event:

    (form.pag1.mytextfield::enter - JavaScript, client)

    var eventname = this.MagicJSfunction();
    

    It is of course possible to get the current name of the event with:

    (form.pag1.mytextfield::enter - JavaScript, client)

    var eventname = event.name; 

    It's a shame it's always = 'Focus' wherever I use it (form.pag1.mytextfield::ENTER - JavaScript, client) (form.pag1.mytextfield::EXIT - JavaScript, client)

    (form.pag1.mytextfield::enter - JavaScript, client)

    my_scripting_obj.my_set_design_function(this, eventname);

    Reason:

    I use to change the structure of a field in realtion to his event in my script object. By calling the function of my script object, I'd use some copy/paste.

    I have more than 120 field where this function must be called to enter and exit the event.

    Hello

    Does that help? http://assure.ly/h8ZLr5.

    In this case, I call the function entry and exit of the events of each field.

    Niall

  • How to read or get the current selected value of selectonechoice

    How to read or get the current selected value of selectonechoice, so that it can be used in the custom query.

    selectOneChoice11.getValue () m:System.NET.SocketAddress.ToString () returns the index of the list.

    from 0 - number of values in selectonechoice.

    I want to read the exact value of selected.

    Concerning

    Niaz M

    Why don't you try this?

    Re: Value of SelectOneChoice in valueChangeListener

    Both approaches will work...

    Julian

  • I reinstalled Firefox Desktop, I downloaded my favorites of Carbonite, how can I get the current Firefox to accept?

    See above

    I reinstalled Firefox Desktop, I downloaded my favorites of Carbonite, how can I get the current Firefox to accept?

    You do backup your bookmark as a .json file?

    Restoration of bookmark

Maybe you are looking for

  • Windows BSOD Crash 10 during the signature version 7.24

    Hey guys,. I'm having the issue of Skype crashing point reset the computer every time I open a session. I have a few delicious diagnostics for you. If you have an idea of what is the cause and how to fix it would be super awesome! Thank you B

  • [URGENT] Vibe Z2 phone Pro is not lit after selecting «encrypt phone»

    Dear staff of Lenovo, Me'm Sudhakar works for Intel, Bangalore. I use the phone for 4-5 months and had some problems of exchange messaging features. So I did a factory reset and tried to quantify phone to install the certificates. After you select En

  • Satellite L30-101 power up used

    I have a L30-101 which has unstable power supply problem. Sometimes it will start without effort. Once I press the power button, load cookies and wifi will be off and the power light will flash briefly, after that a few seconds, the load and wifi lig

  • Error on kernel stack inpage error and blue screen

    (Note: this post was created on behalf of another user.) Recently, my PC had blue screen errors.  Thinking it was probably a problem of aging HD, the HD has been replaced and a new install of Win XP Home Edition with Service Pack 2.  Blue screens per

  • Link broken for Docs

    http://supportforums.BlackBerry.com/T5/Java-development/BlackBerry-Java-SDK-guides/Ta-p/614746 The link of network in the list points to nothing for the PDF