Dynamic Case expression

select  count(*)
  from  vwsr_all_merged_data s
 where  sr_tio_priority in ('Level 0','CEO','TER','Priority Assistance','Enquiry')
   and  sr_status = 'Open'
   and  SR_BUS_UNIT IN ('Business Support and Improvement','Finance and Administration','Cust Sat Simplification and Productivity','Project New and Customer Experience','Corp Strategy and Customer Experience','Other')

  COUNT(*)
----------
       126
the same should be able to dynamically with a Case expression, until I create the string as
SELECT 
     CASE 
        WHEN :name = 'BS&I' THEN ('('||''''||'Business Support and Improvement'||''''||','||''''||'Finance and Administration'||','||''''||'Cust Sat Simplification and Productivity'
                          ||''''||','||''''||'Project New and Customer Experience'||''''||','||''''||'Corp Strategy and Customer Experience'||''''||','||''''||'Other'||''''||')')
         ELSE null 
     END  
FROM dual
/

CASEWHEN:NAME='BS&I'THEN('('||''''||'BUSINESSSUPPORTANDIMPROVEMENT'||''''||','||
-----------------------------------------------------------------------------------------------------------
('Business Support and Improvement','Finance and Administration,'Cust Sat Simplification and Productivity','Project New and Customer Experience','Corp Strategy and Customer Experience','Other')

SQL> var name varchar2(10)
SQL> exec :name:='BS&I'

PL/SQL procedure successfully completed.
the same query string, I put here within the subquery to make higher up the chain, it doesn't work.
select  count(*)--sr_bus_unit,count(trunc(sr_open_date))
  from  vwsr_all_merged_data s
 where  sr_tio_priority in ('Level 0','CEO','TER','Priority Assistance','Enquiry')
   and  sr_status = 'Open'
   and  SR_BUS_UNIT IN 
              (   SELECT 
                    CASE 
                       WHEN :name = 'BS&I' THEN ('('||''''||'Business Support and Improvement'||''''||','||''''||'Finance and Administration'||','||''''||'Cust Sat Simplification and Productivity'
                          ||''''||','||''''||'Project New and Customer Experience'||''''||','||''''||'Corp Strategy and Customer Experience'||''''||','||''''||'Other'||''''||')')
                   ELSE null 
               END  
                        FROM dual
               ) 
/
COUNT(*)--SR_BUS_UNIT,COUNT(TRUNC(SR_OPEN_DATE))
------------------------------------------------
                                               0
Published by: user13653962 on 24/01/2013 17:09

Published by: user13653962 on 24/01/2013 17:10

Isn't it the same

SELECT COUNT (*)
FROM vwsr_all_merged_data s
WHERE     sr_tio_priority IN ( 'Level 0'
                                       , 'CEO'
                                       , 'TER'
                                       , 'Priority Assistance'
                                       , 'Enquiry'
                                       )
AND sr_status = 'Open'
AND SR_BUS_UNIT IN ( 'Business Support and Improvement'
                   , 'Finance and Administration'
                   , 'Cust Sat Simplification and Productivity'
                   , 'Project New and Customer Experience'
                   , 'Corp Strategy and Customer Experience'
                   , 'Other'
                       )
AND :NAME = 'BS&I'

Tags: Database

