Decode statement using nvl function

I have inherited some code that using a decode and nvl. I'm unsure the purpose of it and want confirmation that it is flawed logic and a mistake. The situation can be recreated by setting up the following.
CREATE TABLE XX_TEST
(ID NUMBER,
FIELD VARCHAR2(255)
INSERT INTO XX_TEST(ID,FIELD) VALUES (1,'Yes')
INSERT INTO XX_TEST(ID,FIELD) VALUES (2,'No')
INSERT INTO XX_TEST(ID,FIELD) VALUES (3,NULL)
commit
SELECT ID,
FIELD,
DECODE(FIELD,'Yes','Yes Result do this', NVL(FIELD,'No'),'No result do this','catch all result do this')
FROM XX_TEST
I'm unsure of the NVL(FIELD,'No') I think the creator maybe thought this would catch the nulls but it doesn't.
The values Null is not converted to No and instead drops into the catch all. Can anyone help with an explaination of of how oracle is interpretting the select statement. Any ideas on why NVL would be used like this? Seems a mistake?

Hi,
What about this -
SQL>
SQL>
SQL>
SQL> SELECT ID,
  2  FIELD,
  3  DECODE(nvl(FIELD,'No'),'Yes','Yes Result do this','No','No result do this','catch all result do this')
  4  FROM XX_TEST;
        ID FIELD                                              DECODE(NVL(FIELD,'NO'),'
         1 Yes                                                Yes Result do this
         2 No                                                 No result do this
         3                                                    No result do this
Elapsed: 00:00:00.00
SQL>
SQL>

Similar Messages

  • How to use NVL Function

    hi,
    i want to use nvl Function in that Quary
    select f_words(SUM(a.AMOUNT)+sum(a.vat_amount) +
    nvl( (select sum(b.LABOUR_AMT)+sum(b.service_tax_amt)
    from LAB_WORK_DTL b
    where a.bill_no =b.bill_no), 0)
    )) as t
    from TRANSACTION_DETAILS a
    where a.bill_no =:P42_bill_no
    group by a.BILL_NO;
    i am using NVL in that Quary Like This
    select f_words*(nvl(S*UM(a.AMOUNT)+sum(a.vat_amount) +
    nvl( (select sum(b.LABOUR_AMT)+sum(b.service_tax_amt)
    from LAB_WORK_DTL b
    where a.bill_no =b.bill_no), 0)
    )) as t
    from TRANSACTION_DETAILS a
    where a.bill_no =:P42_bill_no
    group by a.BILL_NO;
    I want to use NVL Function In BOLD
    How Can I use NVL Functiion.
    Thanks
    Edited by: Manoj Kaushik on Mar 25, 2010 5:55 AM

    hi,
    select f_wordsl(SUM(a.AMOUNT)+sum(a.vat_amount) +
    nvl( (select sum(b.LABOUR_AMT)+sum(b.service_tax_amt)
    from LAB_WORK_DTL b
    where a.bill_no =b.bill_no), 0)
    )) as t
    from TRANSACTION_DETAILS a
    where a.bill_no =:P42_bill_no
    group by a.BILL_NO;
    i have two tables Bill no is comman field in both tables if i have not enter value in any one of the table .
    so how can i show Total amount in words if Bill NO are not in any one table.
    Thanks

  • Compilation problems using NVL function in Pro*C subselect

    I have come across a weird oracle problem. When I execute the following query in SQLPlus it works but when
    I include it in Pro*C code in a EXEC SQL statement it gives syntax errors and fails to compile. Any idea what I am doing wrong.
    SELECT DISTINCT
         A.ID_PERSON,
         C.ID_STAGE_PERSON_LINK ,
         A.NM_PERSON_FULL,
         A.NBR_PERSON_AGE,
         A.ADDR_PERSON_ST_LN_1,
         A.ADDR_PERSON_CITY,
         A.ADDR_PERSON_ZIP,
         A.CD_PERSON_STATE,
         A.CD_PERSON_COUNTY,
         A.NBR_PERSON_PHONE,
         C.CD_STAGE_PERS_REL_INT
         FROM
              PERSON A,
              STAGE_PERSON_LINK C
         WHERE
         C.ID_CASE = 88776721
         AND          A.IND_INVALID_PERS IS NULL
         AND          C.CD_STAGE_PERS_TYPE = 'PRN'
         AND          C.ID_PERSON = A.ID_PERSON
         AND C.ID_STAGE_PERSON_LINK =
    NVL (
                   (SELECT MAX(F.ID_STAGE_PERSON_LINK)
                   FROM STAGE_PERSON_LINK F
                   WHERE F.ID_PERSON=C.ID_PERSON
                   AND F.ID_CASE = C.ID_CASE
                        AND F.CD_STAGE_PERS_TYPE = 'PRN'
                        AND F.CD_STAGE_PERS_REL_INT IS NOT NULL)
                   (SELECT MAX(G.ID_STAGE_PERSON_LINK)
                   FROM STAGE_PERSON_LINK G
                   WHERE G.ID_PERSON=C.ID_PERSON
                   AND G.ID_CASE = C.ID_CASE
                        AND G.CD_STAGE_PERS_TYPE = 'PRN')
    AND A.ID_PERSON NOT IN
    SELECT S.ID_PERSON
    FROM STAGE_PERSON_LINK S,STAGE T
    WHERE S.ID_CASE = C.ID_CASE
    AND S.ID_CASE = T.ID_CASE
    AND S.ID_STAGE = T.ID_STAGE
    AND T.CD_STAGE <> 'INT'
    MINUS
    SELECT H.ID_PERSON
    FROM STAGE_PERSON_LINK H, STAGE F
    WHERE H.ID_CASE = F.ID_CASE
    AND H.ID_STAGE = F.ID_STAGE
    AND H.ID_CASE = C.ID_CASE
    AND H.CD_STAGE_PERS_ROLE <> 'XE'
    AND F.CD_STAGE <> 'INT'
    This query returns data when run in sqlplus.When used in a Pro*C C program and compiled the precompiler complains with syntax errors when used with EXEC SQL DECLARE CLSS82D_CURSOR CURSOR FOR < query above >.However removing the NVL function and retaining the subselect clause compiles but that is not what I want to do.
    Syntax error at line 262, column 20, file clss82d.pc:
    Error at line 262, column 20 in file clss82d.pc
    SELECT MAX( F.ID_STAGE_PERSON_LINK )
    ...................1
    PCC-S-02201, Encountered the symbol "MAX" when expecting one of the following:
    ( ) * + - / . @ | at, day, hour, minute, month, second, year,
    The symbol "(" was substituted for "MAX" to continue.
    Syntax error at line 263, column 10, file clss82d.pc:
    Error at line 263, column 10 in file clss82d.pc
    FROM STAGE_PERSON_LINK F
    .........1
    PCC-S-02201, Encountered the symbol "FROM" when expecting one of the following:
    , ) * + - / | at, day, hour, minute, month, second, year,

    Pro*C works bit differently tha sqlplus. try removing the blank line after
    SELECT MAX(G.ID_STAGE_PERSON_LINK)
    FROM STAGE_PERSON_LINK G
    WHERE G.ID_PERSON=C.ID_PERSON
    AND G.ID_CASE = C.ID_CASE
    AND G.CD_STAGE_PERS_TYPE = 'PRN')
    good luck,
    Gauranga

  • Problem Using NVL Function

    I ran across a problem with the format of an ASCI output file of an SQL script. The problem I have is with handling a particular column that contains account numbers. The column is defined with 8 characters. However not every entry has data. I have several fields that don't have any information.
    Originally in my script I had the following line that made the script fail:
    LPAD(TO_CHAR(TO_NUMBER(konten_nr)),8,'0'),
    I then changed the line to the following: (The script ran but now I notice that the formatting is wrong)
    LPAD(TO_NUMBER(LTRIM(konten_nr)),8,'0'),
    I attempted to use the NVL function that will return a value when there is nothing in the column field but it doesn't work. Does anyone know what I'm doing wrong?
    LPAD(NVL(TO_CHAR(TO_NUMBER(konten_nr),'FM999999999'),'0'),8,'0'),

    what is exactly your problem ?
    you want to translater " 1234" in "00001234" ? then simply use to_char(konten_nr,'FM00000000') .
    You want to translate " 1 1 1 1" in "01010101", then use replace(konten_nr,' ','0')
    Give us some samples

  • Binding problem when using NVL function

    Hello.
    I have a problem with my ADF application (11.1.2.1).
    I use VO with a query (database view) - pivot table.
    If i use where clause like table.attr = :p_attr, everything works ok.
    If i use where clause like table.attr = NVL (:p_attr, table.attr) and put a value in :p_attr (executeWithParam) , query executes as if there is a null value.
    Debug console shows:
    Binding null of type 12 for "p_attr".
    Query with NVL works ok in sqldeveloper.
    But in jdev, as if the table attribute isn't bind to bind variable.
    If a just remove NVL function, it works.
    Any idea?
    Thanks.
    Regards
    Edited by: DejanH on Oct 6, 2011 1:32 PM

    Hello.
    I enter 50 in p_depart parameter and click "ExecuteWithParams". Query is executed and shows records (pivot table).
    But if i look at the log window i see that an empty query was executed first.
    <OracleSQLBuilderImpl> <bindParamValue> [427] Binding null of type 12 for "p_depart"
    <OracleSQLBuilderImpl> <bindParamValue> [428] Binding null of type 12 for "p_job"
    <OracleSQLBuilderImpl> <bindParamValue> [429] Binding null of type 12 for "p_hire_od"
    <OracleSQLBuilderImpl> <bindParamValue> [430] Binding null of type 12 for "p_hire_do"
    Then, it is autoexecuted for the second time with parameter set to the value i inserted.
    <OracleSQLBuilderImpl> <bindParamValue> [470] Binding param "p_depart": 50
    <OracleSQLBuilderImpl> <bindParamValue> [471] Binding null of type 12 for "p_job"
    <OracleSQLBuilderImpl> <bindParamValue> [472] Binding null of type 12 for "p_hire_od"
    <OracleSQLBuilderImpl> <bindParamValue> [473] Binding null of type 12 for "p_hire_do"
    The same happens in our query. But ours is much more complex and it takes a lot of time to first execute "empty" query and then with inserted parameter.
    We cannot use it.
    It looks like bug.
    Regards
    Edited by: DejanH on Oct 11, 2011 6:52 AM

  • How to use nvl() function in SQL Loader

    I am trying to use nvl() funtion in my SQL Loader control file and I keep geting errors. Would someone please tell me where I can find the syntax reference to this?
    Thanks a lot!

    I just answered a similar question like this last Thursday.
    SQL*LOADER how to load blanks when data is null

  • Using NVL function in Dynamic SQL

    Hi ,
    I have created a procedure using the Dynamic SqL and while using the NVL() getting the following error . ORA-00936: missing expression.
    The query I have written as
    SQL_Txt:=' INSERT INTO VF.tblCData (A, B, C, D, E, F,G,H,I,J)
         SELECT '||l_A||',
         '||l_B||',
         '||l_C||',
              '||l_D||',
              NULL ,
              '||L_F||',
              NVL('||Param1||',''''),
              NVL('||Param2||',''''),
              NVL('||Param3||',''''),
              NULL
              FROM '||ParamTbl1||' WHERE ' ;
    and so on.
    For Param1 I have data for one execution and Param2 and Param3 is null for that execution.
    While executing the same I am getting below
    INSERT INTO VF.tblCData (A, B, C, D, E, F,G,H,I,J)
    SELECT 25,
         1,
         7,
              6,
              NULL ,
              5,
              NVL(PurchaseDate,''),
              NVL(,''),
              NVL(,''),
              NULL
              FROM xyz.PBuyer@pocdb WHERE
    and error ORA-00936: missing expression is popping up for Param2 and Param3 NVL(,'')
    Any suggestion to resolve this issue is highly appreciable.
    Thanks
    Sudipta

    NVL(,''),Where's the first argument to NVL? That's the obvious problem. Empty strings are NULL in Oracle anyway, so just lose the NVL and insert the values...
    C:\>                                                                        
    C:\>sqlplus hr/hr                                                           
    SQL*Plus: Release 11.2.0.3.0 Production on Wed May 8 10:08:53 2013          
    Copyright (c) 1982, 2011, Oracle.  All rights reserved.                     
    Connected to:                                                               
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> set NULL I_AM_NULL                                                     
    SQL> create table x(y varchar2(20));                                        
    Table created.                                                              
    SQL> insert into x values ('');                                             
    1 row created.                                                              
    SQL> select * from x;                                                       
    Y                                                                           
    I_AM_NULL                                                                   
    SQL>                                                                        

  • Using NVL function in subselect of an update

    Hi,
    nvl is not working in my situation
    Here is my select
    SELECT nvl(a.id, 'WAS NULL') FROM table_1 a, table_2 b
    WHERE a.id=b.id;
    Now here I get NULL instead of 'WAS NULL' as I accepted.
    Table a and table b do not have any identical ids, still I need to be a value returned.
    Is there a way?
    Thanks

    Well this works for me:
    SQL> CREATE TABLE table_1 (id INT NOT NULL, val VARCHAR2(10) NOT NULL);
    Table created.
    SQL> CREATE TABLE table_2 (id INT NOT NULL, val VARCHAR2(10) NOT NULL);
    Table created.
    SQL> INSERT INTO table_1 VALUES (1, 'A');
    1 row created.
    SQL> INSERT INTO table_2 VALUES (2, 'B');
    1 row created.
    SQL> UPDATE table_1 t1
      2  SET    val =
      3         ( SELECT NVL(t2.val,'Was NULL') FROM table_2 t2
      4           WHERE  t2.id = t1.id );
    SET    val =
    ERROR at line 2:
    ORA-01407: cannot update ("WILLIAM"."TABLE_1"."VAL") to NULL
    SQL> UPDATE table_1 t1
      2  SET    val =
      3         NVL
      4         ( ( SELECT t2.val
      5             FROM   table_2 t2
      6             WHERE  t2.id = t1.id )
      7         , 'Was NULL');
    1 row updated.
    SQL> SELECT * FROM table_1;
            ID VAL
             1 Was NULL
    1 row selected.

  • NVL function's strange behaviour

    Hi,
    I have a sql statement (listed below) that uses NVL function which returns either the business name of branch name depending on whether the business name is null or not. It also uses the branch_name pl/sql function that returns the name of the branch.
    What I found strange was that it executes the branch_name function even when the business_name is not null. It was my understanding that nvl returns expr1 if it's not null, and expr2 if expr1 is null. I don't want it to execute the branch_name function if business_name exists. Is it possible using NVL, or do I need to use DECODE to achieve that? p_record_id is a parameter that I pass to the function containing the sql statement e.g., p_record_id=10.
    SELECT nvl( business_name, branch_name( p_record_id) ) "Name"
    FROM entity
    WHERE record_id = p_record_id;
    Thanks
    Vic

    Marc,
    Thanks for looking into it.
    I just ran the code using DECODE and it seems that it executes the function only when the condition is true, which is exactly what I want. It won't execute the function if the condition is false, e.g., in the code below if the business_name is null then it executes the branch_name function, other wise it returns the business_name.
    SELECT DECODE ( business_name,
    null, branch_name( p_record_id ),
    business_name ) "Name"
    FROM entity
    WHERE record_id = p_record_id;
    Vic

  • Difference between join conditions using NVL and not using NVL

    Hi,
    I have a join condition in one of the applications as follows.
    NVL(RQ.out_mesg_id,0) = NVL(RS.out_mesg_id,0)How is it different without using NVL function. What is the internal execution difference.
    RQ.out_mesg_id = RS.out_mesg_idWill there be any difference in Performance and also in the query output.
    Regards,
    Pabolu

    Pabolu wrote:
    Hi,
    I have a join condition in one of the applications as follows.
    NVL(RQ.out_mesg_id,0) = NVL(RS.out_mesg_id,0)How is it different without using NVL function. What is the internal execution difference.
    RQ.out_mesg_id = RS.out_mesg_idWill there be any difference in Performance and also in the query output.
    Regards,
    PaboluI suppose that's a bit of a trick question (or could be).
    If the column is allowed to be NULL, then your 2 queries are NOT equivalent, so comparing isn't useful since presumably you can only have one correct result :)
    However, if RQ and RS (no idea what the table names are) are both defined as having a NOT NULL constraint on the column out_mesg_id (ignoring the possibility of column level masking possible with the use of VPD here) then the optimizer could do better if you rewrote the query without the use of NVL (this would of course depend on your tables, indexes, etc ... i am merely showing you that it COULD make a difference).
    SQL> select * from v$version;
    BANNER                                                                         
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product               
    PL/SQL Release 10.2.0.1.0 - Production                                         
    CORE     10.2.0.1.0     Production                                                     
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production                        
    NLSRTL Version 10.2.0.1.0 - Production                                         
    SQL>
    SQL> create table t1 as
      2  select level as col1, case when mod(level, 10) = 0 then null else mod(level, 10) end as col2
      3  from dual connect by level <= 1000;
    Table created.
    SQL>
    SQL> alter table t1 add constraint t1_pk primary key (col1);
    Table altered.
    SQL>
    SQL> create index t1_i_001 on t1 (col2);
    Index created.
    SQL>
    SQL> exec dbms_stats.gather_table_stats(user, 'T1', cascade => true);
    PL/SQL procedure successfully completed.
    SQL>
    SQL> create table t2 as
      2  select level as col1, case when mod(level, 100) = 0 then null else mod(level, 100) end as col2
      3  from dual connect by level <= 1000;
    Table created.
    SQL>
    SQL> alter table t2 add constraint t2_pk primary key (col1);
    Table altered.
    SQL>
    SQL> create index t2_i_001 on t2 (col2);
    Index created.
    SQL>
    SQL> exec dbms_stats.gather_table_stats(user, 'T2', cascade => true);
    PL/SQL procedure successfully completed.
    SQL>
    SQL> --query using NVL
    SQL> explain plan for
      2  select count(*)
      3  from t1, t2
      4  where nvl(t1.col1, 0) = nvl(t2.col1, 0)
      5  /
    Explained.
    SQL>
    SQL> SELECT * FROM table(DBMS_XPLAN.DISPLAY);
    PLAN_TABLE_OUTPUT                                                              
    Plan hash value: 663667122                                                     
    | Id  | Operation              | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT       |       |     1 |     8 |     5  (20)| 00:00:01 |
    |   1 |  SORT AGGREGATE        |       |     1 |     8 |            |          |
    |*  2 |   HASH JOIN            |       |  1000 |  8000 |     5  (20)| 00:00:01 |
    |   3 |    INDEX FAST FULL SCAN| T1_PK |  1000 |  4000 |     2   (0)| 00:00:01 |
    |   4 |    INDEX FAST FULL SCAN| T2_PK |  1000 |  4000 |     2   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT                                                              
    Predicate Information (identified by operation id):                            
       2 - access(NVL("T1"."COL1",0)=NVL("T2"."COL1",0))                           
    16 rows selected.
    SQL>
    SQL> --verbose version of NVL
    SQL> explain plan for
      2  select count(*)
      3  from t1, t2
      4  where t1.col1 = t2.col1
      5  or ( (t1.col1 is null and t2.col1 = 0) or (t2.col1 is null and t1.col1 = 0) or (t1.col1 is null and t2.col1 is null) )
      6  /
    Explained.
    SQL>
    SQL> SELECT * FROM table(DBMS_XPLAN.DISPLAY);
    PLAN_TABLE_OUTPUT                                                              
    Plan hash value: 1043818223                                                    
    | Id  | Operation              | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT       |       |     1 |     8 |     2   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE        |       |     1 |     8 |            |          |
    |   2 |   NESTED LOOPS         |       |  1000 |  8000 |     2   (0)| 00:00:01 |
    |   3 |    INDEX FAST FULL SCAN| T1_PK |  1000 |  4000 |     2   (0)| 00:00:01 |
    |*  4 |    INDEX UNIQUE SCAN   | T2_PK |     1 |     4 |     0   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT                                                              
    Predicate Information (identified by operation id):                            
       4 - access("T1"."COL1"="T2"."COL1")                                         
    16 rows selected.So if we compare the 'verbose' version of the query, in the "predicate information" section of the explain you can see that the optimizer was able to completely ignore the
    or ( (t1.col1 is null and t2.col1 = 0) or (t2.col1 is null and t1.col1 = 0) or (t1.col1 is null and t2.col1 is null) ) condition since it knows that neither t1.col1 NOR t2.col1 columns can be null (by definition), and because of this we get a slightly different index access choice.

  • ORA-00917: missing comma when using NVL

    Hi All,
    I have a INSERT statement which works fine and looks something like:
    EXECUTE IMMEDIATE
    'insert into MYTABLE(ID,TASK_ROLE, PROGRESS,SALES_PERSON) values ...
    However if I change the above piece to use NVL function like this:
    EXECUTE IMMEDIATE
    'insert into MYTABLE(ID,TASK_ROLE, NVL(PROGRESS,''0''),SALES_PERSON) values ...
    I am getting the following error:
    ORA-00917: missing comma
    Where should I enter the extra comman needed?
    Regards,
    Pawel.

    Hi these are in fact two simple quotes '. If I use only one simple quote I get an error:
    1 error has occurred
    ORA-06550: line 48, column 239: PLS-00103: Encountered the symbol "0" when expecting one of the following: * & = - + ; < / > at in is mod remainder not rem return returning <> or != or ~= >= <= <> and or like LIKE2_ LIKE4_ LIKEC_ between into using || multiset bulk member SUBMULTISET_ The symbol "* was inserted before "0" to continue.
    Same thing happens if I ommit the quotes at all and leave it like NVL(PROGRESS,0)
    Edited by: padmocho on Sep 20, 2010 11:37 AM

  • NVL Function and Truncate Function in Template Builder

    Hi Guys,
    How would I use NVL function and Truncate function in the Word Template Builder.
    These functions do not work in the Query Builder when i use SQL Query as the Dataset while creating a report.
    I could not find examples in the Publisher Guide either.
    Thanks
    rkingmdu

    Hi
    How can you not use the functions in your query? Does the builder return an error? ow about just pasting your query into the report definition does the nvl/trunc work then ?
    Regards
    Tim
    http://blogs.oracle.com/xmlpublisher

  • To use Boolean function in DECODE or CASE statement

    Hi all
    I have a scenario where i need to use a boolean function inside DECODE statement. When i tried this way iam getting "ORA-06553: PLS-382: expression is of wrong type".
    I doubt whether i can use boolean function inside DECODE or not?
    My query will be like this:
    select decode(my_fuction( ),'TRUE',1,'FALSE',0) from dual;
    Any help is highly appreciated.
    Thanks
    Sriram

    Overloaded functions must differ by more than their
    return type . At the time that the overloaded
    function is called, the compiler doesn't know what type
    of data that function will return. The compiler cannot,
    therefore, determine which version of the function to
    use if all the parameters are the same.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • 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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • NULLIF Function converts to illegal DECODE Statement

    I am converting a SQLServer 2000 application to Oracle 8i (release 3) using release 9.2.0.1.7 of the Migration Workbench. I have 39 SQLServer stored procedures which utilize the NULLIF function. The Migration Workbench is converting the NULLIF into a DECODE statement which results in the following PL/SQL compilation error.
    Line: 59 Column: 40 Error: PLS-00204: function or pseudo-column 'DECODE' may be used inside a SQL statement only
    T-SQL line --> SET @VAL = LTRIM(RTRIM(NULLIF(@VAL,'')))
    PL/SQL line --> PROCNAME.VAL := LTRIM(RTRIM(DECODE(PROCNAME.VAL,'',NULL,PROCNAME.VAL)));
    Why is the workbench creating an illegal use of the DECODE function in the PL/SQL ? Is there another workaround or 'trick' that I could apply so I don't have to manually correct a lot of code ?

    Stephen,
    Bug logged: Bug3393406
    The workaround is to use select from dual:
    SELECT LTRIM(RTRIM(DECODE(PROCNAME.VAL,'',NULL,PROCNAME.VAL)))
    INTO PROCNAME.VAL FROM DUAL;
    This is automatically done if 'SELECT' is used in place of 'SET' in T-SQL.
    Turloch

Maybe you are looking for