EXTRACT function can be used directly in the CASE statement WHEN

I wrote the following SELECT statement. The function 'calc_time_diff' is a stored function that subtracts two timestamps and returns the result to the total number of seconds. My DBA does not 'calc_time_diff' as a stored function, then, I replaced the third line (in bold) in the SELECT statement with this:

COUNTY ( BOX WHEN (extract (DAY OF v_end_ts-v_st_ts) * 24 * 60 * 60) +)

(extract (HOUR FROM v_end_ts-v_st_ts) * 60 * 60) +.

(excerpt (v_end_ts-v_st_ts MINUTE) * 60) +.

extract ((DEUXIÈME à PARTIR de v_end_ts-v_st_ts) < 3600 THEN 1 END) less_than_1_hrs_count

But the CASE above does not work. It returns the same value as COUNT (*). If the total number of tickets is 32 output will be

total_tickets less_than_1_hrs_count

32                                 32

If I call the "calc_time_diff" then I get the correct result. What I'm doing wrong here?

**********************************************************************************************************************************************************************

SELECT

Count (*) total_tickets,

COUNTY ( CASE WHEN END of calc_time_diff (t.created_date, h.closed_date) < 3600 THEN 1) less_than_1_hrs_count

OF n01.cc_ticket_info t

JOIN IN-HOUSE

(SELECT ticket_id, MAX (created_date) closed_date

OF n01.cc_ticket_status_history

WHERE ticket_status = 'CLOSED' AND created_date > = 18 August 2013 ' AND created_date < (to_date('08/24/2013','MM/DD/YYYY') + interval '1' DAY)

GROUP BY ticket_id

) h

WE (t.ticket_id = h.ticket_id)

INNER JOIN n01.cc_ticket_notes n

WE (n.created_date = h.closed_date)

WHERE (t. ticket_status = 'NOTIFICATION' t.ticket_status 'CLOSED' = GOLD) AND t.created_date > = 18 August 2013 ' AND t.last_changed < to_date('08/24/2013','MM/DD/YYYY') + interval '1' DAY);

***********************************************************************************************************************************************************

create or replace

FUNCTION calc_time_diff)

p_st_ts N01.cc_ticket_info. Type of LAST_CHANGED %,

p_end_ts N01.cc_ticket_info. Type of LAST_CHANGED %)

RETURN NUMBER

AS

v_no_sec NUMBER;

v_st_ts N01.cc_ticket_info. Type of LAST_CHANGED %;

v_end_ts N01.cc_ticket_info. Type of LAST_CHANGED %;

BEGIN

v_st_ts: = p_st_ts;

v_end_ts: = p_end_ts;

SELECT (extract (DAY OF v_end_ts-v_st_ts) * 24 * 60 * 60) +.

(extract (HOUR FROM v_end_ts-v_st_ts) * 60 * 60) +.

(excerpt (v_end_ts-v_st_ts MINUTE) * 60) +.

excerpt ((SECOND from v_end_ts-v_st_ts)

IN v_no_sec

DOUBLE;

Return v_no_sec;

END calc_time_diff;

Hello

You don't need a function defined by the user or the EXTRACT to find the difference between two timestamps.

SELECT COUNT (*) AS total_tickets

, COUNTY ( BOX WHEN h.closed_date < t.created_date="" +="" interval="" '1'=""> )

                     THEN 1

END

) AS less_than_1_hrs_count

...

I hope that answers your question.
If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.
If you change the query at all, post your modified version.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).

See the FAQ forum: https://forums.oracle.com/message/9362002

Tags: Database

