BETWEEN FUNCTION WITH IN A DECODE FUNTION IN A CURSOR

The following below is my query..I have to get the hours,min and seconds from a 'yyyy-mm-dd-24hh.mi.ss' value and check if the time is between 12 am to 6 am , then write it with one value else write an another value..I am trying to use 'BETWEEN' function in decode function but i am getting error.....Can we use BETWEEN function with in decode function or is there any other way
set serveroutput on
declare
cursor cur_dte is select lst_upd_date from EMPLOYESS ;
begin
for i in cur_dte loop
DECODE (substr(trim(i.lst_upd_date),12)) ,between '00.00.00.0000' and '06.00.00.00.0000' ,101,102);
dbms_output.put_line(i.lst_upd_date);
end loop;
end

First of all. If you are in PL/SQL then CASE is just a more colmplex expression then IF THEN ELSE. I usually prefere If then else, but for some rare cases.
The other issue is that you convert a datetime value into a string. This is wrong. it opens up all possible kinds of cenversion bugs. Stay with date or timestamp as long as possible.
The solution depends a little upon the datatype of your lst_upd_date column.
Here is a pl/sql solution assuming it is DATE.
The TRUNC function can be used to reduce a datetime to a day or to an hour.
declare
   cursor cur_dte is select lst_upd_date from employees ;
begin
   for i in cur_dte loop
     if trunc(i.lst_upd_date,'HH') between trunc(i.lst_upd_date) and trunc(i.lst_upd_date)+6/24 then
        dbms_output.put_line(to_char(i.lst_upd_date,'DD-MON-YYYY HH24:MI:SS'));
     end if;       
   end loop;
end;
/But a pure SQL solution is much better.
Here is how you implement it using CASE in SQL.
example using pure sql
select e.*,
        case when trunc(e.lst_upd_date,'HH')
               between trunc(e.lst_upd_date) and trunc(e.lst_upd_date)+6/24
        then 101
        else 102
        end as "early_morning_check"
from employees e;And if it is a timestamp column then you could use the EXTRACT function.
select e.*,
        case when to_number(extract(hour from e.lst_upd_date))
               between 0 and 6
        then 101
        else 102
        end as "early_morning_check"
from employees e;You might want to consider if date values like 06:45:00 should be included or not.

