Decode or nvl2 or case functions

create a query that displays employees lastname and commission amounts.if an employee does not earn commission,put "no commission."label column comm
Sample Output
lastname comm
king no commission
abel .3
Note:The column commission is of number datatype

Hi,
This looks an awful lot like homework.
If you're really stuck, post your best attempt so far, and a description of what you think is wrong with it.
The assignment itself, "Decode or nvl2 or case" gives you three different ways to do this.
CASE is a lot more useful in general, so I suggest learning how to use it first.
NVL2 is a little more concise for this particular problem.
DECODE can do anything CASE can do, often with a lot more coding. Unless it's required for your schiool work, I don't suggest using DECODE.
You'll probably need to use the TO_CHAR function, to convert the commission to a string, so that whatever kind of expression you use (CASE or NVL2 or DECODE) it will always return the same datatype: VARCHAR2.
All built-in functions are documented in the SQL Language manual:
http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/index.htm
Actually, CASE and DECODE are not functions, but they're described in the same manual,.

Similar Messages

  • What is the difference betwee decode & case function

    Hi
    What is the difference betwee decode & case function
    1.decode can't used in pl/sql 1) case can be user
    2.in decode we can't use (>,<,>=) 2) we can use
    any other do u have....
    thanks in advance....

    DECODE works with expressions which are scalar values.
    CASE can work with predicates and subqueries in searchable form.
    There is one more Important difference between CASE and DECODE
    DECODE can be used Only inside SQL statement....
    But CASE can be used any where even as a parameter of a function/procedure
    Eg:-
    SQL> create or replace procedure pro_01(n number) is
      2  begin
      3  dbms_output.put_line(' The number  = '||n);
      4  End;
      5  /
    Procedure created.
    SQL> set serverout on
    SQL> var a varchar2(5);
    SQL> Begin
      2  :a := 'ONE';
      3  End;
      4  /
    PL/SQL procedure successfully completed.
    SQL> Begin
      2   pro_01(Decode(:a,'ONE',1,0));
      3  End;
      4  /
    pro_01(Decode(:a,'ONE',1,0));
    ERROR at line 2:
    ORA-06550: line 2, column 9:
    PLS-00204: function or pseudo-column 'DECODE' may be used inside a SQL
    statement only
    ORA-06550: line 2, column 2:
    PL/SQL: Statement ignored
    SQL> Begin
      2    pro_01(case :a when 'ONE' then 1 else 0 end);
      3  End;
      4  /
    The number  = 1
    PL/SQL procedure successfully completed.Message was edited by:
    Avi
    Message was edited by:
    Avi

  • Decode Statement Inside the Case statement

    Can we use Decode Statement inside a CASE Statement as show below --
    It is giving an error -- Is the a better way to write with out any error
    create or replace
    function test (a varchar2) RETURN VARCHAR2
    is
    m varchar2(20);
    begin
    m :=
    CASE
    WHEN a IN (
    '1009' -- (soon obsolete)
    ,'1010'
    ,'1019'
    ,'1051'
    ,'XGP'
    ,'XSC')
    THEN (SELECT DECODE(v_lef_cd,'NAM','71','GLB','99','01') into m FROM DUAL)
    -- ) THEN '01' -- UNITED STATES OF AMERICA
    WHEN a IN (
    '1069' -- South Africa
    ,'SAO' -- South Africa
    ,'SA' -- South Africa
    ) THEN '26' -- South Africa
    ELSE NULL
    END;
    return m;
    end;

    Hi,
    You can only use DECODE in SQL statements.
    Your SELECT DECODE (...) INTO statement would work anywhere a PL/SQL statement is allowed; but PL/SQL statements are not allowed within CASE expressions.
    Remember, the expression that comes after THEN in a CASE expression must be a single value.
    I would write a function like this using IF ... ELSIF statements. It's a little more typing than CASE, but a lot easier to code, test and maintain.
    If you want to use CASE, here's one way:
    ...     m := CASE
              WHEN  a  IN ('1069', 'SAO', 'SA')
                   THEN  '26'     -- South Africa
              WHEN  a  NOT IN ('1009', '1019', '1051', 'XGP', 'XSC')
              OR    a  IS NULL
                   THEN  NULL
              WHEN  v_lef_cd = 'NAM'
                   THEN  '71'
              WHEN  v_lef_cd = 'GLB'
                   THEN  '99'
                   ELSE  '01'     -- USA
              END;This assumes that you have a variable v_lef_cd defined.
    If you want, you can nest CASE expressions, like this:
    ...     m := CASE
              WHEN  a  IN ('1069', 'SAO', 'SA')
                   THEN  '26'     -- South Africa
              WHEN  a  IN ('1009', '1019', '1051', 'XGP', 'XSC')
                   THEN  CASE  v_lef_cd
                          WHEN  'NAM'
                             THEN  '71'
                          WHEN  'GLB'
                             THEN  '99'
                             ELSE  '01'     -- USA
                         END
              END;Always format your code, so you can see where the CASE expressions and each of the WHEN clauses begin and end.
    When posting formatted text on this site, type these 6 characters:
    (all small letters, inside curly brackets) before and after sections of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Decode or NVL2?

    What should be used when we have a choice of using decode or NVL2, how will it affect the performance?

    Hi,
    Nandini wrote:
    I don't want to know the difference between both. I want to know which should be prefered to use.Knowing their difference means knowing how to use them and in what particular situation you may use them.
    NVL2 is an extension of the functionality of NVL function which takes 3 arguments.
    The syntax for the NVL2 function is:
    NVL2( string1, value_if_NOT_null, value_if_null )
    string1 is the string to test for a null value.
    value_if_NOT_null is the value returned if string1 is not null.
    value_if_null is the value returned if string1 is null.
    The syntax for the DECODE function is:
    decode( expression , search , result [, search , result]... [, default] )
    expression is the value to compare.
    search is the value that is compared against expression.
    result is the value returned, if expression is equal to search.
    default is optional. If no matches are found, the decode will return default. If default is omitted, then the decode statement will return null (if no matches are found).
    Regards.

  • Case function

    hi
    can i write case function below like this
    select case (when information_type='SQ_IQAMA' then pei_information) end
    from per_people_extra_info
    information_type has two types like
    information_type pei_information1
    sq_iqama 2073636454
    sa_passport A 559873
    now i want show this in report with diff. columns
    can anyone help me.
    thnks

    user615979 wrote:
    hi
    can i write case function below like this
    select case (when information_type='SQ_IQAMA' then pei_information) end
    from per_people_extra_info
    information_type has two types like
    information_type pei_information1
    sq_iqama 2073636454
    sa_passport A 559873
    now i want show this in report with diff. columns
    can anyone help me.
    thnksYou can use DECODE. Which looks much simpler for this.
    select max(decode(informatino_type, 'sq_iqama',  pei_information1)) sq_iqama,
            max(decode(information_type, 'sa_passport', pei_information1)) sa_passport
      from <table_name>

  • Subtotal issue when subtotaling on a calc field built using CASE function

    Okay, I hpe I can explain this well. May be possible that this is something cannot handle in Discoverer. I am using Discoverer Plus to develop a new workbook - cross project expenditure inquiry. A requirement is to not allow a worksheet user to see labor cost (since possible to figure out someone's salary) amount unless they are allowed to view labor cost. I have a function that returns a Y/N value that tells me if they can view labor cost. That works out just fine. So what I am doing is taking my database cost column (which is defined as Number(22,5) in the Oracle table. I create a new calculated column, basically like this -
    CASE WHEN expenditure type <> LABOR THEN cost WHEN view labor cost = 'Y' THEN cost ELSE NULL END.
    That calculated column is working just fine. I am seeing my desired results in that column. Okay so far.
    Next, the users want subtotals by project organization and project. So I created a new total. When I did that, my subtotal row amount is blank.
    Okay, I have seen this happen with NULLS before. Like in the gl_je_lines tables, where the accounted_Dr and accounted_Cr may be null, and have to do a NVL function to convert the null to 0 and allow me to subtotal on the column in a Discoverer workbook.
    So I tried creating a second calculation -
    NVL(Cost,0)
    So I return the cost if not null, otherwise I return 0. Second calc column results look okay.
    Now I did a subtotal on the second calculation. Oops. Wrong result. Amount is shown as 0.
    For grins, I went back to my CASE statement on my first calculation and changed the ELSE condtion from NULL to 0. When I did that, the subtotal on that column changes from a blank (Null) value to a 0 value. Well, better, but still just like my second calculation subtotal.
    Obviously the users have the option to export to Excel and subtotal in Excel.
    Does anyone know of a way to get a good subtotal in this kind of situation, where I am attempting to subtotal on a calculated field that is built on a CASE function? Or am I out of luck when it comes to Discoverer?
    John Dickey

    Okay, I did find a workaround, though I do not understand why the workaround works, but why the way I first tried to get a subtotal did not work. What I did is that I had to go to Discoverer Administrator. I picked my folder and did an Insert/Item. I created my new item building the same CASE statement that I used in my worksheet to create a new calculation. I then closed Discoverer Plus and reopened Discoverer Plus. Opened my worksheet. Edited the worksheet and brought in my new (derived) item from my folder. Then I created my subtotals for this secured cost amount. Voila. I get a number now, and the subtotal amount appears to be correct (still testing/verifying, but looks okay so far). So I deleted my subtotals on my calculated column and then deleted the calculation, to get that stuff out of the report. Sure would be nice if there was documentation in the Discoverer manuals about this.
    John Dickey

  • How to use, Case function and Filter in Column Formula?

    Hello All,
    I am using case function and also would like to filter value to populate.
    Below is showing error :
    case
    when '@{Time}' = 'Year' then "Time"."Fiscal Year"
    when '@{Time}' = 'Quarter' then "Time"."Fiscal Quarter"
    when '@{Time}' = 'Month' then FILTER ("Time"."Fiscal Period" USING "Time"."Fiscal Period" NOT LIKE 'A%')
    else ifnull('@{Time}','Selection Failed') end
    Thanks, AK

    when '@{Time}' = 'Month' then FILTER ("Time"."Fiscal Period" USING "Time"."Fiscal Period" NOT LIKE 'A%')I dont think Filter this works here or any other data types except number.
    Try to use option Column's->Filter->Advanced->Convert this filter to SQL
    If helps mark

  • XSLT upper-case function()

    Does anybody know how to use a upper-case() function in XSLT? I have it in a XSL mapping of a routing service. I want it as below:
    <xsl:when test='(upper-case(/imp1:GENERIC4) = "YES") or (/imp1:AWARDTYPE = "227")'>
    <top:ccFlag>
    <xsl:text disable-output-escaping="no">Y</xsl:text>
    </top:ccFlag>
    I want it to be true no matter what case of YES is. It can be yes/Yes/YES/or anything.
    I also tried the following,
    <xsl:variable name="lower">abcdefghijklmnopqrstuvwxyz</xsl:variable>
    <xsl:variable name="upper">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>
    <xsl:choose>
    <xsl:when test='(translate(/imp1:GENERIC4,$lower,$upper) = "YES") or (/imp1:AWARDTYPE = "227")'>
    <top:ccFlag>
    <xsl:text disable-output-escaping="no">Y</xsl:text>
    </top:ccFlag>
    </xsl:when>
    <xsl:otherwise>
    <top:ccFlag>
    <xsl:text disable-output-escaping="no">N</xsl:text>
    </top:ccFlag>
    </xsl:otherwise>
    </xsl:choose>
    But doesnt work.
    Thanks for helping.

    this code works for me
        <ns1:testBPELProcessRequest>
          <ns1:input>
            <xsl:value-of select="xp20:upper-case(/ns1:testBPELProcessRequest/ns1:input)"/>
          </ns1:input>
        </ns1:testBPELProcessRequest>
      </xsl:template>maybe you need to use the namespace in front of the upper-case

  • CASE function problem in forms

    I am using the CASE function in View. Whenever i execute it using SQL plus it runs successfully. I have developed a form on this view and the form does not reflect the CASE function changes. Just an example i am using the CASE function to set the number format but it is not depicting on form.
    SELECT (CASE when TO_NUMBER(123123.12/1000000) < 1 THEN TO_CHAR(TO_NUMBER(123123.12/1000000),'0.99999')
    ELSE LTRIM(TO_CHAR(TO_NUMBER(123123.12/1000000),'999,999.999999')) END) as targetamount
    FROM DUAL

    This is not that diffucult.....I rememeber doing this in one of my forms....
    I would have three content areas
    ContentArea A (Portrait) linked to Subform A
    ContentArea B (Landscape) linked to Subform B
    ContentArea C (Portrait) linked to Subform C
    Now I will set the Min, Max and Initial values for each of those Subform using Binding tab.
    Then I will manage the page layout selection with each of those subforms using Object>>Pagination>>Place and link those to the Content area A B or C based on the layout they should go on. That should do the trick.
    If this is not helpful just forward me a copy at n_varma(AT)lycos.com....I will try my best.
    Good Luck,

  • CASE function is not working

    Hi,
    I want to use the CASE function in a sql statement used at form level but it's not working. I can't compile the form. I am using developer 6i at font end and Oracle 10g database at back end. Is it possible to use case function at form level sql statement. If so then please help me about it.
    Best Regards

    Forms has it's own PL/SQL engine, and in Forms 6i it's version 8 where no CASE was available. So if you want to use CASE you'll have to use a view or put your logic in a stored procedure.

  • Concatenation in CASE function

    Hi Gurus,
    In 9.0.4, the concatenation is not working in case statement. The append works fine in WHEN condition in CASE function and the result is the concatenated result. If I put the same condition without concatenation in ELSE statement, it gives datatype inconsistency error. Is there a way to do it?
    Thanks,
    Pooja

    Hi Pooja,
    Use the "To_Char()" function in ur concate function ,
    Because concat function only accept the string not an integer.
    Manikandan
    GKB Consulting Inc.,

  • Grand total of calculated column and case function in the same calcultd col

    Hi Gurus,
    In 9.0.4, the Grand total of the calculated column is not working as per the CASE function. It is taking the ELSE formula for all records. Is there a way to correct it.
    Thanks,
    Pooja

    Hi Pooja,
    In the totals ,which u mentioned try using cell sum function instead of sum function.
    Manikandan
    GKB Consulting Inc.,

  • CASE function in determining turn around time

    I am working with a customer that submits work for processing that must be accomplished on very short turnaround. There is a submission date in one table and in a joined table there is an accomplishment date. I can use the CASE calculation with a simple "like" condition to compare submission dates with accomplishment dates to answer "yes" or "no" if they match or do not match. How can I report a turnaround time of 2 days or 3 days, where the accomplishment date is 2 or 3 days after the submission date. Can I use a variation of the CASE calculation to derive a "yes" or "no" answer to these variations?

    I am working with a customer that submits work for
    processing that must be accomplished on very short
    turnaround. There is a submission date in one table
    and in a joined table there is an accomplishment
    date. I can use the CASE calculation with a simple
    "like" condition to compare submission dates with
    accomplishment dates to answer "yes" or "no" if they
    match or do not match. How can I report a turnaround
    time of 2 days or 3 days, where the accomplishment
    date is 2 or 3 days after the submission date. Can I
    use a variation of the CASE calculation to derive a
    "yes" or "no" answer to these variations?I think that I was able to find an answer to my question in an earlier forum response to someone who wanted to know how to determine difference in workdays. I really wanted the simplicity of the "yes" or "no" answer allowed by the CASE function. The forum response date I found was Nov 15, 2006

  • Syntax for CASE Function when multiple values equates to the same result?

    Tried using the 'IN' keyword with the CASE function but it does not work, does each case have to be stated separately? trying to save some lines..
    tried:
    case me607.rmc_code
    when in ('M','MS','MP') then 'H311'
    end as carrier_code
    Do i have to do:
    case me607.rmc_code
    when 'M' then 'H311'
    when 'MS' then 'H311'
    when 'MP' then 'H311'
    end as carrier_code,
    etc..
    Thanks for any help..

    One other thing forgot to ask, how do you do a second case selection as:
    case when me607.rmc_code
    in ('M','MP','MS') then 'H311'
    case when me607.rmc_code
    in ('1','2') then 'H252'
    end as carrier code
    wanting to keep the results in carrier_code..
    Thanks..
    Edited by: user12296489 on Dec 10, 2009 3:53 PM

  • 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

Maybe you are looking for

  • Input file size limition in File Reader Adapter

    Hi, We have a File Read Activity(using File Reader Adapter) which works on a Polling model. Whenever a input file is found in a designated directory it invokes our BPEL web service. During load testing we found out that if input file size exceeds 7 M

  • Scatter plot using time series function - Flash charting

    Apex 3 + XE + XP I am trying to build a time series scatter plot chart using flash chart component. Situation : On each scout date counts are taken within each crop. I want to order them by scout dates and display them in a time series chart. Each se

  • Did iweb kill my G5?

    Installed iLife06 on my G5 Built 1 website with iWeb Posted Site to my .mac account Went to save and quit--- Sipnning Beachball of death Went to Force Quit--- not possible. Manually shut off G5 Restarted G5-- no desktop. OS will not load. Restarted f

  • Syncing my iPhone 4s on both iMac and MacBook

    Help! When I got my iphone I only had our iMac, which was what I org. synced my phone to.  Since then I have purchased a MacBook and connected it to my MacBook (without any data loss, that I know of)  I do remember receiving messages of such the firs

  • Sending po printout by fax server

    hi! i have a very urgent problem, we implemented fax server for sending purchase order printout to the vendor. we used userexit vn00001 for recieving the vax number of the agent. we need to get also the country code and change it to te country code o