Decode statement syntax?

I want decode a column value based on the flag condition value in other column
example: Select DECODE (UPPER (VPA.Secondary_other), 'TRUE', VPA.Secondary_Other_Response) from Table

Hi,
francislazaro wrote:
I want decode a column value based on the flag condition value in other column
example: Select DECODE (UPPER (VPA.Secondary_other), 'TRUE', VPA.Secondary_Other_Response) from TableThe syntax is correct. "TABLE" isn't a good name for a table, but I don't see anything else that's obviously wrong or suspicious.
I can't tell if it will do what you want or not, since I don't know what you want.
Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) and the results you want from that data.

Similar Messages

  • Decode statement in Select line of a View Object Query

    I attempted to create a view object in expert mode with a customized query.
    The query had a decode statement in the select line of the query. The view
    object compiled correctly but gave an error when run.
    ex: select .... decode(CrpSchools.SCHOOLS_ID,null,CrpCustSchools.SCHOOL_NAME,CrpSchools.SCHOOL_NAME) SCHOOL_VALUE, ...
    from ....
    where ....
    The error was that school_value does not exist in the statement. I got the error when
    doing a vo.executeQuery().
    When I removed the decode statement everything worked correctly. Does anyone know if
    the decode statement cannont be used in the select line of a query in a view object?
    Or maybe I was linking the query column (SCHOOLS_ID) up to the view attribute (SCHOOL_VALUE) incorrectly in the
    Attribute Mappings tab of the VO wizard?

    There should be no problem using a DECODE() statement, provided that you've aliases the column as you have done.
    At design time, if you click on the (Test) button, does your query test ok?
    Are you by chance applying a custom where clause at runtime?
    If so, are you saying:
    setWhereClause("yourtable.column_alias = ?";
    or are you doing:
    setWhereClause("column_alias = ?";
    for an expert-mode query, you'll need to use the latter syntax.

  • IF statement syntax in SQL script view

    I need to include a "IF" condition in the "SELECT" section of my SQL script view.
    I tried the following syntax's but I get the error 'Incorrect SQL syntax near 'IF'
    1.  IF(Revenue <> '0' AND Quantity <> '0', Revenue/Quantity, '0') AS Gross Price
    2.  IF(Revenue != '0' AND Quantity != '0', Revenue/Quantity, '0') AS Gross Price
    3.  IF(Revenue <> '0' AND Quantity <> '0' THEN Revenue/Quantity ELSE  '0' END) AS Gross Price
    4.  IF(Revenue != '0' AND Quantity != '0' THEN Revenue/Quantity ELSE  '0' END) AS Gross Price
    My final SQL would read like follows:
    SELECT field1, field2, IF(......) AS field3
    FROM table1
    Can anybody please help with the correct IF statement syntax to be used in the SQL script based view?

    Hi Lakshmi,
    below is the syntax for IF statement.
    IF <bool_expr1> THEN
    <then_stmts1>
    ELSEIF <bool_expr2>
    THEN <then_stmts2>
    [ELSE <else_stmts3>]
    END IF
    eg :
    BEGIN
    DECLARE found INT := 1;
    SELECT count(*) INTO found FROM books WHERE isbn = :v_isbn;
    IF :found = 0 THEN
    INSERT INTO books VALUES (:v_isbn, 'In-Memory Data Management', 1, 1, '2011', 42.75, 'EUR');
    ELSE
    UPDATE books SET price = 42.75 WHERE isbn =:v_isbn;
    END IF;
    END;
    Sreehari

  • Logical Standby SQL Apply Using Incorrect Decode Statement

    We are seeing statements erroring out on our logical standby that have been rewritten (presumably by sql apply) with decode statements that don't appear to be correct. For example, here is one of the rewritten statements.
    update /*+ streams restrict_all_ref_cons */ "CADPROD"."OMS_SQL_STATEMENT" p
    set *"APPLICATION"=decode(:1,'N',"APPLICATION",:2)*,
    "STATEMENT"=dbms_reputil2.get_final_lob(:3,"STATEMENT",:4)
    where (:5='N' or(1=1 and (:6='N' or(dbms_lob.compare(:7,"STATEMENT")=0)or(:7 is null and "STATEMENT" is null)))) and(:8="APPLICATION")
    The problem comes in, we believe, with the attempt to write the value "APPLICATION" to the application column which is only a 10 character field. the value for the :1 bind variable is "N" and the value for :2 is null.
    We see the following error on the logical standby:
    ORA-00600: internal error code, arguments: [kgh_heap_sizes:ds], [0x01FCDBE60], [], [], [], [], [], []
    ORA-07445: exception encountered: core dump [ACCESS_VIOLATION] [kxtoedu+54] [PC:0x2542308] [ADDR:0xFFFFFFFFFFFFFFFF] [UNABLE_TO_READ] []
    ORA-12899: value too large for column "CADPROD"."OMS_SQL_STATEMENT"."APPLICATION" (actual: 19576, maximum: 10)
    Is this a configuration issue or is it normal for SQL Apply to convert statements from logminer into decode statements?
    We have an Oracle 10.2.0.4 database running on windows 2003 R2 64-bit os. We have 3 physical and 2 logical standby's, no problems on the physical standbys.

    Hello;
    I noticed some of your parameters seem to be wrong.
    fal_client - This is Obsolete in 11.2
    You have db_name='test' on the Standby, it should be 'asadmin'
    fal_server=test is set like this on the standby, it should be 'asadmin'
    I might consider changing VALID_FOR to this :
    VALID_FOR=(ONLINE_LOGFILES,ALL_ROLES)Would review 4.2 Step-by-Step Instructions for Creating a Logical Standby Database of Oracle Document E10700-02
    Document 278371.1 is showing its age in my humble opinion.
    -----Wait on this until you fix your parameters----------------------
    Try restarting the SQL Apply
    ALTER DATABASE START LOGICAL STANDBY APPLY IMMEDIATEI don't see the parameter MAX_SERVERS, try setting it to 8 times the number of cores.
    Use these statements to trouble shoot :
    SELECT NAME, VALUE, UNIT FROM V$DATAGUARD_STATS;
    SELECT NAME, VALUE FROM V$LOGSTDBY_STATS WHERE NAME LIKE ;TRANSACTIONS%';
    SELECT COUNT(1) AS IDLE_PREPARERS FROM V$LOGSTDBY_PROCESS WHERE
    TYPE = 'PREPERER' AND STATUS_CODE = 16166;Best Regards
    mseberg
    Edited by: mseberg on Feb 14, 2012 7:37 AM

  • How to determine INT and FLOAT in a DECODE statement

    Can anyone help me with the following problem:
    I have a column defined as a NUMBER(15,4). I am trying to determine the java type using the getScale() method in ResultSetMetaData. When the scale is greater than 0, then it is an float, else it is an int. In this case, the getScale() method should return 4. However, when querying with a DECODE statement on the NUMBER(15,4) field, the getScale() method always returns 0 and the value is therefore converted to an int. Anyone knows how to solve this problem?
    Thanks

    Alcides,
    Oracle NUMBER data type is mapped to "java.math.BigDecimal" class.
    You will find more information in the JDBC Developer's Guide and Reference which is part of the Oracle documentation and available from:
    http://www.oracle.com/technology/documentation/index.html
    Good Luck,
    Avi.

  • 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

  • Calling a stored proc in a decode statement

    I am having a problem calling a store procedure in a SQL statement. I am using Oracle's thin driver.
    I have been able to do the following:
    select col1,
    col2,
    SOME_STORED_PROC(var1,var2,col3)
    from some_table
    where col3 = var3
    However, when I try to call a stored procedure with-in a decode statement, the call fails. I have tested the call from a sql prompt and it works fine but it does not work when I execute the query in my Java program.
    Here is an example of what I am trying to do:
    select col1,
    col2,
    decode((select col1
    from some_other_table
    where col2 = var1), 'X',
    SOME_STORED_PROC(var1,var2,col3),
    SOME_OTHER_STORED_PROC(var2,var4,col5))
    from some_table
    where col3 = var3
    Does anyone know if this type of call is not supported in Oracle's thin driver?
    Thanks,
    Cory
    null

    I played around with a [parallel PL/SQL launcher|http://www.williamrobertson.net/feed/2008/08/parallel-plsql-launcher-update.html] a while ago, but I wouldn't call it production-ready.
    You could also [submit procedure calls in background|http://www.williamrobertson.net/feed/2005/12/job-control-object.html] using DBMS_ALERT to track completion status.

  • 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.

  • Improving SQL Insert statement syntax

    It's about insert statement syntax, in insert statement, unlike in update statement column names and corresponding values are separated in two different sets. With this separation debugging/writing of insert statement is going to be time taking activity. To identify what value is getting stored in any column, first column position needs to be identified and after that by counting commas in the values list value is located. If functions are included in insert statement then counting of commas doesn't help to locate the value.
    In any non trivial application column count in insert statement is going to be very big number and it is unmanageable.
    If column name and value are written next to each other as it is done in cause of UPDATE statement, it is going to drastically reduce the debugging efforts and there by improves the productivity of the developers.
    So I request SQL community please consider having a variant of insert statement in similar lines of update statement. This will simplify the life of millions of developers.
    Edited by: user9110509 on Feb 6, 2010 10:19 AM

    Hi,
    That's a good idea! An optional alternate way of specifying the columns would be handy.
    Perhaps the reason it hasn't been done yet is that most people, like those who have responded to this message, do not find the current syntax much of a problem. We can't be sure if your idea "is going to drastically reduce the debugging efforts" until it is available, but my guess is that it isn't.
    One thing I do to make sure the two lists match is to indent the values directly below the column names, like this:
    INSERT INTO emp (empno, ename,   hiredate,                job)
          VALUES (9876,  'OBAMA', TO_DATE ( '20-JAN-2009'
                              , 'DD-MON-YYYY), 'PRESIDENT');If the list is very long, or individual values are very complicated, then I might start with a list of the column names
    INSERT INTO emp          -- Step 1: not ready to run yet
    (     empno
    ,     ename
    ,     hiredate
    ,     job
    VALUESthen use the editor's copy and paste commands to duplicate that list:
    INSERT INTO emp          -- Step 2: not ready to run yet
    (     empno
    ,     ename
    ,     hiredate
    ,     job
    VALUES
    (     empno
    ,     ename
    ,     hiredate
    ,     job
    ;and then fill in the VALUES section, leaving the copied names as comments:
    INSERT INTO emp          -- Step 3: ready to run
    (     empno
    ,     ename
    ,     hiredate
    ,     job
    VALUES
    (     9876               -- empno
    ,     'OBAMA'               -- ename
    ,     TO_DATE ( '20-JAN-2009'
              , 'DD-MON-YYYY
              )          -- hiredate
    ,     'PRESIDENT'          -- job
    ;

  • DECODE statement

    please can someone kindly code the following line of SQL using the DECODE statement:
    case when Student_Status in ('Registered','Repeat','Referral', 'Deferral')and GRADE <> 'MISSING' then EXAM1_RESULT else Null end as Valid_EX1
    It will be most appreciated.
    Thanks

    user607929 wrote:
    I'm ever so sorry, I keep sending the same Wrong thing.
    This is what i need translated to DECODE:
    "case when
    Student_Status in ('Registered','Repeat','Referral', 'Deferral') and GRADE is not 'MISSING'
    then EXAM1_RESULT
    else Null end as Valid_EX1"
    the issue is with the NOT 'MISSING' string.Check this. Just re-arrange of Andrés Muchiut post
    DECODE (
    STUDENT_STATUS
    ,'Registered',DECODE(GRADE,'MISSING',null,EXAM1_RESULT)
    ,'Repeat' ,DECODE(GRADE,'MISSING',null,EXAM1_RESULT)
    ,'Referral' ,DECODE(GRADE,'MISSING',null,EXAM1_RESULT)
    ,'Deferral' ,DECODE(GRADE,'MISSING',null,EXAM1_RESULT)
    , null) Valid_EX1Hope this may help you...

  • Decode statement in a mapping involve Source Text File & Table.

    Hi All,
    Oracle 9i Warehouse Builder Client: 9.2.0.4.0
    Oracle 9i Warehouse Builder Repository: 9.2.0.2.0
    Oracle9i Enterprise Edition Release 9.2.0.5.0 - 64bit Production
    Does OWB allow to use Decode statement in a mapping involves Source Text File and Oracle Table.
    My understanding is it's not possible, since OWB makes use of Sqlloader. For this work arround could be make use of External Table instead of Text Flat File.
    However I came across an old posting (June-2003) which says that this feature is available OWB 9.2.
    Following is the url:
    IF THEN LOGIC from Flat File to Table
    Can someone please confirm this?
    Thanks in Advance.
    Regards,
    Vidyanand

    Hi all,
    If you want to validate correctly this mapping you must to :
    1. Right click on the mapping, then Configure
    2. Right click on Sql Loader Data Files, then Create
    3. Verify that the location name is correct and complete the Data File Name
    4. OK
    The validation is now OK.
    I hope it will be help you
    Best Regards
    Samy

  • 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

  • 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.

  • Decode Statement Inside the Case statement

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

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

  • 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.

Maybe you are looking for

  • Problem with coding blocks

    Dear All, I am doing a BDC for  a particular transaction. The BDC program defaults some values. The problem is , at a particular screen the coding blocks screen was popping up..I did n't code this coding block screen..I want to supress that coding bl

  • Any default sound boards in Flash 8?

    I want to have a simple MP3 play on my site when I open the page. I want the MP3 to have a sound board attached to it though with play, stop, pause, volume, etc... Are there any of these built into Flash 8 or is there a place I can download one inste

  • Urgent,I can deploy a bean on websphere in windows;but an error occur in un

    urgent,I can deploy a bean on websphere in windows;but an error occur in unix. [Servlet Error]-[presentation]: Failed to load servlet: java.lang.LinkageError: LinkageError while defining class: com.s1.ccb.messaging.MessagingServlet Could not be defin

  • Enable the Debug mode for Dispatcher and Server0.

    Hello All,         In our EP server 7.0(stand alone java) apart from SDM we need to enable the Debug mode for Dispatcher and Server0.I tried to do it from mmc but cannot do so.When I try to right click & enable from mmc the "Enable Process" is not hi

  • Why can't I upgrade to mountain lion from 10.6.8

    I am using a Macbook 4,1 (not sure how to identify whether it's early or late 2008). I want to upgrade to Mountain Lion, so I spent $50 getting additional memory in order to be able to upgrade. I installed the extra memory, but the app store isn't le