Similar Questions

  • Questions of the CASE expression.

    I have a very simple as table below:


    CREATE TABLE C_POST
    (
    POST_ID INTEGER NOT NULL,
    CLOB POST_REPLY_SET
    )

    I have this line:

    CASE post_reply_set IS NOT NULL THEN SELECT dbms_lob.substr (post_reply_set) ELSE 'NULL' END OF c_post;

    Error: ORA-00923: KEYWORD not found where expected


    then I have this line:

    SELECT (CASE post_reply_set IS NOT NULL THEN dbms_lob.substr (post_reply_set) ELSE 'NULL' END) OF c_post;

    Error: ORA-00907: lack the right parenthesis


    Finally, I have this line:

    SELECT CASE post_reply_set when IS NOT NULL THEN dbms_lob.substr (post_reply_set) ELSE 'NULL' END OF c_post;

    Error: ORA-00936: lack of expression

    Hello

    You need the WHEN keyword.  It will immediately after the CASE keyword, like this:

    SELECT THE CHECK BOX

    WHEN post_reply_set IS NOT NULL

    THEN dbms_lob.substr (post_reply_set)

    ELSE 'NULL '.

    END

    OF c_post;

    Lost or missing key words often lead to misleading error messages.

    If you are testing just if a variable is NULL, you can use NVL2 instead of the CASE:

    NVL2 SELECT (post_reply_set

    dbms_lob.substr (post_reply_set)

    , 'NULL '.

    ) AS col_alias

    OF c_post;

  • ACTION DYNAMIC - box Expression Javascript

    Hello
    I have 2 PCs in stock
    1 P2_REQUEST_TYPE_CODE
    a. SELECT LIST
    i. EQUIPMENT REV
    II. POSTERS
    III. the SHELL ROOM
    IV. VISIO CAD
    2 P2_RETURNED_FILE_TYPE_CODE
    a. BOX
    i. 2D POSTER
    DRAWING CAD II.
    III. PDF
    IV. VISIO

    I have a dynamic Action
    Event: change
    Selection type: item (s)
    Article (s): P2_RETURNED_FILE_TYPE_CODE, P2_REQUEST_TYPE_CODE
    Condition: Expression of JavsScript
    Value:
    $v ('P2_RETURNED_FILE_TYPE_CODE') == '2D POSTER |
    $v ('P2_REQUEST_TYPE_CODE') == 'POST '.

    When my user chooses ' P2_REQUEST_TYPE_CODE ("POST") "there shows the address columns, and it does.". When my user chooses "P2_RETURNED_FILE_TYPE_CODE ('2D POSTER")"it should display the address columns and it does. Everything works well except when in "P2_RETURNED_FILE_TYPE_CODE" all the checkboxes are checked the address columns don't get display, no idea?

    Request Express 4.1.1.00.23

    Thank you
    -JC

    Hi JC,.

    If you check multiply the boxes that the value will be a string with the value separated by a colon.
    You must use something like indexOf.

    $v('P2_RETURNED_FILE_TYPE_CODE')=='2D POSTER'||
    $v('P2_REQUEST_TYPE_CODE').indexOf('POSTER') != -1
    

    Kind regards
    Kees Vlek

    http://www.orcado.nl
    http://www.orcado.nl/blog/blogger/listings/69-kvlek

    If the answer to question please change to answered.

  • Problem with instruction box (order by case expression)

    Hi friends, I'm stuck in a strange problem. My query is like below

    OPEN FOR Cursor_prnt_req
    SELECT
    LTRIM (to_char (sprq.stit_numb)). ' - ' || substr (IH. (Name, 1, 35).
    sprq.event_key,
    sprq.planogram_key,
    TO_CHAR (sprq.request_date, 'HH12:MI:SS') requested_time,-asked on time
    TO_CHAR (plano2.desc2) desc2,-department
    TO_CHAR (plano2. Desc4) desc4,-in subcategory
    CASE)
    SELECT sp.status
    OF v1sprq01 sp
    WHERE sp.event_key = sprq.event_key
    AND sp.planogram_key = sprq.planogram_key
    AND to_char (sp.request_date, 'YYYYMMDD') = to_char (sprq.request_date, 'YYYYMMDD')
    AND ROWNUM = 1
    ORDER BY sp.status ASC
    )
    WHEN 'R '.
    THEN "ready."
    WHEN 'P '.
    THEN 'print '.
    WHEN THE A '
    And THEN "pattern".
    Status of END,
    CASE)
    SELECT count (DISTINCT planogram_key)
    OF v1sprq01
    WHERE stit_numb = sprq.stit_numb
    AND to_char (request_date, 'YYYYMMDD') = to_char (sprq.request_date, 'YYYYMMDD')
    )
    WHEN 1
    THEN "N".
    ELSE 'Y '.
    END dual_sited
    (
    SELECT MAX (request_date)
    OF v1sprq01
    WHERE event_key = sprq.event_key
    AND planogram_key = sprq.planogram_key
    ) latest_requested_time,.
    CASE sprq.status
    WHEN THE A '
    THEN "N".
    ELSE 'Y '.
    Printable END
    Of
    v1sprq01 sprq,
    dplapro1.ix_spc_planogram plano2,
    dplapro1.ix_spc_product ih - Ver 1.1
    WHERE sprq.event_key = plano2.dbkey5
    AND sprq.planogram_key = plano2.dbkey
    AND sprq.status IN ('R', 'P', the from ')
    AND sprq.stit_numb = ih.ID
    AND sprq.store_key = p_dbstorekey
    AND to_char (sprq.request_date, 'YYYYMMDD') = to_char (SYSDATE, 'YYYYMMDD')

    UNION

    SELECT
    LTRIM (to_char (sprq.stit_numb)). ' - ' || NVL (substr (IH. ((Name, 1, 35), cm).
    sprq.event_key,
    sprq.planogram_key,
    TO_CHAR (sprq.request_date, 'HH12:MI:SS') requested_time,-asked on time
    "& nbsp" desc2,-Department
    "& nbsp" desc4,-in subcategory
    "No direct Plan."
    N AS dual_sited,
    (
    SELECT MAX (request_date)
    OF v1sprq01
    WHERE event_key = sprq.event_key
    AND planogram_key = sprq.planogram_key
    ) AS latest_requested_time,
    "N" AS printable
    Of
    v1sprq01 sprq
    LEFT OUTER JOIN dplapro1.ix_spc_product ih - Ver 1.2
    WE (sprq.stit_numb = ih.ID)
    WHERE sprq.status = ' don't
    AND sprq.store_key = p_dbstorekey
    AND to_char (sprq.request_date, 'YYYYMMDD') = to_char (SYSDATE, 'YYYYMMDD')

    ORDER BY
    requested_time DESC,
    desc2 CSA,
    Desc4 CSA,
    latest_requested_time / / DESC
    ;

    When I compile my inner... I get an error ORA-00936: lack of expression (it points to the first case statement) but when I take the ORDER BY clause, it works very well.

    Can ne1 plz help (I tried google, but which did not help at all)

    Hey Suman,

    Order preference allows for the display of your need, or to access the data in a cursor in your SQL, a sort order is not necessary in cases and case statement does not support order them by in anyway.

    * 009 *.

  • Problem with CASE expressions

    Using Oracle 10 g R2, plsql in SQL Developer (or TOAD). I have a question 'simple' with the criteria 'complicated' in where clause.
    So, it's something like this:

    Select the fields in a table
    where stuff like Upper(:CategoryId) | '%'
    and sub_category_id like Upper(:SubCategory). '%'
    and order_date > =: StartDate
    and order_date < =: EndDate
    and division_id =: Division

    Up to this point, the query works fine. Here is where is the problem:
    If there is a value in the following parameter field, it works very well, but it is possible that the parameter is null, then I have to test for this first, and if it is empty (or even assigned a 'false' value) then it must restore all settings. The following parameter field is titled: SKU. The reason why I do this first place is to spend several values in a field of single parameter - comma which is great as long as there is some values...

    (This works with the above)
    and INSTR (Upper(:SKU), table.sku) > 0

    And I have a similar problem with another field in the table entitled: catalogue and as: SKU, it works very well if there is at least one input value.

    What I tried (who doesn't) is therefore:
    and as table.sku (BOX WHEN: SKU = '1' AND '%')
    Of OTHER INSTR (Upper(:SKU), table.sku) > 0
    END CASE)
    Same thing with the catalog:
    and as table.catalog (BOX WHEN: catalog = '1' AND '%')
    Of OTHER INSTR (Upper(:Catalog), table.catalog) > 0

    There must be a way to make this work. I will be grateful for any suggestions that would help in my situation.

    What is

    select s.sku,
            s.std_cost_ea,
            s.unit_price,
            o.QUANTITY,
            o.order_no,
            o.order_line
    from f21.ffct_offer_product_sku s
    inner join f21.fmkt_order_detail o
           on s.sku = o.sku
           and s.company_id = o.company_id
           and s.division_id = o.division_id
           and s.offer_id = o.offer_id
           and s.offer_year = o.offer_year
    where s.category_id like Upper(:CategoryId) || '%'
    and s.sub_category_id like Upper(:SubCategory) || '%'
    and instr(Upper(nvl(:SKU,s.sku)), s.sku) > 0
    and instr(Upper(nvl(:Offer,s.offer_id), s.offer_id) > 0
    and o.order_date >= :StartDate
    and o.order_date <= :EndDate
    and s.division_id = :Division
    and s.version_no = 0
    
  • How to disable Edit/Clone/case when transaction obtained ceratin in apex 4.2

    Hi all

    In our application, we have designed a screen using interactive report as shown below, in this report when they click on the checkbox and click the middle button we are what makes this transaction as being inactive and red color display. Requirement is now this line had to be disabled once the record was ceratin.

    1. below is screenshot of reference

    2 when they select the checkbox and click the ceratin that she will change in different as on the first row, now that the rank we now need to disable this, since this product has been produced de-activated.

    3 below used concept to achieve color, using dynamic action, we put in place this

    $('td[headers="Active_Flag"]').each(function() {  
      if ( $(this).text() === 'N' ) {  
        $(this).closest('tr').find('td').css({"background-color":"#EEA196"});
      } 
    });
    

    4. the logic of inactive code

    update t_test
                 set active_flag='N',
                      inactive_date=sysdate
                WHERE prod_map_id = to_number(apex_application.g_f01 (i));    
    

    Could you please let me know how to disable it.

    Kind regards

    Sruthitamiri

    Sruthi Tamiri wrote:

    I created an application in apex.oracle.com, please find necessary details, when you click on the checkbox and click Delete active, I call process of having ename like "N", then entire line should be disabled, because these have become now in use. Also, I gave the icon change, but total feature I didn't explain, that won't hurt i., e will redirect us to another page, where they changed the required fields, in this case I'm showing only a blank page. Once the entire line is turn off, it will not be able to click the icon change as well.

    Using CASE expressions in the report query to conditionally exclude links and lines disabled checkboxes and add a hidden (EMPNO) key column that can be referenced as a parameter in the conditional link:

    select
        case ename
          when 'N'
          then
            null
          else
            ''
        end "Edit"
      , ename
      , job
      , case ename
          when 'N'
          then
            null
          else
            apex_item.checkbox2(
                p_idx => 1
              , p_value => empno)
        end checkbox
      , empno
    from
       emp
    

    The column change Display Type value Standard report columnand the column Link Text link #Edit #.

  • Case returns the error on the value of type (error-17308)

    Hello

    I have the following problem with TestStand: I use a sequence setting tension on an instrument. The first step in this sequence is to choose the instrument to define. It worked absolutely fine so far. Next, I added a tool to select (called 2602A here). Now, it always works for all instruments, but not for this one. I also tested the Select / Case regardless, he does the same. The error message indicates that the type of my value does not match the type expexted. Yet, the type, as defined in the parameters.instrument is good (see attached photo). I tried with/without reference: same behavior. I tried with/without check Type: same behavior.

    Maybe I can specify that my instrument works very well, I tested the list of instructions under the indendently step case, without any difficulty.

    Any idea? Thank you in advance.

    TestStand:

    TS engine f1 2010 SP1 (4.5.1.144)

    4.5.1.134 sequence editor

    LabVIEW:

    Version 11.0.1f2

    Hello

    Looks like you do a comparison in the "select" for a string type as seen by the value, but the setting for the case is an assessment rather than a string of values to compare to and I can not make sense since he's looking for a game (chained a ternary operator) or returns - 1 - making in this case doesn't make no sense - do in the select to return whereby cases to go.

    The step case type is more than a 1:1 comparison, however, you have already demonstrated, the case itself may be an expression - you must ensure that the expression is returned exactly the correct type, so-1 is not valid, but would be "-1".

    Who is?

    So I tried to replicate this - if I send a pure (as in "2604" string) number when I'm looking for Parameters.Instrument == "2604 A '? '" 2604 A': Parameters.Instrument == "2604 B"? "" 2604B ':-1

    He then drops the default case.

    If I switch 2604 'B' which then activates OK.

    If I pass in "fred" which fails with the error since we were looking for - 1 because it is a number, it does not work.

    If I replace the case expression with:

    Parameters.Instrument == "2604 A '? '" 2604 A': Parameters.Instrument == "2604 B"? "" 2604-B ":"2604 A.

    While expression first only returns a string, so you'll get to the channel currently selected string comparison AND if I get A 2604 or 2604 B then I get a return value that corresponds to the string passed, or get a string that does not match, so the case is not the right one.

    So Don't pass return - 1 = return pass which is valid for this case, but do not match the incoming parameter.

    Thank you

    Sacha

  • Use Schedule Auto dynamic locking

    Hello

    The configuration is the following:

    My client wants to run 4 devices of individual test on the same PC. Each test set-up will take place at least 4 parallel trials at the same time by using the parallel model. For now, let's assume it's the same sequence is performed in all the plugs and fixtures. That might change, but the same conditions of blocking will be present on the different sequences.

    What I need to do, it is in the stages of locking and resources, both internally in a fixture and through all meetings. This is where my problem lies.

    If I use an ordinary lock, then I can do this, all I do is keep track of this fixture is actually running the steps. I can lock on a parameter, say Parameter.Fixture. Or lock simply ignoring what is actually being run around the world.

    But if I try to use Auto planning then this won't work. IM know not everything as automatic functionality of calendar but it seems that if I use the same parameter, it hangs on the real parameter rather than the value of the parameter contains the. What I tried was to use a chart such as locking, the expression typically would be Locals.Locks [Parameter.Fixture]. But it does very well with performance that threw me an error-17502. I can't use the words double locking as which can allow a simple mounting to acquire both.

    The customer wants to use auto MRP to reduce test times. In general, there is a unique instrument used on all fixtures that would be considered as a unique resource, while some test steps can be run at the same time within a luminaire (radio tests that intereferes through taken).

    Anyone has an idea on how to create a dynamic locking expression that can accept step or I missed something fundamental to automatic planning stage?

    / Nimgaard

    Note that you can get an effect similar to autoscheduling using locks with multiple threads (sequence calls have an option to run in a new thread). If each thread locks the resources he needs, he will be executed when the resource is available. Operations (threads) for a device can run in a different order than those of other share, based on the availability of resources, thus optimizing the flow. If you want to force operations can not overlap, for example for a specific device, you can have each thread locks the resources that it uses both the device he uses.

  • The difference between the expression and the function?

    Could someone please explain me the technical difference? For example, I know CAST is an expression and To_CHAR would be a function, but what differentiates the expressions of functions?

    Hello

    2776946 wrote:

    Could someone please explain me the technical difference? For example, I know CAST is an expression and To_CHAR would be a function, but what differentiates the expressions of functions?

    What is the difference between a bird and an OWL?  An OWL is a special type of a bird.  All owls birds, but not all birds are fun.

    Similarly, a function is a particular type of expression.  All functions are expressions, nut not all expressions are functions.

    In fact, the CAST is a function, but you're not wrong when you say "CAST is an expression.

    Maybe you wanted to say, not MOUNT.  CASE expressions are expressions, but not the functions.

    The technical difference between the functions and the other types of expressions has to do with how they are being implemented and is not all that important to users.  Is DECODE function?  It depends on which version you use.  The Oracle 6, it was a function; in Oracle 8, it wasn't; Since Oracle 9 it is again a function.  I don't know what has changed; Maybe the documentation.

  • Case statement

    Hi all

    I wrote the code that gives the same number below:

    Select

    Count (case when dm_recd_load_dt < add_months(sysdate,-12) then 1 else 0 end) as count_recd_ly,

    Count (case when dm_recd_load_dt < end (sysdate) then 1 else 0) as count_recd

    of cr_customer

    where nvl (primary_cust_flag, 'Y') = 'Y '.

    and the brand = 'The Commission'

    Hello

    Whenever you have a problem, please post a small example data (CREATE TABLE and only relevant columns, INSERT statements) of all the tables involved, so that people who want to help you can recreate the problem and test their ideas.

    Also post the exact results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.

    Post earlier in this forum.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

    2849981 wrote:

    Hi all

    I wrote the code that gives the same number below:

    Select

    Count (case when dm_recd_load_dt< add_months(sysdate,-12)="" then="" 1="" else="" 0="" end)="" as="">

    Count (case when dm_recd_load_dt< (sysdate)="" then="" 1="" else="" 0="" end)="" as="">

    of cr_customer

    where nvl (primary_cust_flag, 'Y') = 'Y '.

    and the brand = 'The Commission'

    Remember that ACCOUNT (exp) done: it returns the number of lines where the expression exp is not NULL.  Neither 1 nor 0 have the value NULL, then

    COUNT (CASE WHEN... THEN 0 OTHERWISE 1 END)

    is equivalent to

    COUNT (*)

    Perhaps you meant

    Count (case when dm_recd_load_dt)< add_months="" (sysdate,-12)="" then="" 1="" end) ="" as="">

    Count (case when dm_recd_load_dt)<            (sysdate)    ="" then="" 1="" end) ="" as="">

    She a CASE expression is not a clause ELSE, ELSE NULL by default.

    Moreover, these are CASES expressions.  A CASE statement is something else, found in PL/SQL, but not in SQL.

  • Expression box

    If the 3 following rules gathered and want to return to 'Y' of another "n" to a result column called BREACHED_IND I used an EXPRESSION BOX below and would like to know what is more, if the best alternative to do this. This is a large table. With the help of 11g

    • payment_ind = 'Y '.
    • activity_desc = "Cancel".
    • trunc (sysdate) between creation_date and (end_date + 5)

    cases where payment_ind = 'Y' and activity_desc = trunc (sysdate) between creation_date and (end_date + 5) and 'Cancellations' then 'Y' "n" of another late breached_ind

    The largest impact on the performance of SQL is the amount of i/o that must be done.

    Your case expression only consumes time CPU and only for the rows returned by the SQL cursor. The expression is not complex. So, it will consume minimum CPU.

    So for 1 million lines, average Boolean evaluation complete (no short-circuit evaluation), execution time will be increased about 6 seconds:

    SQL> set timing on
    SQL>
    SQL> declare
      2          flag            varchar2(1);
      3          payment_ind     varchar2(1)     default 'Y';
      4          activity_desc   varchar2(20)    default 'Cancellation';
      5          creation_date   date            default sysdate-1;
      6          due_date        date            default sysdate;
      7  begin
      8          for i in 1..1000000 loop
      9                  flag := (case
     10                                  when payment_ind = 'Y' and  activity_desc = 'Cancellation'
     11                                  and trunc(sysdate) between creation_date and (due_date + 5) then 'Y'
     12                          else
     13                                  'N'
     14                          end);
     15          end loop;
     16  end;
     17  /
    
    PL/SQL procedure successfully completed.
    
    Elapsed: 00:00:05.72
    SQL>
    

    So more time CPU for this calculation is minimal - and totally insignificant compared to the time required to find the line and read the line.

    If performance is a problem, you have to look either to reduce the i/o for the cursor SQL (better I/O paths, best execution plan), or perform i/o in parallel. And not to the expression box as the main contributor to the performance impact.

  • 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.

  • Case statement does not work

    Dear all,

    We have the database oracle 11g r2 on windows.

    I created under function: -.

    SQL > CREATE OR REPLACE FUNCTION FUNC_TEST (P_TEST VARCHAR2)

    2 RETURN VARCHAR2

    3 AS

    4 V_TEST VARCHAR2 (20);

    5

    6 BEGIN

    7

    8 V_TEST: = P_TEST;

    9

    10

    11 CASES

    12. WHEN V_TEST = UPPER ('%UU%') THEN V_TEST: = REPLACE (V_TEST, 'UU', 'U');

    13. WHEN V_TEST = UPPER ('%OO%') THEN V_TEST: = REPLACE (V_TEST, 'OO', 'O');

    14. WHAT V_TEST = UPPER ('%NN%') THEN V_TEST: = REPLACE(V_TEST,'NN','N');

    15 ELSE V_TEST: = "CHANCHAL";

    END 16 CASES;

    17

    18

    19 V_TEST RETURN;

    20 EXCEPTION SO THAT OTHERS THEN

    21 DBMS_OUTPUT. PUT_LINE (' THERE IS AN ERROR ');

    22 END;

    23.

    The function is created.

    SQL > SHOW ERR

    No errors.

    SQL > SELECT FUNC_TEST('toon') FROM DUAL;

    FUNC_TEST ('TOON')

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

    CHANCHAL

    above function should show 'YOUR' build 'Toon' but its display "CHANCHAL";

    I train hard get the result OK but could not get it.

    Any suggestions would be very helpful.

    Kind regards
    Chanchal wankhade.

    Hello

    Chanchal Wankhade wrote:

    Dear all,

    We have the database oracle 11g r2 on windows.

    I created under function: -.

    SQL > CREATE OR REPLACE FUNCTION FUNC_TEST (P_TEST VARCHAR2)

    2 RETURN VARCHAR2

    3 AS

    4 V_TEST VARCHAR2 (20);

    5

    6 BEGIN

    7

    8 V_TEST: = P_TEST;

    9

    10

    11 CASES

    12. WHEN V_TEST = UPPER ('%UU%') THEN V_TEST: = REPLACE (V_TEST, 'UU', 'U');

    13. WHEN V_TEST = UPPER ('%OO%') THEN V_TEST: = REPLACE (V_TEST, 'OO', 'O');

    14. WHAT V_TEST = UPPER ('%NN%') THEN V_TEST: = REPLACE(V_TEST,'NN','N');

    15 ELSE V_TEST: = "CHANCHAL";

    END 16 CASES;

    17

    18

    19 V_TEST RETURN;

    20 EXCEPTION SO THAT OTHERS THEN

    21 DBMS_OUTPUT. PUT_LINE (' THERE IS AN ERROR ');

    22 END;

    23.

    The function is created.

    SQL > SHOW ERR

    No errors.

    SQL > SELECT FUNC_TEST('toon') FROM DUAL;

    FUNC_TEST ('TOON')

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

    CHANCHAL

    above function should show 'YOUR' build 'Toon' but its display "CHANCHAL";

    I train hard get the result OK but could not get it.

    Any suggestions would be very helpful.

    Kind regards
    Chanchal wankhade.

    I think you meant:

    CASE

    WHEN SUPERIOR (V_TEST) LIKE "% UU" THEN V_TEST: = REPLACE (UPPER (V_TEST), 'UU', 'U');

    WHEN SUPERIOR (V_TEST) LIKE '% OO %' THEN V_TEST: = REPLACE (UPPER (V_TEST), 'OO', 'O');

    ...

    '%' is a wildcard character only on the right-hand side of the LIKE operator. '%' has no particular meaning when you use the = operator.

    You can also use a CASE expression, rather than a CASE statement to this:

    v_test: = UPPER (p_test);

    v_test: = BOX

    WHEN v_test LIKE "% UU" THEN REPLACE (v_test, 'UU', 'U')

    WHEN v_test LIKE "% UU" THEN REPLACE (v_test, 'OO', 'o')

    ...

    END;

    Whatever it is, if v_test contains different models (for example "HOOVER VACUUM"), only 1 of them will be changed.  Is that what you want?

    If this isn't the case, after a few examples of data (CREATE TABLE and INSERT statements) and the results desired from these sample data.  Explain how you get these results from these data.

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

  • ELSE IF or CASE!

    Hi, can someone tell me when these terms of use.

    Both serve the same purpose (to me), I'm not sure what to use when, or that one is better or faster.

    Hello

    There is no difference between a CASE statement and an IF statement.

    What is the best depends on what you mean by 'better' and is very subjective.  I think it is best in a given situation, and you might think that the other is better.  This does not mean that one of us would be a mistake.

    When a BOX Simple statement is appropriate, it is a little less coding than the corresponding FI, and I think it's more clear.

    Any CASE statement can easily be confused with a CASE Expression.  I do not use Search BOX instructions for this reason.

    CASE statements are not available in very old versions of Oracle (version 9 or earlier, I think).

    I don't think you will never notice any speed difference between a CASE statement and an all too well-written IF statement.

    The terms I used above are all defined in the PL/SQL manual.  See the PL/SQL control statements

  • using the case statement


    Hello

    How can I convert a code for the below sql case statement:

    If)

    (length of (tmp_co_orig_val) < = 0 OR tmp_co_orig_val < = 0 OR tmp_co_orig_val == 1 OR tmp_co_orig_val > = 9999999)

    OR

    ((tmp_co_orig_val == 999999 AND (length of (tmp_rcr_orgn_ltv_rt) < = 0 OR tmp_rcr_orgn_ltv_rt < tmp_rcr_orgn_ltv_rt > 1.3 GOLD 0.15)))

    Start

    tmp_collatvalue = «»

    tmp_msg_cd = 115

    end

    Is the case statement below that I wrote is correct. I don't have an environment now to test.  Please advice.

    BOX WHEN (CHAR_LENGTH (tmp_co_orig_val) < = 0 OR tmp_co_orig_val < 0 OR tmp_co_orig_val = 1 OR tmp_co_orig_val = > = 9999999)

    OR (tmp_co_orig_val = 999999 AND (CHAR_LENGTH (tmp_rcr_orgn_ltv_rt) < = 0 OR tmp_rcr_orgn_ltv_rt < tmp_rcr_orgn_ltv_rt > 1.3 GOLD 0.15))

    THEN tmp_collatvalue IS NULL AND tmp_msg_cd = 115

    END

    Hello

    937454 wrote:

    Thanks Frank. Really helps. But I have to write a sql statement

    But can you also specify, if I made a mistake in my code, or it's ok.

    There are no CASES reported in Oracle SQL.

    Oracle SQL has BOX expressions, but they only return a single value.  You cannot set 2 columns in the same expression BOX.

    Perhaps the best thing to do in pure SQL for you is to write a CASE expression, very similar to the CASE statement above, in a subquery and use the results of this in 2 separate expressions of BOX (very simple) in a Super application.

Maybe you are looking for