Using 'DECODE'  instead of 'CASE' in select

Hi,
I am using CASE statements in my Select clause using 9i.
SELECT
                 CASE
                       WHEN S.cmpy_num = S.cpty_borg_num THEN
                       ''OURS''
                       ELSE
                       ''THEIRS''
                       END AS SDIOwner,
                       S.active_flag,
from SDI sI wud like to try this in 8I but 8i doesnt support CASE statements
in Select clauses.
It was recommended to use Decode in place of CASE in 8I
How can i write the decode statement for the above CASE statement in 9I

GOT IT RUNNIG.THANKS A LOT JAMES...
I AM TESTING SYSTEMS ON 9I AND 8I...

Similar Messages

  • Query to find out sum by using decode or case

    Hi, I have data like below and required an output as given below, could you please help me to get the same by using decode / case .....Thanks for your help
    INSNAME INSID STATUS
    AAA 1000 Scheduled
    AAA 1000 Processing
    BBB 1001 Inspector
    BBB 1001 Scheduled
    BBB 1001 Processing
    BBB 1001 Inspector
    CCC 1002 Scheduled
    CCC 1002 Processing
    CCC 1002 Inspector
    CCC 1002 Scheduled
    CCC 1002 Processing
    CCC 1002 Inspector
    Required Output...
    INSNAME INSID sum_of_scheduled sum_of_Processing sum_of_Inspector
    AAA 1000 1 1 0
    BBB 1001 1 1 2
    CCC 1002 2 2 2

    And if you want it with CASE statement:
    WITH test_table AS
       SELECT 'AAA' insname, 1000 insid, 'Scheduled'   status FROM DUAL UNION ALL
       SELECT 'AAA' insname, 1000 insid, 'Processing'  status FROM DUAL UNION ALL
       SELECT 'BBB' insname, 1001 insid, 'Inspector'   status FROM DUAL UNION ALL
       SELECT 'BBB' insname, 1001 insid, 'Scheduled'   status FROM DUAL UNION ALL
       SELECT 'BBB' insname, 1001 insid, 'Processing'  status FROM DUAL UNION ALL
       SELECT 'BBB' insname, 1001 insid, 'Inspector'   status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Scheduled'   status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Processing'  status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Inspector'   status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Scheduled'   status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Processing'  status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Inspector'   status FROM DUAL
    SELECT insname
          ,insid
          ,SUM(CASE WHEN status = 'Scheduled'
                    THEN 1
                    ELSE 0
                END
              ) sum_of_scheduled
          ,SUM(CASE WHEN status = 'Processing'
                    THEN 1
                    ELSE 0
                END
              ) sum_of_processing
          ,SUM(CASE WHEN status = 'Inspector'
                    THEN 1
                    ELSE 0
                END
              ) sum_of_inspector         
      FROM test_table
    GROUP BY insname
            ,insid;
    Regards
    Arun

  • Problem using Decode/Case

    I have one table which stores candidates' response. The structure is like this
    (Seatno, Questionnumber, Answer).
    And I have another table Master as (Questionnumber, Answer)
    Now I want to calculate marks by comparing Candidate's response with Master.
    I tried to use decode and case. But was not successful.
    My query with decode was ...
    select c1.candidatesrno, sum(decode(c1.answer,(c1.answer=m1.answer),1,0))
    from candidate c1,master q1
    where c1.question=m1.question
    group by c1.candidatesrno
    And query with CASE was...
    select c1.candidatesrno,
    case when (c1.answer=m1.answer) then 1 else 0
    end resultset
    from candidate c1,master m1
    where c1.questionnumber=m1.questionnumber
    group by c1.candidatesrno
    Can anybody help ?

    I want to compare candidate's response with master
    table.
    Now for each question of Candidate, if its answer
    matches with answer in Master table I have to give 1
    marks...if it does not match I have to give 0
    marks...like this there are two-three conditions...
    Something like this ?
    test@ORA10G>
    test@ORA10G> with master as (
      2    select 'Q1' as question_num, 'A1' as answer_num from dual union all
      3    select 'Q2', 'A2' from dual union all
      4    select 'Q3', 'A3' from dual),
      5  candidate_response as (
      6    select 'S1' as seat_num, 'Q1' as question_num, 'A1' as answer_num from dual union all
      7    select 'S1', 'Q2', 'A2' from dual union all
      8    select 'S1', 'Q3', 'A3' from dual union all
      9    select 'S2', 'Q1', 'A5' from dual union all
    10    select 'S2', 'Q2', 'A6' from dual union all
    11    select 'S2', 'Q3', 'A3' from dual)
    12  --
    13  select
    14    cr.seat_num,
    15    cr.question_num,
    16    cr.answer_num,
    17    case when m.question_num is null and m.answer_num is null then '0 point'
    18         else '1 point'
    19    end as points
    20  from candidate_response cr, master m
    21  where cr.question_num = m.question_num(+)
    22  and cr.answer_num = m.answer_num(+)
    23  order by cr.seat_num, cr.question_num, cr.answer_num;
    SE QU AN POINTS
    S1 Q1 A1 1 point
    S1 Q2 A2 1 point
    S1 Q3 A3 1 point
    S2 Q1 A5 0 point
    S2 Q2 A6 0 point
    S2 Q3 A3 1 point
    6 rows selected.
    test@ORA10G>
    test@ORA10G> with master as (
      2    select 'Q1' as question_num, 'A1' as answer_num from dual union all
      3    select 'Q2', 'A2' from dual union all
      4    select 'Q3', 'A3' from dual),
      5  candidate_response as (
      6    select 'S1' as seat_num, 'Q1' as question_num, 'A1' as answer_num from dual union all
      7    select 'S1', 'Q2', 'A2' from dual union all
      8    select 'S1', 'Q3', 'A3' from dual union all
      9    select 'S2', 'Q1', 'A5' from dual union all
    10    select 'S2', 'Q2', 'A6' from dual union all
    11    select 'S2', 'Q3', 'A3' from dual)
    12  --
    13  select cr.seat_num, count(*) as score
    14  from candidate_response cr, master m
    15  where cr.question_num = m.question_num
    16  and cr.answer_num = m.answer_num
    17  group by cr.seat_num
    18  order by cr.seat_num;
    SE      SCORE
    S1          3
    S2          1
    test@ORA10G>
    test@ORA10G>pratz

  • Why we use Tables statement in case of using SELECT-OPTIONS:

    hi all,
    Why we use Tables statement in case of using the following coding in an ABAP program ...
    tables: vbak.
    SELECT-OPTIONS: s1 for vbak-vbeln.
    here if we dont provide the tables statement why it does not work ????
    pls answwer ....???

    Hi
    This statement is not allowed in classes and declares a data object table_wa as a table work area whose data type is adopted from the identically named structured data type table_wa from the ABAP Dictionary. table_wa must be defined as a flat structure in the ABAP Dictionary. You can specify database tables or Views for table_wa.
    Work table areas declared with TABLES are interface work areas and should only be declared in the global declaration section of a program for the following purpose:
    reward if usefull
    The statement TABLES is required for exchanging data between screen fields that were defined in a program screen when transferring from the ABAP Dictionary and the ABAP program. For the screen event PBO, the content of the table work area is transferred to identically named screen fields; for PAI, the system adopts the data from identically named screen fields.
    In executable programs, flat table work areas can be used for adopting data that were provided for the event GET table_wa from a linked logical database. TABLES is synonymous with the statement NODES for this purpose.
    Work table areas declared with TABLES behave like the data declared with the addition COMMON PART, meaning the data are used by the programs of a program group.
    Table work areas declared with TABLES can be declared in subroutines and
    function modules. However, this is not recommended. A table work area declared in a procedure is not local but belongs to the context of a framework program. The table work area can be viewed starting from the declaration in the framework program and lives as long as the framework program. In contrast to normal program-global data, the content of the table work areas declared in subroutines and function modules is stored temporarily when these subroutines and function modules are called. Value assignments that were made during runtime of the procedure are preserved until the procedure is completed. When exiting the procedure, the table work areas are filled with the contents that they contained when the procedure was called. Table work areas declared in procedures behave like global data to which the statement LOCAL is applied in the procedure.
    The form TABLES * is obsolete.

  • Problem using CASE within SELECT in a standard REPORT region

    I'm trying to do a CASE-oriented SELECT within a standard REPORT region and the parser is rejecting the SQL statement.
    The code I'm using is the following:
    SELECT
    CASE
    WHEN INSTR(citation, '@') > 0 THEN
    SUBSTR(citation, 1, INSTR(citation, '@')-1)
    || ':'
    || SUBSTR(citation, INSTR(citation, '@')+1,
    LENGTH(citation) - INSTR(citation, '@'))
    ELSE citation
    END
    FROM citation
    WHERE obj_table_cd = 'FI'
    AND obj_id = :P41_FIND_ID
    ORDER BY CITATION
    The parser says the (case .... ) is invalid, use column alias. The query works correctly when using SQL_Developer and SQL*PLUS.
    My intention is to replace an '@' with ':' within the citation text. The standard citation format should have a colon, but this causes problems with AppExpress, hence the substitution situation.
    Any insights on this or on another way to achieve the purpose?
    Thanks,
    George

    George,
    You should give a column alias after the END of the case statement:
    SELECT
    CASE
    WHEN INSTR(citation, '@') > 0 THEN
    SUBSTR(citation, 1, INSTR(citation, '@')-1)
    || ':'
    || SUBSTR(citation, INSTR(citation, '@')+1,
    LENGTH(citation) - INSTR(citation, '@'))
    ELSE citation
    END citation_col
    FROM citation
    WHERE obj_table_cd = 'FI'
    AND obj_id = :P41_FIND_ID
    ORDER BY CITATIONSam

  • Using decode function without negative values

    Hi friends
    I am using oracle 11g
    I have at doubt regarding the following.
    create table Device(Did char(20),Dname char(20),Datetime char(40),Val char(20));
    insert into Device values('1','ABC','06/13/2012 18:00','400');
    insert into Device values('1','abc','06/13/2012 18:05','600');
    insert into Device values('1','abc','06/13/2012 18:55','600');
    insert into Device values('1','abc','06/13/2012 19:00','-32768');
    insert into Device values('1','abc','06/13/2012 19:05','800');
    insert into Device values('1','abc','06/13/2012 19:10','600');
    insert into Device values('1','abc','06/13/2012 19:15','900');
    insert into Device values('1','abc','06/13/2012 19:55','1100');
    insert into Device values('1','abc','06/13/2012 20:00','-32768');
    insert into Device values('1','abc','06/13/2012 20:05','-32768');
    Like this I am inserting data into table for every 5 minutes Here i need the result like
    output:
    Dname 18:00 19:00 20:00
    abc 400 -32768 -32768
    to retrieve this result i am using decode function
    SELECT Dname,
    MAX(DECODE ( rn , 1,val )) h1,
    MAX(DECODE ( rn , 2, val )) h2,
    FROM
    (SELECT Dname,Datetime,row_number() OVER
    (partition by Dname order by datetime asc) rn FROM Device
    where substr(datetime,15,2)='00' group by Dname.
    According to above data expected result is
    Dname 18:00 19:00 20:00
    abc 400 600(or)800 1100
    This means I dont want to display negative values instead of that values i want to show previous or next value.
    Edited by: 913672 on Jul 2, 2012 3:44 AM

    Are you looking for something like this?
    select * from
    select dname,
           datetime,
           val,
           lag(val) over (partition by upper(dname) order by datetime) prev_val,
           lead(val) over (partition by upper(dname) order by datetime) next_val,
           case when nvl(val,0)<0  and lag(val) over (partition by upper(dname) order by datetime) >0 then
             lag(val) over (partition by upper(dname) order by datetime)
           else 
             lead(val) over (partition by upper(dname) order by datetime)
           end gt0_val
    from device
    order by datetime
    where substr(datetime,15,2)='00';Please take a look at the result_column gt0_val.
    Edited by: hm on 02.07.2012 04:06

  • CASE in SELECT statement

    Hello,
    in Oracle8 I've the following problem:
    The statement
    SELECT ''' | ''||' || 'rpad'
    || '(''' || column_name
    || ''',' ||
    (CASE WHEN (data_type = 'VARCHAR2' AND
    data_length > 50) THEN
    to_number('50')
    WHEN (data_type = 'CHAR' AND
    data_length > 50) THEN
    to_number('50')
    WHEN (data_type = 'CLOB' AND
    data_length > 50) THEN
    to_number('50')
    WHEN (data_type = 'DATE' AND
    data_length != 19) THEN
    to_number('19')
    ELSE
    data_length
    END )
    || ', '' '')||' AS column_name
    FROM dba_tab_columns
    WHERE
    table_name = upper('DBA_TABLES') AND
    owner = upper('SYS')
    ORDER BY column_id;
    works fine but defining the same statement as a cursor in a PL/SQL Procedure, I got a
    Error: PLS-00103: Encountered the symbol "CASE" when expecting one of the following:
    ( - + mod 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 time timestamp interval date
    <a string literal with character set specification>
    <a number> <a single-quoted SQL string>
    The same procedure can be compiled in Oracle9i without errors.
    Does anybody know if there are any restrictions using CASE statements in a PL/SQL CURSOR in Oracle8?
    Thanks
    Patric

    Hi,
    I am encountering the same problem.
    Can u suggest the decode statement used instead of case
    for this select clause which uses the CASE statement ?
    SELECT
                           CASE
                           WHEN S.cmpy_num = S.cpty_borg_num THEN
                           ''OURS''
                           ELSE
                           ''THEIRS''
                           END AS SDIOwner,
    From TABLE

  • How to use decode on the value part ?

    i have a query
    select
         col1, col2, col3
    from
         tab1, tab2
    where
         cond1= 'parameter1'     
    I need to modify this query to use a decode function instead of this parameter1.
    something like
    select
         col1, col2, col3
    from
         tab1, tab2
    where
         cond1= decode(parameter1, 'x','val1','val2')
    How can i use such a decode function on the value part ?
    IF i try this, it gives me no data found error....
    The following is also not working..IS there a way to do such cases ?
    select
         col1, col2, col3
    from
         tab1, tab2
    where
         cond1= ( select decode(parameter1, 'x','val1','val2') from dual )

    Of course it works...
    test@ORA10G>
    test@ORA10G> drop table table1;
    Table dropped.
    test@ORA10G> create table table1 (
      2    name        varchar2(50),
      3    condition1  varchar2(2),
      4    condition2  varchar2(10)
      5  );
    Table created.
    test@ORA10G> insert into table1 (name,condition1,condition2)
      2  values ('Hi there!!','xx','VAL1');
    1 row created.
    test@ORA10G> commit;
    Commit complete.
    test@ORA10G>
    test@ORA10G> select * from table1;
    NAME                           CO CONDITION2
    Hi there!!                     xx VAL1
    1 row selected.
    test@ORA10G>
    test@ORA10G> declare
      2    CodeL varchar2(3) := 'AB';
      3    CodeName varchar2(50) := '';
      4  begin
      5    select decode(CodeL,'AB','VAL1', CodeL)
      6    into CodeName
      7    from dual;
      8    dbms_output.put_line('CodeName: '||CodeName);
      9    select Name
    10    into CodeName
    11    from table1
    12    where condition1='xx'
    13    and condition2 in ( select decode(CodeL,'AB','VAL1', CodeL) from dual );
    14    dbms_output.put_line('CodeName: '||CodeName);
    15  end;
    16  /
    CodeName: VAL1
    CodeName: Hi there!!
    PL/SQL procedure successfully completed.
    test@ORA10G>pratz

  • How to use Decode Function in Webi / Designer - BOE XI 3.1

    Hi All,
    I have a SQL query which needs to include in the webi report.
    Below is the query :
    SELECT
    SECURITY.SEC_CUSIP_NO "CUSIP", 
    SECURITY.STY_SEC_TY_CD "SECURITY TYPE",
    SECURITY.SEC_DERIVED_DESC_TX "SECURITY DESCRIPTION",
      SECURITY.sec_dep_teleg_de "FED DESCRIPTION",
      SEC_STND_PR "STANDARD/FACTORED PRICE",
      SEC_STND_PR_EFF_DT "STANDARD/FACTORED PRICE Date",
      SECURITY.SEC_YIELD_PR "YIELD PRICE",
      SECURITY.SEC_YIELD_PR_DT "YIELD RICE EFFECTIVE DATE",
      STND_PR_VND_VENDOR_CD "PRICE SOURCE",
      SEC_MATURITY_DT "MATURITY DATE",
      SEC_ISSUE_DT "ISSUE DATE",
                 CASE WHEN SECURITY.STY_SEC_TY_CD IN ('BA','CD','CDD','CDE','CDM','CDV','CP','CPD') THEN
                    (position.PSN_AVAIL_PAR_VL + position.PSN_COLLAT_PAR_VL) * (SECURITY.SEC_STND_PR) / 100
                 ELSE
                    (position.PSN_AVAIL_PAR_VL + position.PSN_COLLAT_PAR_VL) * (  (  SECURITY.SEC_YIELD_PR * DECODE (SECURITY.SEC_PRIN_FT, 0, 1, SECURITY.SEC_PRIN_FT))) / 100
                    * DECODE(SECURITY.STY_SEC_TY_CD, 'AMP', DECODE(NVL(SECURITY.SEC_MULTIPLIER_UNIT_VL,0), 0, 1, SECURITY.SEC_MULTIPLIER_UNIT_VL), 'MMP', DECODE(NVL(SECURITY.SEC_MULTIPLIER_UNIT_VL,0), 0, 1, SECURITY.SEC_MULTIPLIER_UNIT_VL), 'AMPT', DECODE(NVL(SECURITY.SEC_MULTIPLIER_UNIT_VL,0), 0, 1, SECURITY.SEC_MULTIPLIER_UNIT_VL), 1 )
                 END
            ) "MARKET VALUE"
    FROM SECURITY SECURITY
       ,   position position
    WHERE STND_PR_VND_VENDOR_CD = 'VT'
    AND SEC_MATURITY_DT > SYSDATE-1
    and SECURITY.sec_sys_id=position.sec_sys_id
    I could create a report which has selected objects and defined where condition from the above query. I have also created a variable for 'when' & 'then' condition but stuck at else part which contains 'DECODE' function.
    Please suggestions how to write the same at the report or designer level.
    Thanks,
    Rameez Shaikh

    Hi Rameez,
    Looking at the query you can create the object directly in the universe, either create two objects one for inner decode and use it in outer case logic. In report it is nothing but nested if logic. For eg.  If(a=b;1;(if(a=c;2;3))
    Thanks
    Gaurav

  • Use of insert in case

    Hi,
    Is it possible to use insert statement in CASE.
    For example as follows:
    let create a table as
    create table DECOMPENSATED_BALANCE_TMP (ENDING_ENTERED_BALANCE_DR number, ENDING_ENTERED_BALANCE_CR number);
    select
    CASE
    WHEN (PERIOD_NET_DR+BEGIN_BALANCE_DR-PERIOD_NET_CR-BEGIN_BALANCE_CR) total > 0
    THEN
    INSERT INTO XXGL_DECOMPENSATED_BALANCE_TMP (ENDING_ENTERED_BALANCE_DR) values (total)
    WHEN (PERIOD_NET_DR+BEGIN_BALANCE_DR-PERIOD_NET_CR-BEGIN_BALANCE_CR) <= 0
    THEN
    INSERT INTO XXGL_DECOMPENSATED_BALANCE_TMP (ENDING_ENTERED_BALANCE_CR) values (total)
    else
    NULL
    end
    from gl_balances
    where code_combination_id=109940 and currency_code='GBP';
    Any answers will be highly appreciated ....
    Thanks,
    zaheer

    I don't think that a conditional insert is really needed in this case. THe only part where the insert differse is the else part of your case statment where no insert should be done. THis can be made into a where clause.
    An easy way would be to use a simple INSERT + SELECT statement. Where the value for the dr and cr columns are created by a case or a decode statement.
    untested example
    insert into XXGL_DECOMPENSATED_BALANCE_TMP
      (ENDING_ENTERED_BALANCE_DR, ENDING_ENTERED_BALANCE_CR)
    select case WHEN (PERIOD_NET_DR+BEGIN_BALANCE_DR-PERIOD_NET_CR-BEGIN_BALANCE_CR) > 0  then total
              else null
              end as DR
             ,case WHEN (PERIOD_NET_DR+BEGIN_BALANCE_DR-PERIOD_NET_CR-BEGIN_BALANCE_CR) <= 0  then total
              else null
              end as CR
    from gl_balances
    where code_combination_id=109940
    and currency_code='GBP'
    and (PERIOD_NET_DR+BEGIN_BALANCE_DR-PERIOD_NET_CR-BEGIN_BALANCE_CR) is not null -- else part
    ;The good thing is you could run this insert statement for several code_combination_ids directly in SQL without any pL-loop.
    Just noticed that leonard aready posted almost the same solution.
    Edited by: Sven W. on Aug 24, 2011 3:22 PM

  • How to use DECODE function in Exspression?

    Hi,
    Can we use DECODE in Expression?
    I'm trying to use DECODE function but there is an error during the validation. But when i validate the mapping, it is successfully compiled but it is failed during deployment.
    But if I use CASE instead of DECODE, it works fine.
    Can we use DECODE in OWB???
    Thanks
    Raj

    Hi,
    In OWB 10gR2, if your are using only one DECODE in an expression, it's working. The package will compile when deploying the mapping. OWB will replace the DECODE by a CASE.
    But when you are using nested decode in an expression ( for example : decode(col1, 1, 'M', decode(col2, 'Madame', 'Mme', null)) ) only the first one is replaced by a case at deployment.
    In ROW_BASED mode, text of the expression is used outside of an sql statement and deployment will fails with "PLS-00204: function or pseudo-column 'DECODE' may be used inside a SQL statement only."
    If operating mode for the mapping is set to SET_BASED, it's working because the expression is used in an sql statement.
    I have logged a SR in metalink for this issue and a bug is opened (bug 5414112).
    But I agree with you, it's better to use case statement.
    Bernard

  • Problem in using aggregate functions inside case statement

    Hi All,
    I am facing problem while using aggregate functions inside case statement.
    CASE WHEN PSTYPE='S' THEN MAX(DECODE(POS.PBS,1,ABS(POS.PPRTQ),0)) ELSE SUM(DECODE(POS.PBS,1,ABS(POS.PPRTQ),0)) END,
    how can I achieve above requirement ? Con anyone help me.
    Thanks and Regards
    DG

    Hi All,
    Below is my query:
            SELECT
            CASE WHEN p_reportid IN ('POS_RV_SN','POS_PB') THEN POS.PACCT
            ELSE POS.PACCT || '-' || DECODE(POS.SYSTEMCODE,'GMI1','1', 'GMI2','2', 'GMI3','4', 'GMI4','3', '0') ||POS.PFIRM|| NVL(POS.POFFIC,'000') END,
            CASE WHEN p_reportid IN ('POS_RV_SN','POS_PB') THEN POS.PACCT||POS.PCUSIP||DECODE(POS.PBS,1,'+',2,'-')
            ELSE POS.PFIRM||POS.POFFIC||POS.PACCT||POS.PCUSIP||DECODE(POS.PBS,1,'+',2,'-') END,POS.SYSTEMCODE,CASE WHEN POS.PSTYPE='S' THEN POS.PSYMBL ELSE POS.PFC END,POS.PEXCH||DECODE(POS.PSUBEX,'<NULL>',''),
            POS.PCURSY,
            CASE WHEN POS.PSBCUS IS NULL THEN SUBSTR(POS.PCTYM,5,2) || SUBSTR(POS.PCTYM,1,4) ELSE POS.PSBCUS || SUBSTR(POS.PCTYM,5,2) || SUBSTR(POS.PCTYM,1,4) END ,
            NVL(POS.PSUBTY,'F') ,POS.PSTRIK,*SUM(DECODE(POS.PBS,1,ABS(POS.PPRTQ),0)) ,SUM(DECODE(POS.PBS,2,ABS(POS.PPRTQ),0))* ,
            POS.PCLOSE,SUM(POS.PMKVAL) ,
            TO_CHAR(CASE WHEN INSTR(POS.PUNDCP,'.') > 0 OR LENGTH(POS.PUNDCP) < 15 THEN POS.PUNDCP ELSE TO_CHAR(TO_NUMBER(POS.PUNDCP) / 100000000) END),
            POS.UBS_ID,POS.BBG_EXCHANGE_CODE,POS.BBG_TICKER ,POS.BBG_YELLOW_KEY,POS.PPCNTY,POS.PMULTF,TO_CHAR(POS.BUSINESS_DATE,'YYYYMMDD'),
            POS.SOURCE_GMI_LIB,
            --DECODE(POS.SYSTEMCODE,'GMI1','euro','GMI2','namr','GMI3','aust','GMI4','asia','POWERBASE','aust','SINACOR','namr',POS.SYSTEMCODE),
            DECODE(p_reportid,'RVPOS_SING','euro','RVPOS_AUSTDOM','aust','RVPOS_AUSTEOD','euro','RVPOS_GLBLAPAC','asia','POS_RV_SN','namr','POS_PB','aust',POS.SYSTEMCODE),
            POS.RIC,
            CASE WHEN PSUBTY = 'S' THEN POS.TYPE ELSE NULL END,
            DECODE(POS.UBS_ID,NULL,POS.PCUSP2,POS.ISIN),POS.UNDERLYING_BBG_TICKER,POS.UNDERLYING_BBG_EXCHANGE,POS.PRODUCT_CLASSIFICATION,
            CASE WHEN PSUBTY = 'S' THEN POS.PSDSC2 ELSE NULL END,
            CASE WHEN PSUBTY = 'S' THEN C.SSDSC3 ELSE NULL END,
            NVL(C.SSECID,POS.PCUSIP),
            NULL,
            POS.PYSTMV,
            POS.PMINIT,
            POS.PEXPDT,
            CASE WHEN POS.PSUBTY='S' THEN  SUBSTR(C.ZDATA2,77,1) ELSE NULL END,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL,
            NULL
            FROM POSITIONS_WRK POS LEFT OUTER JOIN
            (SELECT * FROM CDS_PRODUCTS CP INNER JOIN FUTURE_MASTER FM ON
            (CP.STRXCH=FM.ZEXCH AND CP.SFC=FM.ZFC AND CP.BUSINESS_DATE = FM.BUSINESS_DATE )) C ON POS.PCUSIP = C.SCUSIP
            AND NVL(POS.PCUSP2,'X') = NVL(C.SCUSP2,'X')
            WHERE
            POS.PEXCH NOT IN ('A1','A2','A3','B1','B3','C2','D1','H1','K1','L1','M1','M3','P1','S1')
            AND (POS.PSBCUS IS NOT NULL OR POS.PCTYM IS NOT NULL OR POS.PSTYPE ='S')
            AND POS.BUSINESS_DATE = run_date_char
            GROUP BY
            POS.UBS_ID,POS.SYSTEMCODE,POS.RECIPIENTCODE,POS.BUSINESS_DATE,POS.PACCT,POS.PFIRM,POS.POFFIC,POS.PCUSIP,POS.PBS,CASE WHEN POS.PSTYPE='S' THEN POS.PSYMBL ELSE POS.PFC END,
            POS.PEXCH,POS.PSUBEX,POS.PCURSY,
            CASE WHEN POS.PSBCUS IS NULL THEN SUBSTR(POS.PCTYM,5,2) || SUBSTR(POS.PCTYM,1,4) ELSE POS.PSBCUS || SUBSTR(POS.PCTYM,5,2)  || SUBSTR(POS.PCTYM,1,4) END,
            NVL(POS.PSUBTY,'F') ,POS.PSTRIK,POS.PCLOSE,TO_CHAR(CASE WHEN INSTR(POS.PUNDCP,'.') > 0 OR LENGTH(POS.PUNDCP) < 15 THEN POS.PUNDCP ELSE TO_CHAR(TO_NUMBER(POS.PUNDCP) / 100000000) END),
            POS.BBG_EXCHANGE_CODE,POS.BBG_TICKER,POS.BBG_YELLOW_KEY,POS.PPCNTY,POS.PMULTF,POS.PSUBTY,POS.SOURCE_GMI_LIB,RIC,
            CASE WHEN PSUBTY = 'S' THEN POS.TYPE ELSE NULL END,
            DECODE(POS.UBS_ID,NULL,POS.PCUSP2,POS.ISIN),POS.UNDERLYING_BBG_TICKER,POS.UNDERLYING_BBG_EXCHANGE,POS.PRODUCT_CLASSIFICATION,
            CASE WHEN PSUBTY = 'S' THEN POS.PSDSC2 ELSE NULL END,
            CASE WHEN PSUBTY = 'S' THEN C.SSDSC3 ELSE NULL END,
            NVL(C.SSECID,POS.PCUSIP),
            POS.PYSTMV,
            POS.PMINIT,
            POS.PEXPDT,
            CASE WHEN PSUBTY = 'S'  THEN  SUBSTR(C.ZDATA2,77,1) ELSE NULL END;Now, could you plz help me in replacing the bold text in the query with the requirement.
    Thanks and Rgds
    DG
    Edited by: BluShadow on 16-May-2011 09:39
    added {noformat}{noformat} tags.  Please read: {message:id=9360002} for details on how to post code/data                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to Use Decode for manipulating time

    How can i use Decode function to manipulate time...
    Example
    suppose ive employee and his time in...i want to display status field by using decode,which reflects if that employee came after 09:15:00 the status='L' else this will print 'P'
    i tried this
    SELECT pin_code,DECODE( to_char(ACCESS_TIME,'HH24:MI:SS'>'09:15:00','l','P'))STATUS
    FROM ATTENDANCE_REG
    this query hasn't work...
    waiting for reply
    Regards
    Danish Hayder

    SQL> select case when to_number(to_char(sysdate,'sssss')) > 33300 then 'L'
      2              else 'P' end status
      3  from dual;
    S
    L
    1 row selected.                                                                                                                                                                                                                                                                                                                                           

  • Can I use decode( decode...)...)

    Hi,
    Can I use decode function inside decode function.
    It seem doesn't work. Please help
    decode(lv.RANK||' / '||
    decode('('||lv.ONE_YR_PCT||'%)', '(%)','N/A','('||lv.ONE_YR_PCT||'%)'),
    '0 / (0%)','N/A', lv.RANK )
    Thanks

    I'm not quite sure it's the result you intended but your nested decode statement does run ...
    SQL> CREATE TABLE lv (rank number, one_yr_pct number)
      2  /
    Table created.
    SQL> insert into lv values (1, 1)
      2  /
    1 row created.
    SQL> insert into lv values (2,2)
      2  /
    1 row created.
    SQL> insert into lv values (0,0)
      2  /
    1 row created.
    SQL> select decode(lv.RANK||' / '||
      2  decode('('||lv.ONE_YR_PCT||'%)', '(%)','N/A','('||lv.ONE_YR_PCT||'%)'),
      3  '0 / (0%)','N/A', lv.RANK )
      4  from lv
      5  /
    DECODE(LV.RANK||'/'||DECODE('('||LV.ONE_
    1
    2
    N/A
    SQL> If you're having problems maybe you should cut'n'paste the output from your SQL*Plus session so we can see what's happening.
    Alternatively, as CD suggests, you may find it easier to express your logic using CASE.
    Cheers, APC

  • Basic query using DECODE not working as expected.

    Version:11.2.0.3
    Platform: RHEL 5.8
    I am trying to use DECODE function.
    In the below example, If the search encounters the string "Enterprise" , then the decode should
    return 'Enterprise' . But it doesn't seem to work.
    I thought some hidden character was causing the issue, so, I used TRIM. But no luck.
    SQL> create table t (banner varchar2(80));
    Table created.
    SQL> insert into t values ('Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from t;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    SQL> select * from t where banner like '%Database%';
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    -- Trying to use decode. If the search encounters the string "Enterprise" , then return 'Enterprise'
    -- Although the string "Enterprise" is present ,  decode doesn't seem to work.
    -- I tried using trim , upper . But no luck.
    SQL> select 'EDITION', decode(banner,'%Enterprise%','Enterprise','Standard') Edition from t where banner like '%Database%';
    'EDITIO EDITION
    EDITION Standard
    SQL> select 'EDITION', decode(trim(banner), '%Enterprise%','Enterprise','Standard') Edition from t where trim(banner) like '%Database%';
    'EDITIO EDITION
    EDITION Standard
    SQL> select 'EDITION', decode(upper(trim(banner)), '%ENTERPRISE%','Enterprise','Standard') Edition from t where upper(trim(banner)) like '%DATABASE%';
    'EDITIO EDITION
    EDITION Standard
    SQL>
    Just don't understand why decode can't see the string "Enterprise"
    BTW . Where is the preview button ?

    It (a portion string matching) ain't work in DECODE, for this CASE has a advantage of using over it.
    Like
    with t
    as
    (select 'Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production' banner from dual)
    select 'EDITION',
    case when banner like '%Enterprise%' then 'Enterprise' else 'Standard' end edition
    from t
    'EDITIO EDITION
    EDITION Enterprise

Maybe you are looking for

  • Memory Slots on 15" Powerbook?

    I have a 15" Powerbook (1.25 mhz). According to the System Profiler there are 2 256 of ram sticks for a total of 512 mb of ram. Are there two available slots on this machine so if I want to upgrade the memory I'd have to take out one of the ram stick

  • Msi k9n2gm-fd no sound

    Hi. I had sound until my realtek ethernet card went dead so i used the onboard ethernet.. now i have no sound from onboard sound card need help thnx

  • CUCI Lync issue "Calls cannot be placed at this time"

    Hello! Could you please assist with the folowing? Quite a time ago the CUCI Lync accounts were configured and working fine. I haven't touched their configuration at all since then. So now I 've got the need to use these accounts and met the error "Ca

  • The paint bucket tool and patterns in Photoshop CC have stopped working, how to fix?

    Suddenly the paint bucket is not filling, and patterns are not filling either with bucket or fx on layer. I tried resetting patterns to default, but that did not help. I restarted my computer, no help, either. Any suggestions? thanks!

  • DCNM 6.1.1a and Nexus 5020

    Hi all, I've got a problem that I am not able to figure out. I've got 2 nexus 5020 running Software   system:    version 5.0(2)N2(1)   system image file is:    bootflash:/n5000-uk9.5.0.2.N2.1.bin Hardware   cisco Nexus5020 Chassis ("40x10GE/Superviso