Similar Messages

  • BETWEEN function with dates

    Hi,
    how do i edit my where clause to display between the SYSDATE and exactly one month before that date?
    i know it's something like
    WHERE last_used >=SYSDATE
    AND last_used is <=??????
    i don't know what to put after that...
    anybody know?

    Daniel,
    This might get you what you want:
    WHERE last_used &gt;=SYSDATE
    AND last_used is &lt;= add_months(sysdate, -1)
    If this answers your question, please assign points and close the question..
    Thank you,
    Tony Miller
    Webster, TX

  • USING BETWEEN CLAUSE WITH 'IN'.

    Can I use between function with IN.
    Example.
    select a.* from emp a, dept b
    where a.deptid=b.deptid
    and a.deptid in (
    a.deptid between '122' and '199', '330'
    Actually its giving an errorr
    ORA-00907: missing right parenthesis*

    This is not a correct syntax. Use multiple between condition with "OR".
    Regards,
    Vidya.

  • Problem using DECODE() function with a Query of Queries

    I
    posted
    on my blog about an issue I was having trying to use the PL/SQL
    DECODE() function with a Coldfusion Query of Queries. This function
    works fine when you query a database for information. However, when
    you query another query, it seems that CF doesn't recognize it. I
    got errors stating that it found a left parenthesis where it
    expected a FROM key word. Here is a simplified version of what I am
    trying to do:
    quote:
    <!--- Simulated query; similar to what I was calling from
    my database --->
    <cfscript>
    qOriginal = queryNew("Name,Email,CountryCode",
    "VarChar,VarChar,VarChar");
    newRow = queryAddRow(qOriginal, 5);
    querySetCell(qOriginal, "Name", "Joe", 1);
    querySetCell(qOriginal, "Email", "[email protected]", 1);
    querySetCell(qOriginal, "CountryCode", "AMER", 1);
    querySetCell(qOriginal, "Name", "Sally", 2);
    querySetCell(qOriginal, "Email", "[email protected]", 2);
    querySetCell(qOriginal, "CountryCode", "AMER", 2);
    querySetCell(qOriginal, "Name", "Bob", 3);
    querySetCell(qOriginal, "Email", "[email protected]", 3);
    querySetCell(qOriginal, "CountryCode", "ASIA", 3);
    querySetCell(qOriginal, "Name", "Mary", 4);
    querySetCell(qOriginal, "Email", "[email protected]", 4);
    querySetCell(qOriginal, "CountryCode", "EURO", 4);
    querySetCell(qOriginal, "Name", "John", 5);
    querySetCell(qOriginal, "Email", "[email protected]", 5);
    querySetCell(qOriginal, "CountryCode", "EURO", 5);
    </cfscript>
    <cfquery name="qCountries" dbtype="query">
    SELECT DISTINCT(CountryCode) AS CountryCode,
    DECODE(states, "AMER", "North America &amp; Canada",
    "EURO", "Europe &amp; Africa", "ASIA", "Japan &amp;
    Asia","") CountryName
    FROM qOriginal
    ORDER BY CountryCode
    </cfquery>
    <cfdump var="#qCountries#">
    <!--- ========== END OF CODE ========== --->
    So running this returned the following error:
    Query Of Queries syntax error.
    Encountered "(. Incorrect Select Statement, Expecting a
    'FROM', but encountered '(' instead, A select statement should have
    a 'FROM' construct.
    Does anybody know why this doesn't work? Is it just not
    supported? Please note that I have also tried to use the CASE()
    function instead of DECODE() and that resulted in basically the
    same error. For now I an looping over my distinct query with a
    switch statement and manually loading a new query with the data how
    I want it. But it would be a lot cleaner and less code to have the
    DECODE() to work. Thx!

    DECODE() is an Oracle function, not generic SQL. Q-of-Q is a
    very limited subset of SQL and lacks many functions and clauses
    available in standard SQL, especially what you may be used to using
    in your particular RDBMS.
    See
    Query
    of Queries user guide
    Phil

  • Order split functionality with PP-PI

    Hello Forum,
    I am not sure whether we can use the order split functionality with process orders .  I had implemented it earlier for a client with discrete MFG production type but not aware whether we can do so in process industry (couldn't find the provision to do so in process order operation overview screen function menu path).
    Cheers
    Kaushik

    Hi Kaushik,
    Yes your right.
    Order split functionality is only applicable for Discrete manfg not for PI industry this is major difference between PI & DM.But you can achieve this at the time of process order confirmation.
    Example :-In the Goods Movement Overview of Process Order confirmation FG material is done Auto GR. This FG material Quantity needs to be splitted. Push button "Split" is provided in the bottom of the Goods Movement Overview screen of Process Order Confirmaton.
    Say FG quantity = 25 KG  which is to be confirmed. Client wants to split the FG quantity into 1 KG wise, for this he needs to split into 25 times.
    You can implement this by using below work order
    Please use the WORKORDER_GOODSMVT for splitting the GR in Confirmation
    This u can implement in PI.Also check Mr.Paulo reply that could be one possibility.
    check & revert.
    TnX

  • Trying to get Photoshop CS4 functional with Mavericks and an Epson 3880 printer. CS4 fails to send a file to the print queue. Have reinstalled the Epson 3880 driver for Mavericks. All looks good but no file is sent.

    rying to get Photoshop CS4 functional with Mavericks and an Epson 3880 printer. CS4 fails to send a file to the print queue. Have reinstalled the Epson 3880 driver for Mavericks. All looks good but no file is sent.
    Does anyone know how to fix this?

    What EXACT version of Photoshop CS4 are you running?  You should be on Photoshop CS4 v 11.0.2.
    Also run Apple's software update to see whether it offers you the latest Epson update:
    Printer Driver v9.33
    Epson Stylus Pro 3880, Drivers & Downloads - Technical Support - Epson America, Inc.
    MOST IMPORTANTLY:  have Photoshop re-create its own Preferences:
    To re-create the preferences files for Photoshop, start the application while holding down Ctrl+Alt+Shift (Windows) or Command+Option+Shift (Mac OS). Then, click Yes to the message, "Delete the Adobe Photoshop Settings file?"
    Note: If this process doesn't work for you while you're using a wireless (Bluetooth) keyboard, attach a wired keyboard and retry.
    Important: If you re-create the preferences by manually deleting the Adobe Photoshop CS6 Settings file, make sure that you only delete that file. If you delete the entire settings folder, you also delete any unsaved actions or presets.
    Reinstalling Photoshop does not remove the preferences file. Before reinstalling Photoshop, re-create your preferences.
    NEW Video! Julieanne Kost created a video that takes you through two ways of resetting your Photoshop preferences. The manual preference file removal method is between 0:00 - 5:05. The keyboard shortcut method is between 5:05 - 8:18. The video is located here:
    How to Reset Photoshop CS6’s Preferences File | The Complete Picture with Julieanne Kost | Adobe TV
    Mac OS
    Important: Apple made the user library folder hidden by default with the release of Mac OS X 10.7. If  you require access to files in the hidden library folder to perform Adobe-related troubleshooting, see How to access hidden user library files.

  • In Indesign CS6 I export an artboard to  TIFF with the sdk's funtion SnapshotUtilsEx- ExportImageToTIFF(iStream) and, the resulting file is one pixel too large in the X, leaving a transparent strip on one edge. Any idea if there is a bug in the sdk?

    In Indesign CS6 I export an artboard to  TIFF with the sdk's funtion SnapshotUtilsEx->ExportImageToTIFF(iStream) and, the resulting file is one pixel too large in the X, leaving a transparent strip on one edge. Any idea if there is a bug in the sdk?

    An easy example to prove this bug of Indesing CS6:  I create a psd with Photoshop CS6, with width 505 pixels, height 317 pixels and a resolution of 300 pixels per inch. This psd is placed on a page in InDesign CS6. Then I try to export it as a tiff with the functions:
    fSnapshotUtilsEx->Draw(flags,fullResolutionGraphics,greekBelowPtSize,enableAntiAliasing,tr ansparencyQuality,abortCheck,pVPAttrMap,bDrawNonPrintingObjects);
    and
    SnapshotUtilsEx-> ExportImageToTIFF (iStream)
    The resulting tiff has a width of 506 pixels (one pixel more in width). It will happen the same if we start with a width of 507 pixels, etc.
    This error does not occur with Indesign CS5, nor Indesing CC.

  • Difficulties replacing some BC functionality with XI (refer to example)

    <b>Difficulties replacing some BC functionality with XI (refer to example)</b>
    I am transferring all interface processing from BC to XI and am having difficulties replacing some of the current BC functionality.  Please refer to my example below
    <b>Current process</b>
    <b>SAP R/3</b>
    SAP R/3 executes an abap that extracts certain data.  This data is passed via a remote function which is configured to point to Business Connector
    <b>Business Connector</b>
    Business Connector takes control and the relevant package does some internal processing then calls the remote enabled function BAPI_ACC_BILLING_POST
    <b>SAP R/3</b>
    Control is returned to SAP R/3 to post the data and on completion control is returned to Business Connector
    <b>Business Connector</b>
    Business Connector again takes control where some more processing is done to generate an xml version of the data prior to returning control back to SAP R/3
    <b>SAP R/3</b>
    Control is returned to the abap immediately following the call to the remote function and processing completes
    The initial synchronous call from SAP R/3 to Business Connector remains open whilst Business Connector executes a subsequent synchronous call to SAP R/3.
    Finally the initial synchronous call in SAP R/3 completes
    <b>Proposed Process</b>
    I am transferring all interface processing from BC to XI and am having difficulties replacing some of the current BC functionality.  In this instance I can set up the initial synchronous call via an XI Integration Process (sync/async bridge).  This allows me to perform subsequent asynchronous calls prior to closing the synchronous bridge
    I have successfully performed synchronous calls to SAP R/3 from XI for different scenarios and have set up the XI design and config in the same manner
    When I try to perform the synchronous posting back to SAP R/3 from within the SA bridge I get the message ‘Message is incomplete. No Sender found’
    Unlike BC, it appears that XI does not allow me to perform the synchronous posting back to SAP R/3 from within the SA bridge.
    <b>Refer to</b> http://help.sap.com/saphelp_nw04/helpdata/en/83/d2a84028c9e469e10000000a1550b0/frameset.htm <b>for the SAP description</b> To enable the communication between a synchronously calling business system (synchronous outbound interface) and an asynchronously called business system (asynchronous inbound and outbound interface), you can define a sync/async bridge in an integration process. You can only define one sync/async bridge for each integration process.
    How can I replace the current BC functionality using XI?
    Regards,
    Mike

    Hi all,
    I cannot replicate the current BC functionality in XI
    So I will take this opportunity to simplify and improve the design for XI --> R/3
    Regards,
    Mike

  • Function with incomplete parameters

    I create a function with many parameters
    and I call this function through my application
    but when I call function I must declare all parameter inside this function like
    ddd("a","b",0,0,0,0,0,0,0)
    is there a method let function set a default value for parameter if code didn't declare it

    You can send just few first parameters and the rest will be passed as false. If you need to pass, say, first and 7th parameter, then you put 6 commas between values, as there is no named parameters in VFP and all parameters are passed by position.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • On the AGO Function need to Create TODATE function with Diff levels - MTD,Q

    Hi All,
    My Basic Requirement is to Create Time Series Function on AAA ie ( Month To Date , Quarter To Date and Year To Date )
    The Logic for the AAA = XXX / Previous 3 Months Revenue.
    we know that we can use the AGO Function to create Previous 3 months Revenue with Month is Level . But the issue is .... i cant use AGO function since i need to perform Year to Date, QTD and MTD upon 'AAA' this OBIEE doesn't permit to use nested time series functions upon varying levels .
    So How can i Resolve the issue ie creation of TODATE function on the AGO Function with Diff levels
    Thanks,
    Swapna S

    hi,
    for your requirement create three repository variables like
    for previous 3 months create repository variable like
    select to_char(sysdate,'yyyymm') -3 from dual;
    for month to date first calculate first day of the month
    select To_Char(Add_Months(Last_Day(Sysdate),-1) + 1,'MM/DD/YYYY') from dual;
    after put a filter in answers date between first date of the present month and current date
    create the same thing for year to date
    calculate first date in the year like following query
    select To_Char(Trunc(Sysdate,'YEAR'),'MM/DD/YYYY') from dual;
    after that apply filter date b/w first date in the year and current date
    i hope it works for your scenario
    Regards
    Naresh
    Edited by: Naresh Meda on Nov 10, 2008 2:08 AM
    Edited by: Naresh Meda on Nov 10, 2008 2:12 AM

  • Case function with group by

    Hi,
      I am having a scenario like :
    Column 1:  BrokerList(dimension1)
    Column 2 : Broker(dimension2)
    Column 3 : Metric value(measure)
    so i am having a case when (dimension 3) Custodian = 'ss' then sum(metirc) group by dimension1,dimension2 but the result value is not matching
    BrokerList
    Broker
    Metric
    a1
    a
    10
    b
    20
    c
    30
    a1 :total
    60
    a2
    a
    50
    c
    60
    d
    10
    a2:total
    120
    Grand total
    180
    Here the metric is based on other case condition.. so the total value is not matching.. Is there any other way to do a case function with group by funtions. Please advise.
    regards,
    Guru

    Use filter on metric by ss value and then go for group by from Criteria
    something like
    sum(FILTER(metric USING (Custodian = 'ss')) by dimension1,dimension2)
    mark if helps
    ~ http://cool-bi.com

  • Use of between functionality in oracle

    what is the use of between functionality in oracle
    my understanding is if i tell val between a and b then it should be >a and <b
    whether it will vary with different versions of oracle
    please clarify
    thanks in advance

    Have you considered looking in the documentation?
    "This comparison operator tests whether a value lies in a specified range. It means: greater than or equal to low value and less than or equal to high value."

  • Difference between Req with insufficient lead time and lead time const

    Hi ,
    1) Can anyone explain the difference between Requirement with insufficient lead time and Requirement lead time constraint exception messages. Both seems to be similar for me with the compressed time.Also at what situations these exceptions are generated.
    2) what is minimum lead time required ,actual lead time and its calculation.
    Thanks...

    Check out
    http://help.sap.com/saphelp_scm50/helpdata/en/99/ed3a981d0f11d5b3fc0050dadf0791/content.htm
    particularly the section "Which functions of the operations relevant to scheduling are supported?"
    It will give you a flavour of what can lead to difference in planning.

  • 2 functions with one cursor or.. 1 function with 2 cursors?

    Hi friends,
    I hope you help me to decide is this easy question:
    Actually I have 2 functions. Both are the same more or less: Both get data from USERS table. (In the users table there are several columns, I'm interested in "code" and "description")
    Function1 have a cursor which obtain data and orders by code,
    Function2 have a cursor which obtain data and orders by description.
    That's the only difference.
    I want to "optimize" the code so I was thinking on creating only a function.
    To do the same in one only function I thinked on passing a parameter i.e.: p_ordertype to know which would be the order ("C" for code or "D" for description)
    In that function I would have two cursors and I would ask for the parameter to execute one "FOR...." or the other.
    The question: Would it be really effective? I think that if I have 2 cursors in a function... I would cosume more memory than if I would only have one cursor.. (because I think data selected from cursors is parsed to memory when you invoke the function, before the 1st instruction after the BEGIN is executed, isn't it?)
    Would it be better 2 functions with one cursor each one or... one function with 2 cursors?
    Thanks in advance for your opinions.
    Jose.

    Hi again Todd,
    there's a problem with you solution :
    Imagine you have the following users:
    usercode - userdescr
    1 - ALAN
    2 - RICHARD
    3 - DANI
    12 - CHARLIE
    20 - BARRY
    If we pass a 'C' as p_ordertype (to obtain the list like above, ordered by usercode) , the result would be:
    1 - ALAN
    12 - CHARLIE
    2 - RICHARD
    20 - BARRY
    3 - DANI
    Do you understand what i'm trying to explain?... I hope that... I tried with
    ORDER BY DECODE(p_ordertype,'C',usercode,'D',TO_NUMBER(userdescr));
    but it doesn't works...
    More ideas?

  • Return multiple columns from an analytic function with a window

    Hello,
    Is it possible to obtain multiple columns from an analytic function with a window?
    I have a table with 4 columns, an id, a test id, a date, and the result of a test. I'm using an analytic function to obtain, for each row, the current test value, and the maximum test value in the next 2 days like so:
    select
    id,
    test_id,
    date,
    result,
    MAX ( result ) over ( partition BY id, test_id order by date RANGE BETWEEN CURRENT ROW AND INTERVAL '2' DAY FOLLOWING ) AS max_result_next_two_day
    from table
    This is working fine, but I would like to also obtain the date when the max result occurs. I can see that this would be possible using a self join, but I'd like to know if there is a better way? I cannot use the FIRST_VALUE aggregate function and order by result, because the window function needs to be ordered by the date.
    It would be a great help if you could provide any pointers/suggestions.
    Thanks,
    Dan
    http://danieljamesscott.org

    Assuming RESULT is a positive integer that has a maximum width of, say 10,
    and assuming date has no time-component:
    select
       id
      ,test_id
      ,date
      ,result
      ,to_number(substr(max_result_with_date,1,10)) as max_result_next_two_day
      ,to_date(substr(max_result_with_date,11),'YYYYMMDD') as date_where_max_result_occurs
    from (select
            id
           ,test_id
           ,date
           ,result
           ,MAX(lpad(to_char(result),10,'0')||to_char(date,'YYYYMMDD'))
               over (partition BY id, test_id
                     order by date
                     RANGE BETWEEN CURRENT ROW AND INTERVAL '2' DAY FOLLOWING )
            AS max_result_with_date
          from table)

Maybe you are looking for