Help! format of decode statements with between or signs ?

Looking for an example of a decode statement with either a between/and or < > signs in the comparison field.
I have tried several variations, but none seem to work. Any help would be appreciated.
Here's a sample that doesn't work.
Select course_no, section_no, capacity, decode(capacity, (capacity < 12), Less than 12, (capacity between 13 and 15), 13-15, More than 15) from section;
Thanks in advance

Hi,
There is a limitation to the Case function, as it cannot be used in the PL/SQL (atleast upto Oracle 8i). Therefore, the only option left is Decode.
If you have to compare the values like capacity < 12 then display Less than 12. You can write it using combination of other functions.
For e.g. follow the steps below:-
1)If you deduct 12 from capacity : (capacity-12) [it will give result as +ve, 0 or -ve.]
2)If you have to narrow down the values to above three options, use function sign:
SIGN(capacity-12) [will result into +1, 0 or -1]
3)Then compare the values using Decode:
DECODE(SIGN(capacity-12),-1,Less than 12,Greater than or equal to 12)
The Decode can be used inside Decode(nested Decode) in above steps to compare more than one values (range between) to get the desired result. Hope have made it clear enough. If not, please let me know.
Cheers.
Yogesh D.

Similar Messages

  • How to replace huge decode statements with lookups to some simple code/key

    I have a legacy PL/SQL application, composed of many very huge decode statements. And the most terribe one is that the guys who develops the application left the company now, leaves no documentation.
    We are trying to read and understand those PL/SQL programs, and I'm asked to replace those huge decode statements with lookups to some simple code/key tables? But I have no idea about how to design such code/key tables. Is there any one who has similar experience may help me? Besides code/key tables, any idea will be welcome.
    Thank you very much!

    Not sure what your data looks like but sometimes decode can be replaced with more appropriate functions, ie;
    SQL> with t as (
       select 'DAY' a, 30 b, null c, null d from dual union all
       select null a, null b, 'MONTH' c, 12 from dual)
    select coalesce(b,d)
    from t
    COALESCE(B,D)
               30
               12
    2 rows selected.
    SQL> with t as (
       select 'DAY' a, 30 b, null c, 0 d from dual union all
       select null a, 0 b, 'MONTH' c, 12 from dual)
    select greatest(b,d)
    from t
    GREATEST(B,D)
               30
               12
    2 rows selected.

  • Decode statement with ||','||

    Hi ,
    I've the following requriement where i need to append the 2 numbers with comma inside the decode stmt
    create table  A_STY_VON ( C_1_ID number ,C_2_ID number ,C_3_ID number)
    Insert into A_STY_VON
       (C_1_ID, C_2_ID, C_3_ID)
    Values
       (1, 2, 3);
    Insert into A_STY_VON
       (C_1_ID, C_3_ID)
    Values
       (1, 3);
    Insert into A_STY_VON
       (C_1_ID, C_2_ID)
    Values
       (1, 2);
    Insert into A_STY_VON
       (C_2_ID, C_3_ID)
    Values
       (2, 3);And the following select stmt is working
    SELECT   DECODE (
              A.C_3_ID,
              NULL, DECODE (A.C_2_ID,
                            NULL, A.C_1_ID,
                            A.C_1_ID || A.C_2_ID) ,
                 A.C_1_ID
             || A.C_2_ID
             || A.C_3_Id) dcd
      FROM A_STY_VON A But i want the comma between the numbers so i tried the following ( with distinct )
    where i'm getting the invalid number error
    SELECT  distinct DECODE (
              A.C_3_ID,
              NULL, DECODE (A.C_2_ID,
                            NULL, A.C_1_ID,
                            A.C_1_ID ||','|| A.C_2_ID) ,
                 A.C_1_ID
              ||','|| A.C_2_ID
              ||','|| A.C_3_Id) dcd
      FROM A_STY_VON A Could you please help me to achieve this
    Thank you
    Edited by: Smile on Apr 26, 2012 3:50 AM

    Just so you can understand why the problem has happened...
    There are some implicit datatype conversions going on in your statement, let's just look at a small part of it...
    DECODE (A.C_2_ID,
                            NULL, A.C_1_ID,
                            A.C_1_ID || A.C_2_ID)Your ID's are numeric.
    DECODE as a function can only return a single datatype. That datatype is determined by the datatype of the first value to be returned (if it's null that's another issue but let's not go there).
    So, in your above statement the datatype returned by DECODE is determined by A.C_1_ID, which is numeric.
    Also in your above statement you are doing a string concatenation of A.C_1_ID and A.C_2_ID, so those numbers are implicitly converted to strings and concatenated, but then because DECODE is now defined as needing a number to be returned, the concatenated string of numbers are implicitly converted back to a number, which is fine because the whole string is numeric.
    In PL/SQL code this would go along these principles...
    ... function ...
    declare
      v_retval NUMBER;
      v_c_1_id NUMBER := 123;
      v_c_2_id NUMBER := 234;
    begin
      if v_c_2_id is null then
        v_retval := v_c_1_id;
      else
        v_retval := to_number(to_char(v_c_1_id)||to_char(v_c_2_id));
      end if;
      return v_retval;
    end;Now, if you try and put a comma into your concatenation...
    DECODE (A.C_2_ID,
                            NULL, A.C_1_ID,
                            A.C_1_ID ||','|| A.C_2_ID)Still the first value returned has defined the DECODE as needing to return a numeric value, but this time the second returned value (The 'else' part of the decode) has a string containing numeric digits with a comma in between. When it implicitly tries to convert this string to a number so it can be returned from the function, it finds that it's not a valid number.
    And we can see this if we use the same PL/SQL type code...
    SQL> declare
      2    v_retval NUMBER;
      3    v_c_1_id NUMBER := 123;
      4    v_c_2_id NUMBER := 234;
      5  begin
      6    if v_c_2_id is null then
      7      v_retval := v_c_1_id;
      8    else
      9      v_retval := to_number(to_char(v_c_1_id)||','||to_char(v_c_2_id));
    10    end if;
    11    --return v_retval;
    12  end;
    13  /
    declare
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    ORA-06512: at line 9It can't do the to_number on the string when it expects the return value to be numeric.
    SQL has a nice NVL2 function (http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions106.htm) which you can use instead when trying to determine different output based on one of the values being null...
    SQL> ed
    Wrote file afiedt.buf
      1  with a as (select 123 as c_1_id, 234 as c_2_id from dual union all
      2             select 789, null from dual)
      3  --
      4  -- end of test data
      5  --
      6  select c_1_id, c_2_id,
      7         nvl2(c_2_id,c_1_id||','||c_2_id,c_1_id) as result
      8* from a
    SQL> /
        C_1_ID     C_2_ID RESULT
           123        234 123,234
           789            789Again, this is using implicit datatype conversion and the resultant datatype of NVL2 is determined by the first result (the second parameter) just as with decode, but because of the way it works, the first result is what it should do if the passed in first parameter is not null and therefore you can force the implicit conversion to a string datatype that way.

  • Order by decode statement with Union all

    Hi
    I use Database Version: Oracle 9.2.0.1.0
    OCI version 9.2
    I try to use order by decode while i have a select base on union and I get en error:
    ORA-01785: ORDER BY item must be the number of a SELECT-list expression
    Here is my code:
    select catalog_type, catalog_id, item_id, item_name
    from items_catalog
    union all
    select catalog_type, catalog_id, organisation_unit_id, organisation_unit_name
    from units_catalog
    order by decode(catalog_type, 1, item_id, organisation_unit_id)
    If I use the decode on a select statement without union, it works.
    What I have to do in order to make it work on union all select?
    Tnx

    Hi,
    Here's a slightly different way:
    COLUMN     sort_key   NOPRINT
    VARIABLE     catalog_type_wanted     VARCHAR2 (5)
    EXEC         :catalog_type_wanted := '4'; 
    SELECT       catalog_id, item_id, item_name
    ,       CASE
               WHEN  :catalog_type_wanted = '1'  THEN  '1'
                                               ELSE  '2'
           END || item_id          AS sort_key
    FROM       items_catalog
          UNION ALL
    SELECT    catalog_id, organisation_unit_id, organisation_unit_name
    ,       CASE
               WHEN  :catalog_type_wanted = '1'  THEN  '2'
                                               ELSE  '1'
           END || organisation_unit_name     AS sort_key
    FROM       units_catalog
    ORDER BY  sort_key
    ;This way guarantees that (for example) 'SHOP50' comes before 'SHOP58', whether or not they are in the first half of the output or the second half.
    Notice that this uses the SQL*Plus COLUMN ... NOPRINT command to hide the sort_key column.
    If you're not using SQL*Plus, then whatever front end you are using may have a similar feature.
    If not, then you can do the UNION in a sub-query, as Daniel did, but do the ORDER BY in the main query (only).

  • How to create procedure having delete statement with between function?

    I am very new in SQL Development, I want to create a procedure having two date variable start and end and these two variable i want to use in procedure body to delete data from a specific table between two date duration.
    Please guide
    Thanks,

    create procedure some_proc (start_date date, end_date date)
    as
    begin
         delete from your_table
                   where your_date_column between start_date and end_date;
    end some_proc;
    /

  • Help on a decode statement

    I wish to decode a column I've named "Request Description"
    to include the data name "Odometer" if odometer exists and if not I want to display the result: ('request_bytes' from 'module_name')
    e.g.: 9A from ECM
    lines 2,3,4 are the referenced areas.
    Here is my entire query:
    SELECT distinct vehicle.vin, ada_param.TARGETED_VALUE_ID as "Module ID",
         max(to_char(decode(data_req.NAME,'Odometer','Odometer',
         '%AUTODTC%',ada_param.req_data_bytes||'from'||module.name))) as "Request Description",
    vehicle_call_session.session_initation_time as "Call Start",
    vehicle_call_session.session_end_time as "Call End", ' ' as "Latitude", ' ' as "Longitude",
         vehicle_class.make||' '||vehicle_class.model||' '||vehicle_class.year as "Description",
         data_req_type.id as "Data Type", vehicle_case_data.raw_value as "Raw Data",
         data_req.name as "DTC/Parameter", vehicle_case_data.dtc_status as "DTC Status"
    FROM vs1_ll.vehicle,
    vs1_ll.data_req,
    vs1_ll.vehicle_call_session,
    vs1_ll.vehicle_class,
    vs1_ll.vehicle_case_data,
    vs1_ll.program,
    vs1_ll.prog_data_req_set_assoc,
    vs1_ll.data_req_set,
    vs1_ll.vehicle_prog_enroll,
    vs1_ll.vehicle_fleet_assoc,
    vs1_ll.ada_param,
    vs1_ll.data_req_type,
    vs1_ll.vehicle_call_detail,
         vs1_ll.module_data_req_assoc,
         vs1_ll.module,
         vs1_ll.c2_param
    WHERE ( (vehicle.ID = vehicle_call_session.vehicle_id)
    AND (vehicle_class.ID = vehicle.vehicle_class_id)
    AND (data_req.ID = vehicle_case_data.data_req_id)
    AND (vehicle_call_session.ID =
    vehicle_case_data.vehicle_call_session_id
    AND (program.ID = prog_data_req_set_assoc.program_id)
    AND (data_req_set.ID = prog_data_req_set_assoc.data_req_set_id)
    AND (vehicle.ID = vehicle_prog_enroll.vehicle_id)
    AND (program.ID = vehicle_prog_enroll.program_id)
    AND (vehicle.ID = vehicle_fleet_assoc.vehicle_id)
    AND ((data_req.ID = ada_param.ID)
              OR (data_req.ID = c2_param.ID))
    AND (data_req_type.ID = data_req.data_req_type_id)
    AND (vehicle_call_session.ID =
    vehicle_call_detail.vehicle_call_session_id
    AND (program.ID = vehicle_call_detail.program_id)
              AND (module_data_req_assoc.DATA_REQ_ID = data_req.ID)
    and vehicle_call_session.SESSION_STATUS_ID = 1
    and vehicle_fleet_assoc.FLEET_ID = 8
    and vehicle_call_session.SESSION_INITATION_TIME >= to_date ('03/14/2007 3:57:00 PM','MM/DD/YYYY HH:MI:SS PM')
    and vehicle.vin = 'XXXXXXXXXXXXXXXXX'
    and data_req.name like '%AUTODTC%'
    and data_req.name like 'Odometer'
    group by (vehicle.vin, ada_param.TARGETED_VALUE_ID, vehicle_call_session.session_initation_time, vehicle_call_session.session_end_time, vehicle_class.make||' '||vehicle_class.model||' '||vehicle_class.year,
    data_req_type.id, vehicle_case_data.raw_value, data_req.name, vehicle_case_data.dtc_status)
    order by vehicle_call_session.SESSION_INITATION_TIME, vehicle.vin
    any ideas would be appreciated as this is currently returning no data.

    hmmm....tried a case and it seems to lock up:
    SELECT distinct vehicle.vin, ada_param.TARGETED_VALUE_ID as "Module ID",
         (case data_req.NAME when 'Odometer' then 'Odometer'
         when '%AUTODTC%' then (ada_param.req_data_bytes||'from'||module.name) END) "Request Description",
    vehicle_call_session.session_initation_time as "Call Start",
    vehicle_call_session.session_end_time as "Call End", ' ' as "Latitude", ' ' as "Longitude",
         vehicle_class.make||' '||vehicle_class.model||' '||vehicle_class.year as "Description",
         data_req_type.id as "Data Type", vehicle_case_data.raw_value as "Raw Data",
         data_req.name as "DTC/Parameter", vehicle_case_data.dtc_status as "DTC Status"
    FROM vs1_ll.vehicle,
    vs1_ll.data_req,
    vs1_ll.vehicle_call_session,
    vs1_ll.vehicle_class,
    vs1_ll.vehicle_case_data,
    vs1_ll.program,
    vs1_ll.prog_data_req_set_assoc,
    vs1_ll.data_req_set,
    vs1_ll.vehicle_prog_enroll,
    vs1_ll.vehicle_fleet_assoc,
    vs1_ll.ada_param,
    vs1_ll.data_req_type,
    vs1_ll.vehicle_call_detail,
         vs1_ll.module_data_req_assoc,
         vs1_ll.module,
         vs1_ll.c2_param
    WHERE ( (vehicle.ID = vehicle_call_session.vehicle_id)
    AND (vehicle_class.ID = vehicle.vehicle_class_id)
    AND (data_req.ID = vehicle_case_data.data_req_id)
    AND (vehicle_call_session.ID =
    vehicle_case_data.vehicle_call_session_id
    AND (program.ID = prog_data_req_set_assoc.program_id)
    AND (data_req_set.ID = prog_data_req_set_assoc.data_req_set_id)
    AND (vehicle.ID = vehicle_prog_enroll.vehicle_id)
    AND (program.ID = vehicle_prog_enroll.program_id)
    AND (vehicle.ID = vehicle_fleet_assoc.vehicle_id)
    AND ((data_req.ID = ada_param.ID)
              OR (data_req.ID = c2_param.ID))
    AND (data_req_type.ID = data_req.data_req_type_id)
    AND (vehicle_call_session.ID =
    vehicle_call_detail.vehicle_call_session_id
    AND (program.ID = vehicle_call_detail.program_id)
              AND (module_data_req_assoc.DATA_REQ_ID = data_req.ID)
    and vehicle_call_session.SESSION_STATUS_ID = 1
    and vehicle_fleet_assoc.FLEET_ID = 8
    and vehicle_call_session.SESSION_INITATION_TIME >= to_date ('03/14/2007 3:57:00 PM','MM/DD/YYYY HH:MI:SS PM')
    and vehicle.vin = 'XXXXXXXXXXXXXXXXX'
    and data_req.name like '%AUTODTC%'
    or data_req.name = 'Odometer'
    order by vehicle_call_session.SESSION_INITATION_TIME, vehicle.vin

  • Help automate an UPDATE Statement with PL/SQL

    Hello, I am on 10g R2, I am slowly learning PL/SQL, got a few books, watching videos on youtube and other things about like Best Practices and etc. I wanted to automate this SQL:
    Basically each month I have to update a whole bunch of older Tables against the current months Table.
    Older Table = ta
    Newer Table = tt
    I was thinking maybe I can like put into a list (like an array), and list all the older tables in there for ta, I have 26 so far and each month I add +1.
    The tt table is just one, that's why I was thinking I could automate that inside a loop ?
    UPDATE OLDER_TABLE_DATE ta
    SET (ta.GTP, ta.UPDATE_DT) =
         (SELECT tt.GTP, SYSDATE
          FROM NEWEST_TABLE_UPDATED tt
          WHERE ta.customer_id = tt.customer_id
          AND ta.STAMP_DATE = tt.STAMP_DATE)
    WHERE EXISTS (SELECT 1
            FROM NEWEST_TABLE_UPDATED tt
            WHERE ta.customer_id = tt.customer_id
            AND ta.STAMP_DATE = tt.STAMP_DATE
            AND (NVL(ta.GTP, 'X') != NVL(tt.GTP, 'X')));
    COMMIT;What do you guys think ? example or help would be appreciated. I can run this as an anonymous block for now, that's fine, thank you!

    Assumptions:-
    -Your all old/new tables are in same schema.
    - Their names have word "OLDER".
    - You will run the procedure from the same schema where all old and new tables exits.
    NOTE: - Please handle exceptions in the given code accordingly, for example, when update fails then handle the exceptions.
    -As mention earlier, this approach does not sound very good. A good solution will be change in design such a way that one table(partition on months) stores all the monthly data.
    CREATE OR REPLACE PROCEDURE UPDATE_TABLES_PROC
    AS
    cursor c1 is
    select table_name from user_tables
    where table_name like '%OLDER%';
    type t_current_table is table of c1%rowtype;
    v_current_table t_current_table;
    SQL_STMT VARCHAR2(3000):=0;
    BEGIN
    OPEN C1;
    LOOP
        FETCH C1 BULK COLLECT INTO  v_current_table  LIMIT 10;
        IF v_current_table.count>0 then
        FOR i in v_current_table .first..v_current_table .last
        LOOP
        SQL_STMT:='UPDATE ' ||v_current_table(i).table_name|| ' ta
                         SET (ta.GTP, ta.UPDATE_DT) =
                                       (SELECT tt.GTP, SYSDATE
                                        FROM NEWEST_TABLE_UPDATED tt
                                        WHERE ta.customer_id = tt.customer_id
                                       AND ta.STAMP_DATE = tt.STAMP_DATE)
                          WHERE EXISTS (SELECT 1
                                       FROM NEWEST_TABLE_UPDATED tt
                                       WHERE ta.customer_id = tt.customer_id
                                       AND ta.STAMP_DATE = tt.STAMP_DATE
                                       AND (NVL(ta.GTP, ''X'') != NVL(tt.GTP, ''X'')))';
        EXECUTE IMMEDIATE SQL_STMT;
        EXIT WHEN c1%NOTFOUND;
        END LOOP;
        END IF;
    COMMIT;
    EXIT WHEN c1%NOTFOUND;
    END LOOP;
    CLOSE C1;
    END UPDATE_TABLES_PROC;

  • Help!! Apple startup flicks between Apple sign and blocked sign

    I restarted my Mac mini and now, when I turn it on it, the apple sign on startup flicks between the apple sign and a blocked, no entry sign (a circle with a diagonal line through it). It stays like this for hours and hasn't changed. How do I fix this?!

    If 10.7.0 or later...
    Bootup holding CMD+r, or the Option/alt key to boot from the Restore partition & use Disk Utility from there to Repair the Disk, then Repair Permissions.
    If that doesn't help Reinstall the OS.

  • Error while replacing IF statements with DECODE function in procedure

    Hi All,
    I have created a procedure which has nested IF statements. Now I want to replace the IF statements with DECODE functions to improve performance.
    Procedure:
    IF (var_int_sev = '0')
    THEN
    var_sev := '2';
    ELSE
    SELECT sev
    INTO var_int_sev
    FROM errorconfig
    WHERE errorcode = var_errorcode;
    var_sev := var_int_sev;
    END IF;
    I converted the above IF statement into DECODE function as mentioned below:
    var_Sev := DECODE(var_int_sev,0,2,SELECT severity FROM errorconfig WHERE errorcode=var_ErrorCode)
    But it throws below error at the select statement used inside DECODE.
    Error(58,51): 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
    Can someone help me in converting the IF to DECODE in the above case. Also how can we use a select statement inside decode.

    instead of trying to rewrite all your code and hoping that the performance will be better, it's a better option to investigate and find out which part of your application is slow
    read this:
    When your query takes too long ...

  • Problem with DECODE statement while migrating forms to 6i

    Hi,
    I'm migrating a form from 5 to 6i. When I compiled the form, I got this error witha decode statement.
    The error is
    Error 307 at line 15 column 7
    too many declarations of "DECODE" match this call
    The trigger has this code:
    IF :PRUN_RECS_INSERTED = 'Y' THEN
          RETURN ;
       END IF ;
       INSERT INTO GJBPRUN
        ( GJBPRUN_JOB,
          GJBPRUN_ONE_UP_NO,
          GJBPRUN_NUMBER,
          GJBPRUN_ACTIVITY_DATE,
          GJBPRUN_VALUE )
       SELECT :KEYBLCK_JOB,
              :ONE_UP_NO,
               GJBPDFT_NUMBER,
               SYSDATE,
          DECODE(GJBPDFT_VALUE, 'SYSDATE',
                          DECODE(GJBPDEF_LENGTH,'11',TO_CHAR(SYSDATE,'DD-MON-YYYY'), SYSDATE),
                          GJBPDFT_VALUE)
       FROM   GJBPDFT G, GJBPDEFEdited by: Charan on Mar 16, 2011 9:15 AM

    Hi Charan
    i think it's all about using both CHARACTER and DATE values at the same time in a DECODE statment u should either use char or date datatype.
    DECODE compares expr to each search value one by one. If expr is equal to a search, then Oracle Database returns the corresponding result. If no match is found, then Oracle returns default. If default is omitted, then Oracle returns null.
    e.g.
    If expr and search are character data, then Oracle compares them using nonpadded comparison semantics.
    expr, search, and result can be any of the datatypes CHAR, VARCHAR2, NCHAR, or NVARCHAR2.
    The string returned is of VARCHAR2 datatype and is in the same character set as the first result parameter.
    for more pls have a look here
    Hope this helps,
    Regards,
    Abdetu...

  • Need help on decode statement

    I had the table as follows :
    ITEMCODE TEDCODE AMOUNT
    AAAA BED 12345
    AAAA EDU CESS 1234
    AAAA SHECESS 123
    AAAA CST 3% 12456
    AND SO ON.
    Now i want to convert the rows in Column heading TEDCODE to columns. But i want the specific rows like BED, EDU CESS, SHECESS in one column suppose EXCISE, and the other row i.e CST 3% in other column under heading TAX.
    Please help me how i can do it using Decode statement.

    SQL> create table t (itemcode varchar(4),tedcode varchar(10),amount number);
    Table created.
    SQL> insert into t values('AAAA','BED',12345);
    1 row created.
    SQL> insert into t values('AAAA','EDU CESS',1234);
    1 row created.
    SQL> insert into t values('AAAA','SHECESS',123);
    1 row created.
    SQL> insert into t values('AAAA','CST 3%',12456);
    1 row created.
    SQL> select itemcode, tedcode,decode(tedcode,'CST 3%',null,amount) EXCISE, decod
    e(tedcode,'CST 3%',amount,null) TAX from t;
    ITEM TEDCODE    EXCISE                                          TAX
    AAAA BED        12345
    AAAA EDU CESS   1234
    AAAA SHECESS    123
    AAAA CST 3%                                                   12456

  • Problem with Decode statement

    Hi
    I am trying to achieve the following in my report:
    If an employee has a surname of . (dot) or a first name of . (dot), the report should not display a dot. An employee's name is made up of surname, first name and middle name which should all be concatenated together. To try to achieve this, I have the following statement in my report:
    decode(e.Surname, '.', ( LTRIM(RTRIM((INITCAP(e.FIRST_NAME)))||' '||INITCAP(e.MIDDLE_NAME)) ) ,
    e.FIRST_NAME, '.', ( LTRIM(RTRIM((INITCAP(e.Surname)))||' '||INITCAP(e.MIDDLE_NAME)) ) ,
    ( LTRIM(RTRIM((INITCAP(e.SURNAME )))||', '||INITCAP(e.FIRST_NAME)||' '||INITCAP(e.MIDDLE_NAME)) ) ) as emp_name
    FROM Employee e
    Problem: The above statement is only working for those employees with surname of . (dot). It's not working for first names of dot. How can I use the decode statement OR is there any other way of doing it without using the CASE statement?
    It seems my decode statement doesn't work with 2 different fields (surname, firstname) being tested within one decode statement.Thanks.

    Thank you so much InoL . I have used the ltrim with Replace but now have a new problem.
    Because I am joining Surname, First name and middle name together and put a comma after the Surname, the name now appears as follows:
    , Maria Ane (if Surname is a dot)
    Boiler, (if first name is a dot)
    I would like to get rid of a comma and only have comma when surname or first name does not have a dot, i.e. for those people with full names e.g. Blake, Anna Marie.
    InoL, how can I achieve this? Thanks.

  • Need help in decode statement to check condition

    Hi All,
    I have table emp with below structure
    empno
    work_phone_no
    Home_phone
    cell_phone
    For the employee if work_phone & Home Phone is null then in place of work_phone we need to send the cell_phone number.
    How to use the decode statement in this scenario to test for Home_phone
    condition in the select statement.
    select DECODE (work_phone_no,
    null, cell_phone_no,office_phone_no )
    from emp
    Thanks

    Hi,
    Given the data you posted:
    empno work_phone_no home_phone_no cell_phone_no
    1     null          80032108556   8003210855
    2     null          null          8003210000 and your requirement is
    "If work & Home nunbers are null then display cellhone number in place of workphone number "
    , then, as John said, you do not want the results you posted. You want:
    1 null       80032108556
    2 8003210000 null That is, on the first row, where empno=1, the work_phone_no is NULL because the home_phone_no is NOT NULL, and cell_phone_no is only to be shown when both of the other phone numbers are missing.
    To get the results above, use CASE:
    SELECT  empno
    ,       CASE
                WHEN  work_phone_no IS NULL
                  AND home_phone_no IS NULL
                THEN cell_phone_no
                ELSE work_phone_no
            END  AS work_phone_no
    ,       home_phone_no
    FROM    ...If you really do want the results you posted, then, as John said, use NVL.

  • So What Now with Help Formats ???

    Well... the launch of Vista and the death of Winhelp has
    really shafted us... and I'm sure a lot of others too. Current
    situation as I understand it is :
    1) Winhelp is dead.
    2) HTML Help is supported but is functionally inferior in the
    following ways :
    - Window position cannot be specified as a percentage of the
    screen (pixels only) which is awkward for secondary windows as we
    need to support everything from 1024x768 to 1920x1280.
    - Context sensitive help support is dreadful compared to
    winhelp - no formatted text, bullets, graphics, hyperlinks, etc...
    - Microsoft refuse to allow CHM files to be launched over a
    network so a server install is out (without a naughty registry
    hack).
    3) Webhelp is supported but rumoured to be on the way out in
    terms of Robohelp support. Is this true ? Its also extremely clunky
    to ship with software due to number of files and, AFAICS, offers no
    context sensitive help functionality. I guess we could get round
    the former by using .MHT files but reasonable support for context
    sensitive help is a must.
    4) The Windows Vista Help directory seems to use 'h1s' files.
    What on earth is this ? For sure Vista has nicely formatted Context
    Sensitive Help but how ? Is this the new, much publicised MS Help
    format ?
    Basically, we need a sensible single file help system for the
    app and context sensitive help with hyperlinks & formatting.
    Anybody have suggestions on what the trend is here - is there even
    a single format solution for what must be a common applications
    requirement ?
    Are Adobe planning their own Winhelp support now that MS have
    ditched it ?
    Are MS planning a new Help System ?
    Thanks,
    Iain.

    I find it fascinating that Microsoft distributes winhelp.exe
    (16-bit
    WinHelp) as part of Vista but stubbornly refuses to
    distribute winhlp32.exe
    (32-bit WinHelp). Apparently Microsoft still needs/wants to
    use WinHelp
    popups so they're keeping the 16-bit WinHelp executable as
    part of Vista.
    So now here's my question... Robohelp has its own .dll
    (RoboEx32.dll) that
    it allows us to distribute. My understanding is that this is
    what allows us
    to have the tripane view. Having been mostly away from help
    development for
    the last several years but about to enter the fray again,
    what happens if I
    develop a RoboHelp Help2000 project and load project.hlp,
    project.cnt and
    the RoboHelp .dll file onto a Vista machine (which only has
    winhelp.exe)??
    Does this work?
    Thanks
    Mike
    "Tamilyrn" <[email protected]> wrote in
    message
    news:[email protected]...
    > Well... the launch of Vista and the death of Winhelp has
    really shafted
    us...
    > and I'm sure a lot of others too. Current situation as I
    understand it is
    >
    > 1) Winhelp is dead.
    >
    > 2) HTML Help is supported but is functionally inferior
    in the following
    ways :
    > - Window position cannot be specified as a percentage of
    the screen
    (pixels
    > only) which is awkward for secondary windows as we need
    to support
    everything
    > from 1024x768 to 1920x1280.
    > - Context sensitive help support is dreadful compared to
    winhelp - no
    > formatted text, bullets, graphics, hyperlinks, etc...
    > - Microsoft refuse to allow CHM files to be launched
    over a network so a
    > server install is out (without a naughty registry hack).
    >
    > 3) Webhelp is supported but rumoured to be on the way
    out in terms of
    Robohelp
    > support. Is this true ? Its also extremely clunky to
    ship with software
    due to
    > number of files and, AFAICS, offers no context sensitive
    help
    functionality. I
    > guess we could get round the former by using .MHT files
    but reasonable
    support
    > for context sensitive help is a must.
    >
    > 4) The Windows Vista Help directory seems to use 'h1s'
    files. What on
    earth is
    > this ? For sure Vista has nicely formatted Context
    Sensitive Help but how
    ? Is
    > this the new, much publicised MS Help format ?
    >
    > Basically, we need a sensible single file help system
    for the app and
    context
    > sensitive help with hyperlinks & formatting. Anybody
    have suggestions on
    what
    > the trend is here - is there even a single format
    solution for what must
    be a
    > common applications requirement ?
    >
    > Are Adobe planning their own Winhelp support now that MS
    have ditched it
    > Are MS planning a new Help System ?
    >
    > Thanks,
    > Iain.
    >
    >
    >

  • Need help in DECODE statement

    I have a scenario like
    if account no is 0001 or 0002 or 0003 then account_flag <> 'Y'
    ELSE IF account no is 00009 then account_status <> 'Y'
    How to write DECODE statement for this in Where part of select statement
    Note: account_flag and account_status are 2 different columns in same table

    Hi,
    I assumed you mean to update the values?
    You can use case for that:
    MHO%xe> select * from same_table;
    ACCOU A A
    0001  N N
    0002  N N
    0003  N N
    0004  N N
    0005  N N
    0006  N N
    0007  N N
    0008  N N
    0009  N N
    0010  N N
    10 rijen zijn geselecteerd.
    Verstreken: 00:00:01.90
    MHO%xe> update same_table
      2  set    account_flag  = case when account_no in ('0001', '0002', '0003')
      3                              then 'Y'
      4                              else account_flag
      5                         end
      6  ,      account_status = case when account_no = '0009'
      7                              then 'Y'
      8                              else account_status
      9                         end;
    10 rijen zijn bijgewerkt.
    Verstreken: 00:00:00.15
    MHO%xe> commit;
    Commit is voltooid.
    Verstreken: 00:00:00.09
    MHO%xe> select * from same_table;
    ACCOU A A
    0001  Y N
    0002  Y N
    0003  Y N
    0004  N N
    0005  N N
    0006  N N
    0007  N N
    0008  N N
    0009  N Y
    0010  N N
    10 rijen zijn geselecteerd.
    Verstreken: 00:00:00.07
    MHO%xe> desc same_table
    Naam                                      Null?    Type
    ACCOUNT_NO                                         VARCHAR2(5)
    ACCOUNT_FLAG                                       VARCHAR2(1)
    ACCOUNT_STATUS                                     VARCHAR2(1)