Similar Questions

  • Any idea which function Essbase or a combination of function can be used to get the level zero members of a list of members.

    Any idea which function Essbase or a combination of function can be used to get the level zero members of a list of members. I know that @RELATIVE or @DESCENDANTS cannot be used.

    If you want to fix on all level 0 members in a member set, then maybe @ILDESCENDANTS will work for you.  Something like: @ILDESCENDANTS (@LIST (members), 0)

  • How can I go directly to the desk top when switching on my XP dell

    How can I go directly to the desk top when switching on my XP dell

    Launch MSCONFIG, and then click the Startup tab.  Uncheck anything you want except your antivirus software.  To run MSCONFIG, click Start and type MSCONFIG in the run box, and then press ENTER.

    Hello

    I suspect that Hula_Baloo might have misinterpreted your question. My interpretation is completely different.

    Hula_Baloo instructions above will be stop all programs that run at startup, some of which may obscure your office.

    My interpretation is that you don't want to have to click your user icon and enter your password to connect to the computer. If my interpretation is correct, then this should help...

    http://support.Microsoft.com/kb/315231

    .. . If you are not comfortable editing the registry then choose the Fixit option.

    Tricky

  • Syntax of the case statement / WHEN

    The table I use a depreciation per fiscal year and the fiscal period.  I try to have the amount of depreciation to go to 2 different columns based on the fiscal year and the fiscal year.  I'm doing it with a nested case statement. I know that is not correct, because I get the message ORA-00905.  I'm relatively new to sql and it is contribtuing to my problem as well.  Here is the code I have and suggestions / corrections would be appreciated.  Thanks for the help...

    SELECT

    lao PDR. DEPTID as DEPTID,

    lao PDR. ASSET_ID as ASSET_NO,

    PA. Descr as DESCRIPTION,

    lao PDR. ACCOUNT_AD as AD_ACCT,

    PDL. DE_ACCT, to take into ACCOUNT

    lao PDR. ADEATH as AMT_DEPR,

    PDL. JOURNAL_ID as JRNL_ID,

    PDL. JOURNAL_DATE as JRNL_DT,

    lao PDR. FISCAL_YEAR as FY,

    lao PDR. ACCOUNTING_PERIOD AP,

    CASE

    WHEN RDP. FISCAL_YEAR = 2014 THEN

    WHEN RDP. PERIOD ACCOUNTANT = 11 THEN pdr. DEPR

    END AS CURR_MONTH,

    CASE

    WHEN RDP. FISCAL_YEAR <>2014

    WHEN RDP. ACCOUNTING PERIOD <>11 THEN pdr. DEPR

    END AS PRIOR_MONTH

    OF PS_DEPR_RPT pdr

    INNER JOIN PS_DIST_LN pdl

    THE pdl. BOOK = pdr. BOOK

    AND pdl. BUSINESS_UNIT = pdr. BUSINESS_UNIT

    AND pdl. FISCAL_YEAR = pdr. FISCAL_YEAR

    AND pdl. ACCOUNTING_PERIOD = pdr. ACCOUNTING_PERIOD

    AND pdl. ASSET_ID = pdr. ASSET_ID

    AND pdl. CF_SEQNO = pdr. CF_SEQNO

    INNER JOIN PS_ASSET PA

    WE pa. ASSET_ID = pdl. ASSET_ID

    AND pa. BUSINESS_UNIT = pdl. BUSINESS_UNIT

    WHERE

    lao PDR. BUSINESS_UNIT = "A0465.

    AND pdr. BOOK = 'RUN '.

    AND ((pdr. FISCAL_YEAR = 2014 AND pdr. ACCOUNTING_PERIOD = 11) OR (pdr. FISCAL_YEAR = 2014 AND pdr. ACCOUNTING_PERIOD = 10))

    Hello

    2713822 wrote:

    Thank you... I appreciate the information you provide when you answer these questions.  I always try to get the amount (from the same column) for 2 rows in different columns.  I tried the LAST_VALUE and LAG but it took a long time for the queries to run, I'm looking for another way to do the same.  I'm only using SQL to retrieve data.  I don't have the ability to create or insert.

    I looked the information above and the CASE statement to look like this:

    CASE

    WHEN RDP. FISCAL_YEAR = 2014

    AND pdr. ACCOUNTING_PERIOD = 11

    THEN the RDP. ADEATH AS CURR_MONTH

    ON THE OTHER

    lao PDR. ADEATH AS MONTHS PREVIOUS

    END

    But I'm now getting an "ORA-00905: lack of keyword" message.

    What I'm trying to do is to draw 2 lines 1 to 2014 / 11 and another for 2014 / 10.  The amount for the period 2014 / 11 should go in the current column and the amount for the period 2014 / 10 should go in the previous column.

    Before current assets management

    01 AB01 50.01 50.03

    ....

    If you want to give an alias for a column, then you can say "AS nome_alias" after that tell you what that is in this column.

    'AS nome_alias' applies to the entire column.  Cannot use 'alias_name' in the middle of an expression, for example, in the middle of a CASE expression, before the END keyword.

    If you want to have 2 separate output columns, curr_month and prior_month to your output, you must then 2 separate columns in your SELECT clause.  for example:

    SELECT pdr.branch

    pdr.asset

    CASE

    WHEN pdr.fiscal_year = 2014

    AND pdr.accounting_period = 11

    THEN pdr.depr

    END AS curr_month

    CASE

    WHEN...

    THEN...

    END AS prior_month

    PDR

    ;

    If post you some sample data (CREATE TABLE and INSERT statements), the results and explanations, I could show you how to complete the... sections.

    To find out what version of Oracle you have, use

    SELECT *.

    SINCE the release of v$.

    The output can be messy, like this:

    BANNER

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

    CON_ID

    ----------

    12 c Oracle database Release 12.1.0.1.0 - 64 bit Production

    0

    PL/SQL Release 12.1.0.1.0 - Production

    0

    CORE Production 12.1.0.1.0

    0

    AMT for 64-bit Windows: Version 12.1.0.1.0 - Production

    0

    NLSRTL Version 12.1.0.1.0 - Production

    0

    The important thing is the number 5 parts on the first line; 12.1.0.1.0 in the example above.

  • Helps the case statement when

    I am trying to compare the (date) "LATEST_EVENT_DT" to the "Big Date" ().

    So for 'The last event,' show "CANCELLED" If the "more great Date" is superior to the "LATEST_EVENT_DT" and if not, then display the value in the column 'LATEST_EVENT_DESC'. "

    If I take the part "Last event" everything works fine. But with it in I get the error 'keyword not found FROM or planned. " If anyone can help with this?

    Select

    LATEST_EVENT_DT,


    "OIT_Closed_Date", "OIR_Closed_Date", "OIN_Closed_Date."

    largest (LATEST_EVENT_DT, nvl ('OIT_Closed_Date', TO_DATE ('01011950', 'MMDDYYYY')), nvl ('OIR_Closed_Date', TO_DATE ('01011950', 'MMDDYYYY')), nvl ('OIN_Closed_Date', TO_DATE ('01011950', 'MMDDYYYY'))) "Big Date"

    "Last event" =.
    CASE
    WHEN LATEST_EVENT_DT < 'Date of larger' THEN 'CANCELLED '.
    OF OTHER LATEST_EVENT_DESC
    END

    of apex01.greatest_date_vw_SGD

    Thank you

    Steven

    Hi, Steven,

    What is

    "Last event" =.

    supposed to do?  Do you want the column returned by the expression BOX to appear as the "Last event" in the output?  If so, use an alias for column after the expression, as you did with "Big Date".

    You cannot define an alias for column (such as "largest Date") and then refer to this alias in the select even where it has been set.  Derive from the column in a subquery, you can reference it in a great query, like this:

    WITH got_greatest_date AS

    (

    Select LATEST_EVENT_DT

    , "OIT_Closed_Date".

    , "OIR_Closed_Date".

    , "OIN_Closed_Date".

    largest (LATEST_EVENT_DT

    nvl ('OIT_Closed_Date',

    , TO_DATE ('01011950', 'MMDDYYYY')

    )

    nvl ('OIR_Closed_Date',

    , TO_DATE ('01011950', 'MMDDYYYY')

    )

    nvl ('OIN_Closed_Date',

    , TO_DATE ('01011950', 'MMDDYYYY')

    )

    ) AS "Big Date".

    of apex01.greatest_date_vw_SGD

    )

    SELECT eff.*

    CASE

    WHEN LATEST_EVENT_DT< "greatest="">

    THEN "CANCELLED."

    OF OTHER LATEST_EVENT_DESC

    END as the "last event".

    OF got_greatest_date g

    ;

    You really like the names in double quotes?  Most people find them very confusing and a lot more trouble than they are worth.

  • an analytic function can be used to get the next largest value?

    I have a table with the values as follows:

    ID term val
    1 200720 aaa
    1 200720 bbb
    1 200720 ccc
    1 201220 ddd
    1 201220 eee

    2 200720 qqq
    2 200720 rrr
    2 200920 sss

    What I need, is to get the value of the next higher period (999999 if not exist) for each id line, like this:

    ID term val next_term
    1 200720 aaa 201220
    1 200720 bbb 201220
    1 200720 ccc 201220
    1 201220 ddd 999999
    1 eee 201220 999999

    2 200720 qqq 200920
    2 200720 rrr 200920
    2 200920 sss 999999

    I tried lead futures partitiion by id, but that just gives me the value in the next line. I watched windowing, but my eyes crossed. Any ideas? I need the next highest value not the value in the next line. The value of next_term must never be identical to the value term

    CREATE TABLE WJPTEST
    (
    ID VARCHAR2 (3 CHAR),
    VARCHAR2 (6 CHAR) TERM,
    VAL VARCHAR2 (3 CHAR)
    )
    ;

    Insert into WJPTEST
    (ID, VAL)
    Values
    ('1', '200720', 'aaa');
    Insert into WJPTEST
    (ID, VAL)
    Values
    ('1', '200720', 'bbb');
    Insert into WJPTEST
    (ID, VAL)
    Values
    ('1', '200720', 'ccc');
    Insert into WJPTEST
    (ID, VAL)
    Values
    ('1', ' 201220 ","ddd");
    Insert into WJPTEST
    (ID, VAL)
    Values
    ('1', ' 201220 ","eee");
    Insert into WJPTEST
    (ID, VAL)
    Values
    ('2', '200720', 'qqq');
    Insert into WJPTEST
    (ID, VAL)
    Values
    ('2', '200720', 'rrr');
    Insert into WJPTEST
    (ID, VAL)
    Values
    ('2', '200920', 'sss');
    COMMIT;

    Published by: wjpenfold on 12 June 2012 10:08

    wjpenfold wrote:
    what I want is the next largest value that may never be the same value as the current line. I'm working on getting the code example.

    What are the increments of TEMP? Assuming that the TERM cannot grow less than 1:

    NVL (Lead (term) OVER (PARTITION BY id ORDER BY term RANK BETWEEN 1 NEXT AND UNBOUNDED FOLLOWING), 999999)

    For example:

    select  sal,
            NVL(FIRST_VALUE(sal) OVER (ORDER BY sal RANGE BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING),999999) lead_sal
      from  emp
      order by sal
    /
    
           SAL   LEAD_SAL
    ---------- ----------
           800        950
           950       1100
          1100       1250
          1250       1300
          1250       1300
          1300       1500
          1500       1600
          1600       2450
    
           SAL   LEAD_SAL
    ---------- ----------
          2450       2850
          2850       2975
          2975       3000
          3000       5000
          3000       5000
          5000     999999
    
    14 rows selected.
    
    SQL>  
    

    SY.

  • Hi there, I been using MacBook Air and IPad2 for awhile. Recently, I lost my MacBook Air and am interested open ICloud to check my folder/old records. Can I get directions to the opportunity to see my files in I have the cloud.

    Hi there, I been using MacBook Air and IPad2 for awhile. Recently, I lost my MacBook Air and am interested open ICloud to check my folder/old records. Can I get directions to the opportunity to see my files in I have the cloud.

    I hope that you are not in a surprise but a MacBook Air not backup to iCloud. It can record data in iCloud drive (if you saved it specifically to this place) and can synchronize Photos, Contacts, etc to iCloud if you had set it to do. You can use any computer and connect to https://www.icloud.com/ to see what is stored. I hope this is good news and that it contains what you hope.

  • In my laptop, when I open the itunes window there is an option 'Internet Radio' to listen to the different type of music. This "Internet radio" function can be used on my iphone5? And if so, how can I make it work?

    In my laptop, when I open the itunes window there is an option 'Internet Radio' to listen to the different type of music. This "Internet Radio" function can be used on my iphone 5? And if so, how can I make it work?

    No more. It merged with the Apple's music.

  • If we then use the DML in function, this function can be used inside s

    If we use the DML statement in a function, then this function can be used within the select query or any DML query?
    select f from t2;
    

    I think that you wanted to interrogate t1.

    This works if the function is a stand-alone transaction:

    create or replace function f return number
    is
    PRAGMA AUTONOMOUS_TRANSACTION;
    begin
        update t1 set c=2;
        commit;
        return 1;
    end;
    / 
    
    select f from t1
    

    But as Billy, why would you do this way DML. And it's not stand-alone procedures should be used.

    A response to an interview question, but nothing wrong with it.

  • Where can I find directions to the user for the hp officejet J4680 printer?

    I am a novice and you want to learn how to use my Officejet J4680 printer all-in-one. Where can I find directions to the user for the HP Officejet J4680 printer? Thank you for responding.

    The user guide and other documentation for the Officejet j4680 can be downloaded here at HP.

  • What API can be used to update the table cs_estimate_details (repair)

    I need to update the columns 'pricing_context' and 'pricing_attribute1' in the cs_estimate_details table.

    Which API can be used to update the columns. Where can I update the table directly?

    Try to use this "CS_Charge_Details_PVT" which in turn call "CS_ESTIMATE_DETAILS_PKG".

  • Case function can be used as a parameter when calling a procedure, please advise...

    Case function can be used as a parameter when calling a procedure, please notify

    The daily procedure is called with the parameter 3 following one of the parameters using a function box between them as shown below.

    Daily_Ins (c1.p_mtrid, c1.p_UOM CASE WHEN "KWH" THEN 1 ELSIF 'KW' THEN 2 END, v_dateHold);

    In my opinion, using decode is illegal, so I think that I cannot say something like :

    Daily_Ins (c1.p_mtrid, ( decode c1.p_UOM, "KWH", 1 'KW', 2), v_dateHold);

    I think I just found something on the net

    SQL > DECLARE

    2 wages NUMBER: = 20000;

    3 employee_id NUMBER: 36325 =;

    4

    5 PROCEDURE give_bonus (emp_id in NUMBER, bonus_amt number) IS

    6 BEGIN

    7 DBMS_OUTPUT. Put_line (emp_id);

    8 DBMS_OUTPUT. Put_line (bonus_amt);

    9 END;

    10

    BEGIN 11

    12 give_bonus (employe_id,

    13 CASES

    14 salary when > = 10000 AND salary<=20000 then="">

    15. WHAT salary > 20000 AND salary<= 40000="" then="">

    16. WHAT > 40000 salary THEN 500

    17 0 OTHERWISE

    18 END);

    END 19;

    20.

    PL/SQL procedure successfully completed.

  • Hello. I can not use "direct selection tool".

    Hello. I can't use 'direct Selection tools. ' When I click the direct Selection tool, as the mouse on the image.errorg.jpg
    I use illustrator cs 6

    The layer is locked? Or object?

  • I have downloaded whatsapp in iTunes on my mac laptop but can't open it or use it. I have already on my iPhone 5. How can I use it on the laptop? Thank you

    I have downloaded whatsapp in iTunes on my mac laptop but can't open it or use it. I have already on my iPhone 5. How can I use it on the laptop? Thank you

    You download it from iTunes or the App Store? An iTunes download works with an IOS device, not a computer.

  • AD can be used to configure the registry?

    Active directory can be used to configure the registry? My understanding is that only local security settings can be configured using Group Policy in the ad. I've always written scripts of security in order to harden the registry. Please adise, thank you

    This issue is beyond the scope of this site (for consumers) and to be sure, you get the best (and fastest) reply, we have to ask either on Technet (for IT Pro) or MSDN (for developers)

    If you give us a link to the new thread we can point to some resources it

Maybe you are looking for