Help with decode or case statement

I have the following insert statement
insert into t_outcome (
TRANSACTION_ID,
charge_DATE,
Charge_TIME,
STATUS_CODE)
values(cur_tem.transaction_id,
cur_tem.charge_date,
cur_tem.charge_time,
cur_tem.STATUS_code)
I require to incorporate the following rules into the population of charge_TIME
if cur_tem.STATUS_code is 7 and cur_temp.charge_time is not null then populate charge_TIME with cur_temp.charge_time
else if cur_tem.STATUS_code is 7 and cur_temp.charge_time is null then populate charge_TIME with -9
else if cur_tem.STATUS_code is not 7 then populate charge_TIME with -7
How do I add these rules into the insert statement ?
Thanks
Brendon

decode(cur_tem.STATUS_code, 7, nvl(cur_tem.charge_time, -9), -7)
I think that will work.
Lee
Message was edited by:
Lee Forkenbrock

Similar Messages

  • Help with error select case statement (ORA-00932: inconsistent datatypes)

    Hi,
    I'm struggling to get my sql query work on Oracle..
    I have a table MyTable with 5 columns ( Column1, Column2, Column3, Column4, Column5 ) all are of type NVARCHAR2.
    I need to check whether Column 3, Column 4 are empty or not in that order..and if they values then I wanna append it to Column2.
    For example
    If a row contains the following values,
    Column 2 = a.b
    Column 3 = 123
    Column 4 = xyz
    then column CA = a.b/123/xyz where column CA = temp column
    If either Column 3 or Column 4 is empty/null, then I don't need to append value for that column..
    For example
    Column 2 = a.b
    Column 3 = either NULL or ''
    Column 4 = xyz
    then CA = a.b/xyz where column CA = temp column
    similarly..
    Column 2 = a.b
    Column 3 = 123
    Column 4 = either NULL or ''
    then CA = a.b/123 where column CA = temp column
    Here is my query..
    select MyTable.Column1 as CA0,
    MyTable.Column2 as CA1,
    MyTable.Column3 as CA2,
    MyTable.Column4 as CA3,
    MyTable.Column5 as CA4,
    MyTable.Column2 + CASE WHEN MyTable.Column3 > '' THEN '/' + MyTable.Column3 ELSE '' END + CASE WHEN MyTable.Column4 > '' THEN '/' + MyTable.Column4 ELSE '' END CA
    from MyTable;
    This query works just fine against SQL Server db, but gainst Oracle I'm getting
    ORA-00932: inconsistent datatypes: expected NUMBER got CHAR
    00932. 00000 - "inconsistent datatypes: expected %s got %s"
    Could you please let me know what I'm doing wrong. I need to get this query working on both SQL Server and Oracle..
    Please let me know your suggestions and thoughts..
    Cheers,

    I need to check whether Column 3, Column 4 are empty or not in that order..and if they values then I wanna append it to Column2. In Oracle, you can do it this way - no need to do all kinds of difficult things:
    select col2||col3||col4
      from tbl

  • Help with Decode/Case

    Hello All,
    Can I use decode/case function within a decode function?
    {code}
    SELECT TO_CHAR (
              EDMS_STRAGG_WC (
                 DISTINCT DECODE (
                             eqs.attrib_code,
                             'PRODUCT_AUTHORIZATION',    'Authorization: '
                                                      || CASE eqs.qual_value
                                                            WHEN 'LIST'
                                                            THEN
                                                               (SELECT lookup_desc
                                                                  FROM edmsadm.edms_lookup
                                                                 WHERE     lookup_type =
                                                                              'PARTNER_AUTHORIZATION'
                                                                       AND lookup_code =
                                                                              eqls.list_value)
                                                            ELSE
                                                               (SELECT lookup_desc
                                                                  FROM edmsadm.edms_lookup
                                                                 WHERE     lookup_type =
                                                                              'PARTNER_AUTHORIZATION'
                                                                       AND lookup_code =
                                                                              eqs.qual_value)
                                                         END,
                             'PRODUCT_CERTIFICATION',    'Certification: '
                                                      || CASE eqs.qual_value
                                                            WHEN 'LIST'
                                                            THEN
                                                               eqls.list_value
                                                            ELSE
                                                               eqs.qual_value
                                                         END,
                             'PRODUCT_SPECIALIZATION',    'Specialization: '
                                                       || (SELECT lookup_desc
                                                             FROM edmsadm.edms_lookup
                                                            WHERE     lookup_type =
                                                                         'PARTNER_SPECIALIZATION'
                                                                  AND lookup_code =
                                                                         CASE eqs.qual_value
                                                                            WHEN 'LIST'
                                                                            THEN
                                                                               eqls.list_value
                                                                            ELSE
                                                                               eqs.qual_value
                                                                         END))))
              program_value
      FROM edms_qual_stg eqs, edms_qual_list_stg eqls
    WHERE     1 = 1
           AND eqs.qual_id = eqls.qual_id(+)
           AND eqs.req_id = 192647
           AND eqs.disc_line_id = 598631
           AND eqs.attrib_code IN
                  ('PRODUCT_CERTIFICATION',
                   'PRODUCT_AUTHORIZATION',
                   'PRODUCT_SPECIALIZATION');
    {code}
    Edms_qual_stg:
    AND_OR_CONDITION
    ATTRIBUTE_SOURCE
    ATTRIB_CODE
    CREATED_BY
    CREATED_DT
    DISC_LINE_ID
    END_DT
    EXCLUDE_INCLUDE
    GROUP_AND_OR_CONDITION
    GROUP_CODE
    MAX_VALUE
    MIN_VALUE
    MODIFIED_BY
    MODIFIED_DT
    QUAL_APPL_PRECEDENCE
    QUAL_ID
    QUAL_OPERATOR
    QUAL_TYPE
    QUAL_VALUE
    REQ_ID
    START_DT
    Edms_qual_list_stg:
    ATTRIBUTE_SOURCE
    ATTRIB_CODE
    CREATED_BY
    CREATED_DT
    END_DT
    INCLUDE_AFFILIATES
    INCLUDE_EXCLUDE
    LIST_VALUE
    MODIFIED_BY
    MODIFIED_DT
    PRIMARY_PARTY
    QUAL_ID
    QUAL_LIST_ID
    REFERENCE_ID
    START_DT
    Edms_lookup:
    CREATED_BY
    CREATED_DT
    DISPLAY_SEQ
    EDMS_LOOKUP_ID
    END_DATE
    LOOKUP_CODE
    LOOKUP_DESC
    LOOKUP_REFERENCE
    LOOKUP_TYPE
    MODIFIED_BY
    MODIFIED_DT
    START_DATE
    SELECT eqs.qual_id, eqs.disc_line_id, eqs.req_id, eqs.attrib_code, eqs.qual_value, eqls.list_value
      FROM edms_qual_stg eqs, edms_qual_list_stg eqls
    WHERE     1 = 1
           AND eqs.qual_id = eqls.qual_id(+)
           AND disc_line_id = 598631
           AND req_id = 192647
           AND eqs.attrib_code IN
                  ('PRODUCT_CERTIFICATION',
                   'PRODUCT_AUTHORIZATION',
                   'PRODUCT_SPECIALIZATION');
    7509575    598631    192647    PRODUCT_CERTIFICATION    LIST    GOLD
    7509575    598631    192647    PRODUCT_CERTIFICATION    LIST    SILVER
    7509576    598631    192647    PRODUCT_AUTHORIZATION    LIST    ATP - JOULEX PROVIDER ESCO
    7509576    598631    192647    PRODUCT_AUTHORIZATION    LIST    ATP - JOULEX PROVIDER IDENTIFY
    7509577    598631    192647    PRODUCT_SPECIALIZATION    LIST    ADVANCED SECURITY
    7509577    598631    192647    PRODUCT_SPECIALIZATION    LIST    EXPRESS FOUNDATION
    Required Output:
    Certification: GOLD, SILVER, Authorization: ATP - JOULEX PROVIDER ESCO, ATP - JOULEX PROVIDER IDENTIFY,  SPECIALIZATION: ADVANCED SECURITY, EXPRESS FOUNDATION.
    Thx
    Shank.

    Hi,
    Sure; a DECODE or CASE expression that returns a NUMBER can be used any place a NUMBER is expected, including within another DECODE or CASE expression.  A DECODE or CASE expression that returns a DATE can be used any place a DATE is expected, including within another DECODE or CASE expression.  A DECODE or CASE expression that returns a VARCHAR2 can be used almost any place a VARCHAR2 is expected.  (There a  couple of special situations where a string literal is absolutely required.)
    There are not many situations where you really need to do that, though.  It's usually simpler and more efficient to use a single CASE expression; nesting is rarely needed.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Simplify the problem as much as possible, so that it contains only enough to show the part you don't already know how to do.
    If you really need a user-defined function to show the problem, then include a CREATE FUNCTION statement, and explain what the function does.  Again, simplify: if the function isn't what you don't understand, post a problem that doesn't use the function.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Decode and case statement in the update..

    Its is more to it, but I want to check with you guys, the experts on this, this look busy to me, it should be a more simplify way of doing it, do you think will work
    The government decide to change the ethnic codes, and we have to come with certain rules to in our report, anyway, do you think this will work? again It is more to it I declare my variables, this is just one part of the precedure.
    BEGIN
          UTL_FILE.fclose_all;
          v_file_handle := UTL_FILE.fopen (v_out_path, v_out_file, 'a');
          UTL_FILE.put_line (v_file_handle,
                             CHR (10) || TO_CHAR (SYSDATE, 'DD-MON-YYYY HH:MI:SS')
          UTL_FILE.put_line (v_file_handle, 'Entering  spbpers_update');
          SELECT upd_spbpers_upd_cur IS
              spriden_pidm,
              szscapp_birth_state,
              szscapp_birth_city,
              DECODE(szscapp_hisp_or_latino_ind,Y,'2',N,'1'),
              DECODE(szscapp_hisp_or_latino_options,XCM,'2',CUB,'2',MEX,'2',PRI,'2',XSM,'2',ESP,'2',XOH,'2'),  
              DECODE(szscapp_amer_indn_alaska_opt,XAN,'1','1',XCW,'1',XCH,'1',XCK,'1',XNV,'1',XSX,'1'),         
              DECODE(szscapp_amer_indn_alaska_other,XON,'1') (,IND,'1',JPN,'1',KOR,'1',PAK,'1',PHL,'1',VNM,'1',XEA,'1',XIS,'1',XSA,'1'),  
              DECODE(szscapp_asian_options,IND,'1',JPN,'1',KOR,'1',PAK,'1',PHL,'1',VNM,'1',XEA,'1',XIS,'1',XSA,'1'),   ,          
              DECODE(szscapp_other_east_asia,(IND,'1',JPN,'1',KOR,'1',PAK,'1',PHL,'1',VNM,'1',XEA,'1',XIS,'1',XSA,'1'),            
              DECODE(szscapp_other_indian_subcont,XIS,'1'),    
              DECODE(szscapp_other_southeast_asia,XSA,'1'),   
              DECODE(szscapp_blk_or_afr_amer_opt,XAA,'1',XAF,'1',XCB,'1',XOA,'1'),     
              DECODE(szscapp_blk_or_afr_amer_other,XOA,'1'),   
              DECODE(szscapp_natve_hawaian_options,GUM,'1',XHI,'1',ASM,'1',XOP,'1'), 
              DECODE(szscapp_hawaiian_other,XOP,'1'),             
              DECODE(szscapp_white_options,XEU,'1',XME,'1',XOW,'1'),           
              DECODE(szscapp_white_other(XOW,'1')
         FROM
             saturn_midd.szscapp 
         WHERE
         spriden_id =  szscapp_id
         AND  spriden_ntyp_code = 'CAPL'
       IF upd_spbpers_upd_cur%ISOPEN
          THEN
             CLOSE upd_spbpers_upd_cur;
          END IF;
          OPEN upd_spbpers_upd_cur;
          LOOP
             FETCH upd_spbpers_upd_cur
              INTO v_pidm,v_birth_state,v_birth_city,v_latino_ind,v_latino_options,
                   v_indn_alaska_opt,v_indn_alaska_other,v_asian_options,
                   v_other_east_asia,v_other_indian_subcont,v_other_southeast_asia,
                   v_blk_or_afr_amer_opt,v_blk_or_afr_amer_other,v_natve_hawaian_options,           
                   v_hawaiian_other,v_white_options,v_white_other;
             EXIT WHEN upd_spbpers_upd_cur%NOTFOUND; 
             IF upd_spbpers_upd_cur%FOUND
               UPDATE  saturn.spbpers
                           set SPBPERS_ETHN_CODE  = CASE
                   WHEN v_latino_ind            IS NOT NULL THEN (spbpers_ethn_code = v_latino_ind,spbpers_activity_date = sysdate)     
                   WHEN v_latino_options        IS NOT NULL THEN (spbpers_ethn_code = v_latino_options,spbpers_activity_date = sysdate)
                   WHEN v_indn_alaska_opt       IS NOT NULL THEN (spbpers_ethn_code = v_indn_alaska_opt,spbpers_activity_date = sysdate)
                   WHEN v_indn_alaska_other     IS NOT NULL THEN (spbpers_ethn_code = v_indn_alaska_other,spbpers_activity_date = sysdate)
                   WHEN v_asian_options         IS NOT NULL THEN (spbpers_ethn_code = v_asian_options,spbpers_activity_date = sysdate)
                   WHEN v_other_east_asia       IS NOT NULL THEN (spbpers_ethn_code = v_other_east_asia,spbpers_activity_date = sysdate)             
                   WHEN v_other_indian_subcont  IS NOT NULL THEN (spbpers_ethn_code = v_other_indian_subcont,spbpers_activity_date = sysdate)
                   WHEN v_other_southeast_asia  IS NOT NULL THEN (spbpers_ethn_code = v_other_southeast_asia,spbpers_activity_date = sysdate)
                   WHEN v_blk_or_afr_amer_opt   IS NOT NULL THEN (spbpers_ethn_code = v_blk_or_afr_amer_opt,spbpers_activity_date = sysdate)
                   WHEN v_blk_or_afr_amer_other IS NOT NULL THEN (spbpers_ethn_code = v_blk_or_afr_amer_other,spbpers_activity_date = sysdate)
                   WHEN v_natve_hawaian_options IS NOT NULL THEN (spbpers_ethn_code = v_natve_hawaian_options,spbpers_activity_date = sysdate)
                   WHEN v_hawaiian_other        IS NOT NULL THEN (spbpers_ethn_code = v_hawaiian_other,spbpers_activity_date = sysdate)
                   WHEN v_white_options         IS NOT NULL THEN (spbpers_ethn_code = v_white_options,spbpers_activity_date = sysdate)
                   WHEN v_white_other           IS NOT NULL THEN (spbpers_ethn_code = v_white_other,spbpers_activity_date = sysdate)
                   WHEN v_birth_state           IS NOT NULL THEN (spbpers_stat_code_birth = v_birth_state,spbpers_activity_date = sysdate)
                   WHEN v_birth_city            IS NOT NULL THEN (spbpers_city_birth = v_birth_city,spbpers_activity_date = sysdate)
                   WHERE spbpers_pidm = v_pidm;
                  END
                     END IF;
          END LOOP;

    Did the procedure compile ?
    Doesn't look like a right Decode syntax.
    DECODE (col1,'VAL1','This','VAL2','That','ElseThis')
    means
    --Psuedocode
    IF col1 = 'VAL1' THEN 'This'
    IF col1 = 'VAL2' THEN 'That'
    ELSE 'ElseThis'You can use CASE statement Instead of DECODE
    CASE
    when      szscapp_amer_indn_alaska_other
         in ('XON','IND','JPN','KOR','PAK' ..... )  THEN '1'
    when      szscapp_hisp_or_latino_options
         in ('XCM','CUB','MEX','PRI','XSM','ESP','XOH' ...) THEN '2'
    END  SS

  • Help with a New Case for the ZEN Touch 20

    Does anyone know of a case other than the one that came with the player?Something I can use,not like the pouch. It would be nice to change songs or even adjust the volume with out having to pull the player out all the time. If some one from Creative reads this....do you have any idea how much money you can make if you put out a case that gives end uesers access to all functions with out haveing to remove from the case.PLEASE HELP!!!!!

    Please Creative!! We need to have at least one case option that allows access to the screen and buttons at a reasonable price. Maybe strike a deal with a current case manufacturer to supply an option for all of the desperate users out here. I'm seriously looking at options to make one myself from materials I can find (actually came across a how-to on making a case out of a milk jug--please don't make us resort to such measures).
    By the way, the Vaja case is nice, but $80 (including shipping) is ridiculous IMO when you just need something to hold the player and provide access at the same time.
    My 2 cents.

  • Help: How to use Case statement in Interface ODI11g?

    Hi
    From my Source base i am getting 'Year' Values and i want translate these values into a code in interface and after translate want to push to Target system.
    Example:
    From source Database i am getting value for
    Year
    2010
    2011
    2012
    When i get Year 2010 i want to modify value into 'FY10'
    when i get Year 2011 i want to modify value into 'FY11'
    and same for Year 2012 TO 'FY12'
    I was trying to do by Case statement but didn't got success.
    I dont want to create Lookup table in source system.
    Any help in this regards.
    Thanks
    Regards
    Sher
    Edited by: Sher Ullah Baig on Aug 26, 2012 5:52 PM

    CASE
    WHEN source_column='2010' THEN 'FY10'
    WHEN source_column='2011' THEN 'FY11'
    WHEN source_column='2012' THEN 'FY12'
    END

  • Decode Vs Case Statement

    What will be good for proformance wise:
    Decode or Case in a sql statement.?????

    See the following link for Tom Kyte's opinion (point #4 in his first answer):
    http://asktom.oracle.com/pls/ask/f?p=4950:8:16717708356827415201::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:1243867216406

  • Neeed help to write a case statement

    I want to write a case statement such that
    i have four name sunny,katie,linda,scott in which sunny is the manager
    the rek is that under sunny if katie,linds scott falls then i need to show "yes" in coloumn other wise "no"
    like
    case when cn1.sunny=cn2 in(katie,linda,scott) then 'y' else 'n'
    Edited by: user13001889 on Jun 20, 2011 1:04 PM

    What is a table structure? Sorry cannot test it right now..
    SELECT <columns>,(SELECT Total FROM tbl WHERE Y=2014)-(SELECT Total FROM tbl WHERE Y=2013)
    FROM tbl
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Help with Decode/CASE function

    Can anyone provide some help or insight how can this be done.
    Senario:
    I have two parameters in my report.
    Paramerer_A and Parameter_B
    If I enter a value (XYZ) in Parameter_A and value (XYZ) in Parameter_B, I want the report to display ERROR and do not run.

    Hi
    It is not possible to have a use defined message come up based on the values of parameters but we can stop the workbook from executing.
    First of all, you will will need to make sure that both parameters are optional and then create your condition such that it will not run if both are populated, like this:
    (Item1 = :Parameter_A OR Item2 = :Parameter_B)
    AND NOT
    :Parameter_A IS NOT NULL AND :Parameter_B IS NOT NULL
    You can also put in a check parameter that controls whether A or B should be used, with a prompt like this: Use Parameter A or Parameter B? Enter A or B
    :Check_Parameter = 'A' AND Item1 = :Parameter_A
    OR
    :Check_Parameter = 'B' AND Item2 = :Parameter_B
    Best wishes
    Michael

  • Need help in using a case statement in expression operator

    Hi All,
    I am using OWB version 10.2.0.1.0.
    My requirement is to add a new column called call _zone_key in expression operator and map it to the target table. I need to use the below expression for populating call_zone_key values
    Expression:
    case when (INGRP1.CHARGETYPE in ('O','F') or  INGRP1.TARIFF_GROUP in ('SMSINT','MMSINT')or ( INGRP1.CALL_TYPE = '002' and   INGRP1.TARIFF_GROUP  = 'MTV'))
    then
    (select call_zone_reltn_key from call_zone_reltn where
    call_zone_cd=substr(case
      when substr( INGRP1.B_SUBNO,1,2)='00'
      then
      substr( INGRP1.B_SUBNO,3)
      else substr( INGRP1.B_SUBNO,1)
      end,1,length(call_zone_cd))and rownum=1)
    else -1
    end
    All the columns needed for using the above expression is available in INGRP1 but still I am unable to deploy the mapping using above expression. Call_zone_reltn table is also imported to the module. I am getting below error
    Error:
    Warning
    ORA-06550: line 4980, column 2:
    PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
       ( - + case mod new not null others <an identifier>
       <a double-quoted delimited-identifier> <a bind variable> avg
       count current exists max min prior sql stddev sum variance
       execute forall merge time timestamp interval date
       <a string literal with character set specification>
       <a number> <a single-quoted SQL string> pipe
       <an alternatively-quoted string literal with character set specification>
       <an alternativ
    NEW_MOD_MAP_CELL_USAGE_FCT_PRE
    Create
    Warning
    ORA-06550: line 4989, column 43:
    PLS-00103: Encountered the symbol ")" when expecting one of the following:
       * & - + ; / at for mod remainder rem <an exponent (**)> and
       or group having intersect minus order start union where
       connect || multiset
    If i replace the expression with numbers such as 1 or 2, I am able to deploy the mapping.
    Kindly help in fixing this issue.
    Thanks,
    Kabilan

    You can't use the SELECT statement inside the expression, you need to join both tables before the expression. Use a Join operator with this JOIN condition:
    CALCULATED_CALL_ZONE_CD = call_zone_reltn.call_zone_cd ( + )
    Where Calculated_call_zone_cd proceed from a previous expression:
    CALCULATED_CALL_ZONE_CD = substr(case when substr( INGRP1.B_SUBNO,1,2)='00' then substr( INGRP1.B_SUBNO,3) else substr( INGRP1.B_SUBNO,1) end,1,length(call_zone_cd))
    And after joining both tables, you can use another expression to get the rownum, then another filter operator to keep only the rownum = 1, and now you can use your expression without the SELECT, using the call_zone_cd column from the outgroup in the joiner operator (you need to include that column in the filter operator to use it).
    Regards
    ANA GH

  • Help with Decode function

    Hello!!
    Can anyone please help me with the decode statement
    Table 1 Table2 Table3
    Id Id Code
    Volume Code
    For each of the codes in Table3 I need to find the corresponding Volume. Can I use decode in the select statement to this,
    Eg Code Volume
    ABC 20
    XYZ 10 etc etc.
    Thankyou all in advance.

    Your table structure is a little unclear from your post. I am assuming that what you posted was:
    Table 1
    Id
    Table2
    Id
    Code
    Table3
    Volume
    Code You can use decode if there are only a few values for table3. For example,
    SELECT table2.code,
    DECODE(table2.code,'ABC',10,'XYZ',20,'UNKNOWN') volume
    FROM table2
    or even
    SELECT code,DECODE(code,null,'NONE',
                      (SELECT volume FROM table3 where code=table2.code)) volume
    FROM table2However, the first will break, or at least be incorrect, if anyone adds a new code/volume pair, and is tedious if you have more than a few values. The second will likely be pretty slow if there are a large number of records in table3. The best solution would be to use a simple join rather than decode. Something like:
    SELECT table1.id, table2.code, table3.volume
    FROM table1, table2, table3
    WHERE table1.id = table2.id and
          table2.code = table3.code

  • Help with decode

    Let's call the field "xfieldx". It’s currently a char data type that either gets inputted as null or “y” meaning yes. The problem comes when the query counts the number of rows that have a non-null value. The sql is below
    sum(decode(xfieldx, null, 0, 'n', 0, 1)) as xfieldxCount
    still returns a char value and later, when subject to a numeric condition “>” it fails. I need to make sure that this count is occurring correctly. Any wisdom?

    Welcome to the forum!
    Whenever you have a question, please post a little sample data (CREATE TABLE and INSERT statements), and the results you have from that data, so that the people who want to help you can re-create the problem and test their ideas.
    If you have an existing query, post the complete query, point out where it's getting the wrong results, and explain how you'd get the right results in those places.
    Always say which version of Oracle you're uisng.
    Since this is your first post, I'll do some sample data for you:
    CREATE TABLE     table_x
    (       x_id     NUMBER (4)     PRIMARY KEY
    ,     xfieldx     VARCHAR2 (1)
    INSERT INTO table_x (x_id, xfieldx) VALUES (0, NULL);
    INSERT INTO table_x (x_id, xfieldx) VALUES (1, 'n');
    INSERT INTO table_x (x_id, xfieldx) VALUES (2, 'y');
    INSERT INTO table_x (x_id, xfieldx) VALUES (3, 'n');
    894540 wrote:Let's call the field "xfieldx". It’s currently a char data type that either gets inputted as null or “y” meaning yes. The problem comes when the query counts the number of rows that have a non-null value. The sql is below
    sum(decode(xfieldx, null, 0, 'n', 0, 1)) as xfieldxCount
    still returns a char value and later, when subject to a numeric condition “>” it fails. I need to make sure that this count is occurring correctly. Any wisdom?That DECODE doesn't return a CHAR; it returs a NUMBER, either 0 or 1. (You can't use SUM on a CHAR expression.) And it's guaranteed either 0 or 1, never NULL. If you're interested in how many of the rows have a non-NULL value, just use COUNT.
    The following query shows the difference:
    SELECT  SUM ( DECODE ( xfieldx
                         , NULL     , 0
                   , 'n'     , 0
                               , 1
             )               AS total_y
    ,       COUNT (xfieldx)          AS count_xfieldx
    FROM     table_x
    ;Output:
    `  TOTAL_Y COUNT_XFIELDX
             1             3This should work in any version of Oracle.
    What results are you trying to get?
    What are you trying to do with a > condition?

  • Need help with DECODE

    Hi,
    I need to write a DECODE function to which if I pass 'mystring' and if it has the value 'M' it should output 'M', if it has a value of 'F' it should output 'F' and if mystring is not same as string_coded then it should output string_coded.
    I know the below statement is incorrect.
    decode (mystring, 'M', 'M', 'F', 'F', (mystring <> string_coded), string_coded)
    Is there a way to correct this DECODE? Please suggest.
    Thanks.

    It is not clear of you want it to match the string 'string_coded' or if it is some column name, but with the example below you should be able to figure out what to adjust to make it work in your case.
    SQL> create table mytable
      2  as
      3  select 'M' mystring, 'X' string_coded from dual union all
      4  select 'F', 'X' from dual union all
      5  select 'X', 'X' from dual union all
      6  select 'Z', 'X' from dual
      7  /
    Tabel is aangemaakt.
    SQL> select mystring
      2       , string_coded
      3       , decode(mystring,'M','M','F','F',string_coded,'mystring = string_coded','mystring != string_coded') your_expression
      4    from mytable
      5  /
    M S YOUR_EXPRESSION
    M X M
    F X F
    X X mystring = string_coded
    Z X mystring != string_coded
    4 rijen zijn geselecteerd.Regards,
    Rob.

  • Help with TYPE and LIKE statements

    HI guys,
    I know this is really novice stuff, but I am a little confused.
    Can anyone please explain the exact difference between TYPE and like with the help of a program, to understand it.
    What situation would demand the use of each of the LIKE statement, since I can do all these things using the TYPE ?

    Hi Akhil,
    I summarized the info in SDN posts and SAP Help, to make it easier for you to understand. I also included some code snippets. Hope these prove to be helpful to you.
    The following is from SAP Help:
    The Additions TYPE and LIKE
    The additions TYPE type and LIKE dobj are used in various ABAP statements. The additions can have various meanings, depending on the syntax and context.
    ·        Definition of local types in a program
    ·        Declaration of data objects
    ·        Dynamic creation of data objects
    ·        Specification of the type of formal parameters in subroutines
    ·        Specification of the type of formal parameters in methods
    ·        Specification of the type of field symbols
    A known data type can be any of the following:
    ·        A predefined ABAP type to which you refer using the TYPE addition
    ·        An existing local data type in the program to which you refer using the TYPE addition
    ·        The data type of a local data object in the program to which you refer using the LIKE addition
    ·        A data type in the ABAP Dictionary to which you refer using the TYPE addition. To ensure compatibility with earlier releases, it is still possible to use the LIKE addition to refer to database tables and flat structures in the ABAP Dictionary. However, you should use the TYPE addition in new programs.
    The LIKE addition takes its technical attributes from a visible data object. As a rule, you can use LIKE to refer to any object that has been declared using DATA or a similar statement, and is visible in the current context.  The data object only has to have been declared. It is irrelevant whether the data object already exists in memory when you make the LIKE reference.
    ·        In principle, the local data objects in the same program are visible. As with local data types, there is a difference between local data objects in procedures and global data objects. Data objects defined in a procedure obscure other objects with the same name that are declared in the global declarations of the program.
    ·        You can also refer to the data objects of other visible ABAP programs. These might be, for example, the visible attributes of global classes in class pools. If a global class cl_lobal has a public instance attribute or static attribute attr, you can refer to it as follows in any ABAP program:
    DATA dref TYPE REF TO cl_global.
    DATA:  f1 LIKE cl_global=>attr,
           f2 LIKE dref->attr.
    You can access the technical properties of an instance attribute using the class name and a reference variable without first having to create an object. The properties of the attributes of a class are not instance-specific and belong to the static properties of the class.
    Example
    TYPES: BEGIN OF struct,
             number_1 TYPE i,
             number_2 TYPE p DECIMALS 2,
           END OF struct.
    DATA:  wa_struct TYPE struct,
           number    LIKE wa_struct-number_2,
           date      LIKE sy-datum,
           time      TYPE t,
           text      TYPE string,
           company   TYPE s_carr_id.
    This example declares variables with reference to the internal type STRUCT in the program, a component of an existing data object wa_struct, the predefined data object SY-DATUM, the predefined ABAP type t and STRING, and the data element S_CARR_ID from the ABAP Dictionary.
    The following info is from various posts:
    --> Type: It is used when userdefined object link with SAP system data type.
    Local types mask global types that have the same names. When typing the interface parameters or field symbols, a reference is also possible to generic types ANY, ANY TABLE,INDEX TABLE, TABLE or STANDARD TABLE, SORTED TABLE and HASHED TABLE.
    --> Like: It is when data object link with the other data object.
    --> TYPE, you assign datatype directly to the data object while declaring.
    --> LIKE,you assign the datatype of another object to the declaring data object. The datatype is referenced indirectly.
    you can refer to all visible data objects at the ABAP program's positon in question. Only the declaration of the data object must be known. In this case it is totally irrelevant whether the data object already exists physically in
    memory during the LIKE reference. Local data objects mask global data objects that have the same name.
    --> Type is a keyword used to refer to a data type whereas Like is a keyword used to copy the existing properties of already existing data object.
    Types: var1(20) type c.
    data: var2 type var1. ( type is used bcoz var1 is defined with TYPES and it
    does not occupy any memory spce.
    data: var3 like var2. ( like is used here bcoz var2 is defined with DATA
    so it does occupy space in memory ).
    data: material like mara-matnr. ( like is used here bcoz mara-matnr is stored in memory)
    --> Type refers the existing data type
    --> Like refers the existing data object
    Please Reward Points if any of the above points are helpful to you.
    Regards,
    Kalyan Chakravarthy

  • Help with filling a if statement

    hello everyone i hope someone can help me
    if you look at my code below the arraylist contains the number 8. but i want to know how i can use that number 8 inside the if statement (if (i%10 == 1)) where the number 1 is, so that number 1 will change to the number 8.
    could someone please help me.
    thanks for your time
    loftty
    hash.put(new Integer(8), st1);
    if(hash.containsValue(st1)) {
                             Enumeration e = hash.keys();
                                  while (e.hasMoreElements()) {
    Object it = e.nextElemenet();
    Object it1 = hash.get(it);
    if (it1.equals(st1){
    arraylist.add(it);
    Enumeration e = v.elements();
                        Object o;
                        for(int i = 1;e.hasMoreElements();i++) {
                        o = e.nextElement();
                             if (i%10 == 1){
                        System.out.println(o);

    By ArrayList do you mean the hashtable in your code?
    Because a hastable is not the same as an arraylist....
    For one thing your hashtable is wrong...
    The first parameter you pass in a put method is a key, the second is an object...
    When you want to get the object from the hashtable you pass it the key.... like so:
    hash.put("Str1", new Double(8));
    Double l_Double = (Double)hash.get("Str1");With an ArrayList you don't use keys by the way...
    Vermelh0

Maybe you are looking for

  • ASDM Access and local username/PW

    Ok, I happened upon this today and thought it was a bit weird. We have a pair of ASA5520 as our primary firewalls. We are using EasyVPN,and the usernames authenticate via the local username / PW configured on the firewall. All of these usernames have

  • ITunes 8 on a G3 iBook

    I'm trying to run iTunes 8 on a G3 500MHz iBook, with only 3.5GB HDD space remaining. I have a backup on an eHDD of my main iTunes Library, 40GB, created on a G5 iMac running iTunes 9.2 I've tried the following on the G3 : launch + Option, selecting

  • My second BMP battery is also broken

    Hello everyone, My first MBP battery was changed due the Apple's replacement program. First one was only 12 days old and it had lost almost 30% of its capacity. This second one is "much" older one but I have only 42 loadcycles. Does Apple, Sony, or w

  • Reg:Refreshing the Screen

    Hi Friends, In my Application i have five Screens. Each screen has different functionality. My requirement is such that after i Execute the function module my Screen should be refreshed with the updated values. Is this possible in Web-Dynpro(Java) Sc

  • How i can make some components visible on comboBox selection change ?

    Hi Thank you for reading my post how i can make some of form component visible/ invisible when user changed a combobox selected item ? can we use partial rendering ?(i just read that ADF support partial rendering) thanks