Maybe you are looking for

  • SAP J2EE Engine : does not work !!!

    Hi everyone, I have installed SAP NW2004s Java SP9 Trial (on Windows XP and Sapdb as database). The installation finished without problems. But when I start my SAP system, the SAP J2EE engine (process <b>jcontrol</b>) is still stopped [... I have alr

  • 7.0 bean - 6.1 bean

    Is there anything special I need to do to have a 7.0 CMP session bean call a 6.1 SP3 CMP session bean? Additionally, I'll need to go the other way too. I appreciate any help. Thanks. Dan

  • Delorie Search Engine Simulator returns redirect

    Hi all, Please can I just say a big thanks to all who continue to answer my frightfully ignorant questions. I have never yet failed to resolve a problem with the help of these forums and am eternally grateful. Now the problem... When I use the delori

  • WLC upgrade due to Advisory

    Hi, We have a 5508 WLC running 7.2.110.0 and need to upgrade according to the advisory released today. It seems we have three upgrade choices: 7.2.110.0 to 7.2.111.3 7.2.110.0 to 7.3.110.0 7.2.110.0 to 7.4.x I've not upgraded one of these 5508's befo

  • I need to ask a new question, but I need to include images for a better explanation, what source do you recommend?

    Hello everyone, I need to ask a new question, but i would like to do it more illustrative, showing some images, I am new on this forum and I would like to follow the best practices and standards on how to ask a "picture" question, is there a way i ca