About Decode Function in oracle(on 28th)

Hi all
Can i use Decode function with Distinct as following.
SUM(DISTINCT DECODE(LR.QUESTIONNAIRE_ID,62, L.WORK_SPACE))
Regards

Hi,
The argument to SUM can be any numeric expression, including a DECODE statement that evaluates to a number.
"SUM (DISTINCT ..." is very suspicious. If you have three rows, with values 1, 1 and 3, the "SUM (DISTINCT" is 4. Is that what you want?
Perhaps your problem is that whenever you have more than one row, they will always be identical (e.g., a one-to-may join), so you have rows with 1, 1, and 1, from which you want to return 1. Most people do that by adding the value to the GROUP BY list, or by using MAX or MIN instead of SUM: they get the same results, but the code is clearer, and it works on non-numeric columns.

Similar Messages

  • DECODE Function in Oracle Froms 6.0

    I have discovered that in Oracle Forms 6.0 (Version 6.0.5.34.0) the DECODE Function performs an implicit TO_CHAR conversion that the DECODE Function in the Oracle 8 database does not.
    I discovered this when working with dates on the form. Dates prior to 2000 were not formatting correctly and all dates were not sorting correctly. By adding TO_DATE with the correct format mask outside of the DECODE statement the correct results were returned.
    When trouble shooting this through SQL Navigator connected directly to the database, the correct results were returned without having to use the TO_DATE function.

    Why don't you have any join conditions specified for your two inline views cr and de?
    If you want help with a query you should post DDL and inserts statements to create enough test data for someone to produce the set of results that you are looking for.
    HTH -- Mark D Powell --

  • DECODE function in Oracle gives duplicate data

    Hi,
    I want to retrieve distinct result using decode function and given below are the queries for that.
    SELECT DISTINCT O.*, DECODE(TA,'AP',AMT,'AC1',AMT,'AC2',AMT,'AC3',AMT,'AC4',AMT,NULL) AS CA,
    DECODE(TA,'AD1',AMT,NULL) AS DA FROM HT O, HIS H, V_CV
    WHERE O.HID=H.HID AND H.HTYP='TRN' AND O.HID = V.HID AND V.CID = '5' ORDER BY CA ASC;
    which gives me
    HID   TA      PT     AMT     CA         DA
    2     A     V     4.1     4.1     null
    3     C     V     14.02 14.02     null
    1     D     V 5.1     null          5.1
    4     D     V     6.21     null      6.21
    which is correct but i want to do sorting on two different column which do not exit in the database and they are dynamic.So i Modified the Query but i am getting duplicate results
    SELECT DISTINCT O.*,
    DECODE(o.TA,cr.TA,o.AMT,NULL) AS CA,
    DECODE(o.TA,de.TA,o.AMT,NULL) AS DA
    FROM HT O,
    HIS H,
    V_CV,
    (select TA from RTD where Ttype= 'C') cr,
    (select TA from RTD where Ttype= 'D') de
    WHERE
    O.HID=H.HID
    AND H.HTYP='TRN'
    AND O.HID = V.HID
    AND V.CID = '5'
    ORDER BY CA ASC
    which gives me
    HID   TA      PT     AMT     CA         DA
    2     A     V     4.1     4.1     null
    3     C     V     14.02 14.02     null
    3     C     V     14.02 null      null
    1     D     V 5.1     null          5.1
    1     D     V 5.1     null          null
    4     D     V     6.21     null      6.21
    2     A     V     4.1     null     null
    which is obviously giving HID 2,3,1 as duplicate value since DECODE select a value and compares with all item where i want only single comparison.
    Any help regarding this would be appreciated.
    Edited by: Pawanchoure on Jul 5, 2011 7:14 AM

    Why don't you have any join conditions specified for your two inline views cr and de?
    If you want help with a query you should post DDL and inserts statements to create enough test data for someone to produce the set of results that you are looking for.
    HTH -- Mark D Powell --

  • How to use decode function in oracle apex 3.2.1

    Hello Friends,
    how to use decode
    var_decode := 'decode'||'('|| var1 ||','|| -800000000000000||','||'.A'||','||
    appreciate your help.
    regards/kumar
    Edited by: kumar73 on Apr 23, 2010 12:25 PM
    Edited by: kumar73 on Apr 23, 2010 12:27 PM

    Hey just on this particular point, there's a handy PL/SQL method for escaping quotation characters which may reduce the complexity of the string.
    For example, if I had a string:
    I can't understand why quoting my 'quote' characters never seems to "work"!and I wanted to pass that into a variable, I could do this:
    vc_foo:= 'I can''t understand why my ''quote'' characters never seems to "work"!';or I could use the q function, whereby you enclose your string within a quote delimiter of your choice, like so:
    vc_foo:= q'^I can't understand why quoting my 'quote' characters never seems to "work"!^';
    note: I used the caret (^) character by convention but any valid character will do
    ...all of which leaves your original string more or less unadulterated.
    I find this particularly useful for generating dynamic SQL and dynamic PL/SQL, as it leave the query looking a tad more readable, although if you are chaining together multiple strings with double-pipes, it can make it a little muddier. I find it particularly useful if I'm going to deal with string data from, for example, a field with Irish-derived surnames such as "O'Reilly"...
    Give it a go!

  • About CAST function in oracle

    Hi ,
    Now iam migrating my system from SQL to ORACLE 9i.
    Here USERID is of NUMBER(38) type
      and DATA is of LONG type in SQL.
    I  have table named :
         PEOPLE  and DBATABLE and i run the following code in oracle but found the following error...
    ORA-00932: inconsistent datatypes:
    SELECT P.USERID FROM PEOPLE P LEFT OUTER JOIN (SELECT DATA  FROM DBATABLE WHERE NAME='USER' ) R ON CAST(DATA  AS VARCHAR(50))= CAST(P.USERID AS VARCHAR(50)) WHERE P.USERLOGID= 1000 AND R.DATA IS NULL;
    So help me for finding my error.
    I have missed somewhere but could not find what i missed .
    Plz help me out.
    With regards,
    Namus

    I messed up with the type conversion of :
    USERID -> NUMBER(38)
      and DATA -> LONG type in SQL.
    I have the checked in the database and found the value of the Column DATA with 31 and when i try to run as :
    SELECT DATA  FROM DBATABLE WHERE NAME='USER' AND DATA = '31'.
    it gives error : Illegal use of the Long datatype and then i tried to cast as :
    SELECT CAST<DATA AS INTEGER>  FROM DBATABLE WHERE NAME='USER' AND DATA = '31'.
    it also give error as:
    FROM keyword not found where expected
    So plz help me out with this conversion.

  • Regarding decode function

    Hi all,
    i want to know abt decode function in oracle-sql
    i..e passing the parameters in decode using decode using ":" bind parameter
    select JOB, decode(:j,'CLERK','MANAGER','ANALYST','EXEC',JOB) FROM EMP;
    i declared the j variable in sql environment
    VARIABLE J VARCHAR2(20);
    i exec the query
    and passed as the clerk as input parameter
    but iam getting the o/p as
    JOB DECODE(:J
    MANAGER MANAGER
    MANAGER MANAGER
    MANAGER MANAGER
    SALESMAN SALESMAN
    SALESMAN SALESMAN
    SALESMAN SALESMAN
    CLERK CLERK
    SALESMAN SALESMAN
    ANALYST ANALYST
    CLERK CLERK
    ANALYST ANALYST
    JOB DECODE(:J
    CLERK CLERK
    12 rows selected.
    SQL> PRINT J;
    J
    im not getting o/p
    so please hlelp me only : should be used not &
    this is my first thread.
    execuse me if any mistakes
    tons of thanks in advance to all

    SORRY DAVE,ROD FOR NOT BEING CLEAR,
    IAM WORKING WITH EMP TABLE THE DATA IN IT IS LIKE THIS
    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
    7782 CLARK MANAGER 7839 09-JUN-81 2450 10
    7566 JONES MANAGER 7839 02-APR-81 2975 20
    7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
    7499 chaitu SALESMAN 7698 20-FEB-81 1600 300 10
    7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
    7900 JAMES CLERK 7698 03-DEC-81 950 30
    7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
    7902 FORD ANALYST 7566 03-DEC-81 3000 20
    7369 SMITH CLERK 7902 17-DEC-80 800 20
    7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    7876 ADAMS CLERK 7788 12-JAN-83 1100 20
    AND I USED DECODE FUNCTION
    select JOB BEFOREPROMOTION, decode(job,'CLERK','MANAGER','ANALYST','EXEC') PROMOTION FROM EMP
    BEFOREPRO PROMOTI
    MANAGER
    MANAGER
    MANAGER
    SALESMAN
    SALESMAN
    SALESMAN
    CLERK MANAGER
    SALESMAN
    ANALYST EXEC
    CLERK MANAGER
    ANALYST EXEC
    I..E ALL THE CLERKS TO MANAGERS AND SAME THING WITH ANALYST
    OK
    NOW I WILL SHOW U ANOTHER QUERY
    select job,decode(job,'CLERK','MANAGER','ANALYST','EXEC',JOB) FROM EMP where job=&job;
    Enter value for job: 'CLERK'
    old 1: select job,decode(job,'CLERK','MANAGER','ANALYST','EXEC',JOB) FROM EMP where job=&job
    new 1: select job,decode(job,'CLERK','MANAGER','ANALYST','EXEC',JOB) FROM EMP where job='CLERK'
    JOB DECODE(JO
    CLERK MANAGER
    CLERK MANAGER
    CLERK MANAGER
    HERE OBSERVE THAT I PASSED JOB ='CLERKS AS PARAMETER AFTER EXECUTING THE QUERY
    IT ASKED LIKE THIS AND SHOWED THE REPLACED VALUES
    Enter value for job: 'CLERK'
    AS SHOWN ABOVE
    FOR THIS TO PASS VALUE
    IN TO THE QUERY BY USING AMPERSAND('&')
    TO TAKE INPUT AS CLERK
    IT CHECKED AND RETURNED THE VALUE
    IN THE SIMILAR WAY CAN I USE ":" COLON
    TO PASS PARAMETERS
    IN TO THE QUERY
    CAN I USE IT
    REGARDS,
    PHANI
    Edited by: user10652894 on Nov 26, 2008 3:24 AM

  • Using a C function in Oracle

    Hi,
    I have a field in my table that stores an ID which is encoded using a C function. (third party database)
    I have also been provided the C function that decodes that field to display the actual value. I have compiled this code using Visual Studio .Net 2003 to a dll file, but do not know how to use it in Oracle. Or are there other ways to use this decode function in Oracle?
    I am on 9i database, Windows 2003 server.
    Any help is appreciated.
    Thank you.

    Hi, see:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:9087161189226

  • How to convert rows into columns with decode function

    Hi,
    How to convert rows into columns with the help of decode function in oracle.
    thanks and regards
    P Prakash

    say
    col1 col2
    1 10
    2 20
    3 30
    then use
    select col1,
    sum(decode(col2,10,10)) "new1"
    sum(decode(col2,20,20))"new2"
    sum(decode(col2,30,30))"new3"
    from table_name
    group by col1;
    we used sum u can use ny function if wont u have to give the column name i.e col2 name also
    so i think u got it nw
    regards

  • Oracle course to learn more about BI functions

    Hi,
    Do you know if there is any Oracle course specific about BI functions?
    Aggregate Functions
    Running Aggregate Functions
    String Functions
    Math Functions
    Calendar Date/Time Functions
    Conversion Functions
    System Functions
    Operators
    Expressions
    Literals
    I know how to build simple reports, but when it comes to use the above functions, I find it difficult.
    Maybe somebody can suggest a good book too?
    Thanks and Regards
    G.

    http://download.oracle.com/docs/cd/E10415_01/doc/bi.1013/b31770.pdf
    Page No 366 about Aggregated functions
    Running Aggregate Functions - 374
    String Functions - 378
    Math Functions - 384
    Calendar Date/Time Functions - 390
    Conversion Functions - 398
    System Functions - 402
    I Hope this works for you..

  • Problem using DECODE() function with a Query of Queries

    I
    posted
    on my blog about an issue I was having trying to use the PL/SQL
    DECODE() function with a Coldfusion Query of Queries. This function
    works fine when you query a database for information. However, when
    you query another query, it seems that CF doesn't recognize it. I
    got errors stating that it found a left parenthesis where it
    expected a FROM key word. Here is a simplified version of what I am
    trying to do:
    quote:
    <!--- Simulated query; similar to what I was calling from
    my database --->
    <cfscript>
    qOriginal = queryNew("Name,Email,CountryCode",
    "VarChar,VarChar,VarChar");
    newRow = queryAddRow(qOriginal, 5);
    querySetCell(qOriginal, "Name", "Joe", 1);
    querySetCell(qOriginal, "Email", "[email protected]", 1);
    querySetCell(qOriginal, "CountryCode", "AMER", 1);
    querySetCell(qOriginal, "Name", "Sally", 2);
    querySetCell(qOriginal, "Email", "[email protected]", 2);
    querySetCell(qOriginal, "CountryCode", "AMER", 2);
    querySetCell(qOriginal, "Name", "Bob", 3);
    querySetCell(qOriginal, "Email", "[email protected]", 3);
    querySetCell(qOriginal, "CountryCode", "ASIA", 3);
    querySetCell(qOriginal, "Name", "Mary", 4);
    querySetCell(qOriginal, "Email", "[email protected]", 4);
    querySetCell(qOriginal, "CountryCode", "EURO", 4);
    querySetCell(qOriginal, "Name", "John", 5);
    querySetCell(qOriginal, "Email", "[email protected]", 5);
    querySetCell(qOriginal, "CountryCode", "EURO", 5);
    </cfscript>
    <cfquery name="qCountries" dbtype="query">
    SELECT DISTINCT(CountryCode) AS CountryCode,
    DECODE(states, "AMER", "North America &amp; Canada",
    "EURO", "Europe &amp; Africa", "ASIA", "Japan &amp;
    Asia","") CountryName
    FROM qOriginal
    ORDER BY CountryCode
    </cfquery>
    <cfdump var="#qCountries#">
    <!--- ========== END OF CODE ========== --->
    So running this returned the following error:
    Query Of Queries syntax error.
    Encountered "(. Incorrect Select Statement, Expecting a
    'FROM', but encountered '(' instead, A select statement should have
    a 'FROM' construct.
    Does anybody know why this doesn't work? Is it just not
    supported? Please note that I have also tried to use the CASE()
    function instead of DECODE() and that resulted in basically the
    same error. For now I an looping over my distinct query with a
    switch statement and manually loading a new query with the data how
    I want it. But it would be a lot cleaner and less code to have the
    DECODE() to work. Thx!

    DECODE() is an Oracle function, not generic SQL. Q-of-Q is a
    very limited subset of SQL and lacks many functions and clauses
    available in standard SQL, especially what you may be used to using
    in your particular RDBMS.
    See
    Query
    of Queries user guide
    Phil

  • Decode function in Update statement

    Hello everyone,
    I'm trying to write a query where I can update a pastdue_fees column in a book_trans table based on a difference between return_dte and due_dte columns.
    I am using Oracle SQL. This is what I have so far for my decode function:
    SQL> SELECT
    2 DECODE(SIGN((return_dte - due_dte)*2),
    3 '-1', '0',
    4 '1', '12', 'Null')
    5 FROM book_trans;
    DECO
    Null
    12
    Null
    0
    So the logic is that if the sign is -1, the value in return_dte column should be 0; if it's +1 then it's 12 and everything else is Null.
    So now, I need to enter my decode function into the update statement to update the columns. However, I get error messages.
    The logic should be:
    UPDATE book_trans SET PastDue_fees = decode(expression)
    I've given it a couple of different tries with the following results:
    SQL> UPDATE book_trans
    2 SET pastdue_fees = SELECT
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    SET pastdue_fees = SELECT
    ERROR at line 2:
    ORA-00936: missing expression
    SQL> UPDATE book_trans
    2 SET pastdue_fees =
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    FROM book_trans
    ERROR at line 6:
    ORA-00933: SQL command not properly ended
    Any help or tips would be greatly appreciated as I've been taking SQL for about six weeks and not very proficient!
    Thanks!

    882300 wrote:
    Hello everyone,
    I'm trying to write a query where I can update a pastdue_fees column in a book_trans table based on a difference between return_dte and due_dte columns.
    I am using Oracle SQL. This is what I have so far for my decode function:
    SQL> SELECT
    2 DECODE(SIGN((return_dte - due_dte)*2),
    3 '-1', '0',
    4 '1', '12', 'Null')
    5 FROM book_trans;
    DECO
    Null
    12
    Null
    0
    So the logic is that if the sign is -1, the value in return_dte column should be 0; if it's +1 then it's 12 and everything else is Null.
    So now, I need to enter my decode function into the update statement to update the columns. However, I get error messages.
    The logic should be:
    UPDATE book_trans SET PastDue_fees = decode(expression)
    I've given it a couple of different tries with the following results:
    SQL> UPDATE book_trans
    2 SET pastdue_fees = SELECT
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    SET pastdue_fees = SELECT
    ERROR at line 2:
    ORA-00936: missing expression
    SQL> UPDATE book_trans
    2 SET pastdue_fees =
    3 DECODE(SIGN((return_dte - due_dte)*2),
    4 '-1', '0',
    5 '1', '12', 'Null')
    6 FROM book_trans;
    FROM book_trans
    ERROR at line 6:
    ORA-00933: SQL command not properly ended
    Any help or tips would be greatly appreciated as I've been taking SQL for about six weeks and not very proficient!
    Thanks!If you really really really want to update the entire table, the syntax would be...
    UPDATE book_trans
       SET
          pastdue_fees  = DECODE(SIGN((return_dte - due_dte)*2), -1, 0, 1, 12, Null);I took out all the single quotes. If you actually have a string column and you're storing entirely numbers in it then it should be declared as a NUMBER column and not a character (varchar2) column.
    ALWAYS use the proper data type, it'll save you a ton of headaches in the future.
    Also, since you're new to the forum, please read the FAQ so you learn the etiquette and what not.
    http://wikis.sun.com/display/Forums/Forums+FAQ

  • Decode Function Help

    Hi,
    I am new to Oracle Development.
    MY Requirement:
    I need to populate a column 'ISMSG' with YES / NO based on the following condition
    When code = 'S' or 'O'......the column 'ISMSG' should display YES else NO..
    ie output should be like
    CODE ISMSG
    A NO
    S YES
    S YES
    O YES
    My code for Decode function:
    CASE
    WHEN c.code = 'S' THEN decode( c.code, 'S','YES','NO')
    WHEN c.code = 'O' THEN decode( c.code, 'O','YES','NO')
    END ISMSG,
    Is my code correct? If so is this the best way to do it?
    If not please correct the code.
    Is there an efficient way to do it?
    Thanks in advance.

    Hi,
    You can use either CASE or DECODE for that; there's no need to use both.
    Using CASE:
    SELECT  c.code
    ,     CASE
             WHEN  c.code  IN  ('S', '0')  THEN  'YES'
                                               ELSE  'NO'
         END     AS ismsg
    FROM    table_x   c;Using DECODE:
    SELECT  c.code
    ,     DECODE ( c.code 
                , 'S'      , 'YES'
                , '0'      , 'YES'
                              'NO'
                )          AS ismsg
    FROM    table_x   c;I suggest you forget about DECODE, and always use CASE, at least while you're just starting out.
    CASE can do anything that DECODE can do. There are a few, simple situations where DECODE is a little shorter than CASE, and therefore a little clearer, but only a little, and, as I said, these are only simple situations, and CASE is clear enough in them.
    DECODE is never much shorter or clearer than CASE. The converse is not true: there are many situations where CASE is much, much shorter and clearer than DECODE.

  • SQL DECODE function

    Oracle version: 9.2.0.1.0
    Procob version: 9.2.0.1.0
    Cobol version: 3.1.11
    O.S. version: Windows XP
    We have a pro*cobol file with the next conversion rule into a select defined with a cursor.
    NVL(TO_CHAR(A.F_ALTA,'YYYYMMDD'),' '),     
    NVL(TO_CHAR(A.F_ESTADO,'YYYYMMDD'),' '),
    we store the result data through a fetch of the cursor into two variables (W-F-ALTA and W-F-ESTADO) When the program executes an insert of these two values in a target table, we define the next conversion rule:
    TO_DATE(DECODE(:W-F-ALTA,' ',NULL,:W-F-ALTA),'YYYYMMDD'),
    TO_DATE(DECODE(:W-F-ESTADO,' ',NULL,:W-F-ESTADO),'YYYYMMDD')
    Pro*Cobol and Cobol does not have errors when we precompile and compile the program but, when we execute the generated exe file, Oracle displays the next error:
    ORA-01841 (full) year must be between -4713 and +9999, and not be 0
    We think that the DECODE function is not understood by the cobol or pro*cobol interpreter. If we execute the same code without the DECODE function (only with TO_DATE function) there is no errors in the execution of the program
    somebody knows if there are reported problems with this DECODE function in Pro*Cobol or Cobol and how to solve them?
    Thanks

    TO_DATE(DECODE(:W-F-ALTA,' ',NULL,:W-F-ALTA),'YYYYMMDD'),
    TO_DATE(DECODE(:W-F-ESTADO,' ',NULL,:W-F-ESTADO),'YYYYMMDD')The problem is with the input values of :W-F-ALTA and :W-F-ESTADO. Using the first line as an example, what you are saying is if :W-F-ALTA is ' ', substitute it with NULL, any other value should be :W-F-ALTA, then output the TO_DATE value of whatever the result is.
    So if the value of :W-F-ALTA is the wrong charater or in the wrong input format, TO_DATE function does not understand it.
    See examples of success and failures below with your Bind variables substituted with typical values.
    SQL> select TO_DATE(DECODE(' ',' ',NULL,'20060830'),'YYYYMMDD') from dual;
    TO_DATE(D
    SQL> select TO_DATE(DECODE('1999-01-01',' ','NULL','20060830'),'YYYYMMDD') from dual;
    TO_DATE(D
    30-AUG-06
    SQL> select TO_DATE(DECODE('SHOULD_ERROR',' ','NULL','SHOULD_ERROR'),'YYYYMMDD') from dual;
    select TO_DATE(DECODE('SHOULD_ERROR',' ','NULL','SHOULD_ERROR'),'YYYYMMDD') from dual
    ERROR at line 1:
    ORA-01841: (full) year must be between -4713 and +9999, and not be 0
    SQL> select TO_DATE(DECODE('20060830',' ','NULL','20060830'),'YYYYMMDD') from dual;
    TO_DATE(D
    30-AUG-06
    SQL> select TO_DATE(DECODE('12345678',' ','NULL','12345678'),'YYYYMMDD') from dual;
    select TO_DATE(DECODE('12345678',' ','NULL','12345678'),'YYYYMMDD') from dual
    ERROR at line 1:
    ORA-01843: not a valid month
    SQL>

  • Help on Decode function in Toplink

    Hi,
    I have a sql statement like this:
    select field1, field2 from table1 where upper(field1) like 'ADELPHI%'
    order by field1,
    DECODE(TO_CHAR(NVL(LENGTH(TRANSLATE(field1,'A1234567890','A')),0)),'0',LPAD(field1 ,50),field1)
    How would I converted this to toplink query?
    I appreciate any help you guys can extend to me.

    I just spent about a half hour writing a response here, and the damned forum timed out on me. #$^!@$#!^!@$%.
    Here is the summary:
    - Using TL Expressions and EJBQL are to allow Java developers who don't necessarily know SQL to write queries and to facilitate portability/maintainability of the apps. For REALLY gnarly queries, using TL Expressions or EJBQL won't buy you this. I.e., SQL is more expressive and easier for this kind of quer, so it's not easier to use, and frankly with the code needed to support it, it won't be easier to maintain or port... Bottom line, maybe SQL is the best option here?
    - If you want to experiment, search for TO_CHAR on this forum, and the decode function in the javadoc. You need to build the expressions in pieces and you can treat expressions as arguments to other expressions -- in other words, you can build an expression like builder.leftPad(50, builder.get("field1")) and use it as one of the key/values in the hashtable to the decode function (in theory).
    - Don

  • BLOB in DECODE function

    Hi All,
    I am new to sql. I want to use decode for BLOB datatype. For this i written a query like below.
    Here user_data is of type BLOB.
    select DECODE(length(user_data), 0, null, file_data) user_data from user_table;
    I have tried the other way by using case like below. Its worked fine
    select
    CASE
    WHEN LENGTH(user_data )=0
    THEN NULL
    ELSE user_data
    END user_data from user_table;
    What i made wrong in the first query?
    Thanks
    Jimmi

    >
    Its just a wrong typo
    >
    Thanks.
    The problem is that this decode
    select DECODE(length(user_data), 0, null, file_data) user_data from user_table; expects you to return a number and you are returning a BLOB.
    Were you getting 'ORA-00932: inconsistent datatypes: expected BLOB got NUMBER'?
    See the DECODE function in the SQL doc
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/functions042.htm

Maybe you are looking for