Decode function issue / problem ..

Dear Sir / Madam,
Thanks for your understanding.
Right now I am facing a unique problem.
I am using decode function in a select statement. The columns are dynamic some columns are of type number and some are varchar datatypes. I want to apply decode function for every column irrespective of datatype.
What i am finding difficult is if the column is a number datatype , the decode funciton is working good but if the column datatype is varchar or char datatype then i am getting ..the error ..
report error:
ORA-01722: invalid number
here's the decode function..
decode (CHAI.EVNDRIVE,
-800000000000000,'.A',
-700000000000000, '.B',
-600000000000000 ,'.C',
-500000000000000 , '.D',
-400000000000000 , '.E',
-300000000000000 , '.F',
-200000000000000, '.G',
-100000000000000 , '.H',
-1000000000, '.R' ,CHAI.EVNDRIVE ) EVNDRIVE
how to use the above decode function irrespective of datatype..
pls let me know how to over come this kind of scenario.
is their a way to find whether the column datatype is number or char , so that i can check the column datatype before the decode funciton is applied ..
thanks ..
kumar

You can try ,
This is a "cheap and dirty" solution,
but it should work (if CHAI.EVNDRIVE is varchar2):
decode (CHAI.EVNDRIVE,
'-800000000000000','.A',
'-700000000000000', '.B',
'-600000000000000' ,'.C',
'-500000000000000' , '.D',
'-400000000000000' , '.E',
'-300000000000000' , '.F',
'-200000000000000', '.G',
'-100000000000000' , '.H',
'-1000000000', '.R' ,CHAI.EVNDRIVE ) EVNDRIVELev

Similar Messages

  • Decode Function issue

    Hi all,
    i want compare two rows in a table. so i used decode function to compare the values, whether its matched or not.
    One of my table column has Long data type.
    Decode(a.col1,b.col1,'Match','NotMatch')
    col1 - is long data type.
    when i use long data type, i got below error,
    is there anyway to rectify this error.
    SQL Error: ORA-00932: inconsistent datatypes: expected NUMBER got LONG
    00932. 00000 - "inconsistent datatypes: expected %s got %s"
    Thanks in advance.
    Regards,
    Santhosh

    >
    You can't use ANY function on a LONG column. This restriction is not limited to DECODE.
    >
    Not quite correct.
    You can use TO_LOB on a LONG column but only in the select list of a subquery in an INSERT statement.
    See TO_LOB in the SQL Language doc
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions205.htm#SQLRF06134
    >
    TO_LOB converts LONG or LONG RAW values in the column long_column to LOB values. You can apply this function only to a LONG or LONG RAW column, and only in the select list of a subquery in an INSERT statement.
    Before using this function, you must create a LOB column to receive the converted LONG values. To convert LONG values, create a CLOB column. To convert LONG RAW values, create a BLOB column.
    You cannot use the TO_LOB function to convert a LONG column to a LOB column in the subquery of a CREATE TABLE ... AS SELECT statement if you are creating an index-organized table. Instead, create the index-organized table without the LONG column, and then use the TO_LOB function in an INSERT ... AS SELECT statement.
    You cannot use this function within a PL/SQL package. Instead use the TO_CLOB or TO_BLOB functions.

  • 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

  • Problem with decode function.

    Hi,
    Can anyone of you help me out in solving this?
    It is like i wish to give different select statements according to the value of a parameter entered by user USING DECODE FUNCTION.The select statement contains some other select statements inside it.So when i execute it,it is giving error like 'ORA-00913-too many values(even when i enclose select statements within brackets).

    ORA-00913 too many values
    Cause: The SQL statement requires two sets of values equal in number. This error occurs when the second set contains more items than the first set. For example, the subquery in a WHERE or HAVING clause may return too many columns, or a VALUES or SELECT clause may return more columns than are listed in the INSERT.
    Action: Check the number of items in each set and change the SQL statement to make them equal.
    the above is from oracle documentation. the brackets is not the problem, u must be using multiple items in the integrated decode queries. If the problem still exists post ur DML for further analysis.
    zaibi.

  • Help needed in decode function

    I am trying to use decode function shown below
    select decode(deptid,(select deistinct dept_id from dept),'found') into id from student ;
    it shows error ORA 01427:single-row subquery returns more than one row.
    could you people help me resovle the issue.
    Thanks.

    Funny thing how many mistakes can be in one little line. I try to list what is wrong here. maybe it helps you to understand what is going on.
    select decode(deptid,(select deistinct dept_id from dept),'found') into id from student ;1) "deistinct" => wrong spelling "distinct"
    2) Uniqueness => the typical DEPT table has DEPT_ID as a primary key. So DISTINCT would do nothing here. "select distinct dept_id from dept" is the same as "select dept_id from dept".
    3) decode with a multi-row subquery => the decode function only accepts single values. e.g: ,"decode(deptid,(select max(dept_id) from dept),..." => THis is not really useful, just an example.
    4) decode without handling other values => it is better to say what should happen, when the values does not match. decode(deptid,:x,'found','notfound')
    5) select .. into ... from. => INTO is only used in a PL/SQL . So I assume this statement is part of a larger PL/SQL block. In that case "into id " is a problem. The select would return many values, but your ID variable could probably hold only one value.
    6) Identification of values => For all students that could be returned, you only would know 'found'. At least select the ID for the student too, else you wouldn't know which student was found. select id, 'found' ... from student.
    7) Don't select everthing and check for each row later. Select only relevent rows. That means do your checks in the WHERE clause of a select statement not in the SELECT clause. Example: "select id from student where dept_id in (select dept_id from dept);" Possible in this case is also a join "select student.id from student, dept where student.dept_id=dept.dept_id"
    8) referential integrity. Why do have to do this check anyway? On table student there should be a FK constraint, so that only values can be inserted where the DEPT_ID is correct. Then you select would be "select id from student;".

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

  • How can i use this expression in DECODE function?

    My PNO table formart is
    PNO PDate PCount
    P001 08/27/05 09:45 20
    P001 08/27/05 09:50 10
    P002 08/27/05 03:40 20
    P003 08/28/05 11:00 20
    P003 09/28/05 10:00 20
    P003 08/27/05 11:00 10
    P003 09/27/05 04:00 50
    I want to display total pcount for shift1(morning) and shift2(evening) & the date is 08/27/05
    PNO Shift1(08/27/2005 08:00 to 12:30) Shift2(08/27/2005 02:00 to 05:30)
    P001 30 0
    P002 0 20
    P004 10 50
    So for shift1 condition is:
    pdate>=08/27/2005 08:00 and pdate<=08/27/2005 12:30
    So for shift2 condition is:
    pdate>=08/27/2005 02:00 and pdate<=08/27/2005 05:30
    If i tried to give this expression in decode function , its not working.
    Please give me the sql query to solve this problem.
    Millions of thanks in advacne

    forgot to paste the output for a given date.
    SQL> create table pno
      2  (pno    varchar2(32)
      3  ,pdate  date
      4  ,pcount number)
      5  /
    Table created.
    SQL>
    SQL> insert into pno values('P001', to_Date('08/27/05 09:45', 'mm/dd/yy hh:mi') ,20)
      2  /
    1 row created.
    SQL> insert into pno values('P001', to_Date('08/27/05 09:50', 'mm/dd/yy hh:mi') ,10)
      2  /
    1 row created.
    SQL> insert into pno values('P002', to_Date('08/27/05 03:40', 'mm/dd/yy hh:mi') ,20)
      2  /
    1 row created.
    SQL>
    SQL> insert into pno values('P003', to_Date('08/28/05 11:00', 'mm/dd/yy hh:mi') ,20)
      2  /
    1 row created.
    SQL> insert into pno values('P003', to_Date('09/28/05 10:00', 'mm/dd/yy hh:mi') ,20)
      2  /
    1 row created.
    SQL> insert into pno values('P003', to_Date('08/27/05 11:00', 'mm/dd/yy hh:mi') ,10)
      2  /
    1 row created.
    SQL> insert into pno values('P003', to_Date('09/27/05 04:00', 'mm/dd/yy hh:mi') ,50)
      2  /
    1 row created.
    SQL> select pno,sum(pcount) "Morning Shift Count"
      2  from pno
      3  where to_char(pdate, 'mm/dd/yyyy hh:mi') >= '08/27/2005 08:00'
      4    and to_char(pdate, 'mm/dd/yyyy hh:mi') <='08/27/2005 12:30'
      5  group by pno
      6  /
    PNO                              Morning Shift Count                           
    P001                                              30                           
    P003                                              10                           
    SQL> select pno,sum(pcount) "Evening Shift Count"
      2  from pno
      3  where to_char(pdate, 'mm/dd/yyyy hh:mi') >= '08/27/2005 02:00'
      4    and to_char(pdate, 'mm/dd/yyyy hh:mi') <='08/27/2005 05:30'
      5  group by pno
      6  /
    PNO                              Evening Shift Count                           
    P002                                              20                           

  • 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

  • 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

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

  • Decode Function I asked this in the wrong section so I hope Im right now!

    select
    a11.SEQ_MEMB_ID,
    a11.Auth_Number,
    a11.Admit_Primary_Date,
    a11.Reviewer,
    Decode (a11.Reviewer,
    CLC, '2',
    HBR, '3',
    RAB, '4')
    a11.admit_primary_date
    from windsoradm.auth_master a11;
    I am trying to get if the Reviewer is CLC then they are code 2 HBR Code 3 etc and it does not work. I take out the decode function and the query works. I am getting ORA-00923 FROM KEYWORD NOT FOUND WHERE EXPECTED.

    Hi,
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Simplify the problem as much as possible. Remove all tables and columns that play no role in this problem.
    Always say which version of Oracle you're using.
    This is the right forum for this question. Mark your question in the other forum {message:id=10266930} as "Answered", so people won't waste their time.
    925518 wrote:
    select
    a11.SEQ_MEMB_ID,
    a11.Auth_Number,
    a11.Admit_Primary_Date,
    a11.Reviewer,
    Decode (a11.Reviewer,
    CLC, '2',
    HBR, '3',
    RAB, '4')
    a11.admit_primary_date
    from windsoradm.auth_master a11;
    I am trying to get if the Reviewer is CLC then they are code 2 HBR Code 3 etc and it does not work. I take out the decode function and the query works. I am getting ORA-00923 FROM KEYWORD NOT FOUND WHERE EXPECTED.That's the correct DECODE syntax, where CLC, HBR and RAB are columns, and you want to return a string (not a number) such as '2'.
    If 'CLC', 'HBR' and 'RAB' are literal values, then enclose them in single-quotes. If you want to return a number, don't put it in quotes. (Anyhting inside single-quotes is a string literal.)
    Perhaps you meant something like:
    ,     DECODE ( a11.Reviewer
                , 'CLC'          , 1
                , 'HBR'          , 2
                , 'RAB'          , 3
                )      AS reviewer_codeThere's an error right after the DECODE. You can't use a11.admit_primary_date as a column alias. (This is probably what's causing the ORA-00923 error.) Either a11_admit_primary_date (with an underscore instead of a dot) or admit_primary_date would be okay. If a11.admit_priomary_date is the next column in the SELECT clause, put a comma befor it.
    You need a FROM clause.

  • 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

  • Using mysql decode function in Java

    Hi everybody,
    mysql documentation says:
    DECODE(crypt_str,pass_str) -->
    Decrypts the encrypted string crypt_str using pass_str as the password. crypt_str should be a string returned from ENCODE().
    I used the above function in a Python script and had no problem, but have difficulty using the same thing in my Java code.
    I receive runtime error when tried decode() in my Java code in executeQuery("s");. As far as I know the decode() function should be compiled, I can't run the decode() in the mysql command tool and receive a response (as I compiled and ran it in my Python script).
    Has anybody ever used this function in the Java code? How? What format did you use? What I should use instead of "s" in this code?
    conn is a database connection:
    stmt = conn.createStatement();
    rs = stmt.executeQuery("s");
    I even tried PreparedStatement, but no luck.
    Any help is greatly appreciated.

    stmt.executeQuery("select blahblahblah, DECODE(fieldName, password), blahblahblah FROM blahblah...")

  • Question regarding decode function.

    Hi friends,
    I have a question regarding using decode.
    I'm try'g to explain my problem using emp table.
    Can you guys please help me out.
    For example consider emp table, now i want to get all manager id's concatenated for 2 employees.
    I tried using following code
    declare
    v_mgr_code  number(10);
    v_mgr1      number(4);
    v_mgr2      number(4);
    begin
    select  mgr into    v_mgr1
    from    scott.emp
    where   empno = 7369;
    select  mgr into    v_mgr2
    from    scott.emp
    where   empno = 7499;
    select v_mgr1||'-'||v_mgr2 into v_mgr_code from dual;
    end;now instead of writing 2 select statements can i write one select statement using decode function ?
    Edited by: user642856 on Mar 8, 2009 11:18 PM

    i don't know wheter your looking for this or not.if i am wrong correct me.
    SELECT Ename||' '||initcap('manager is ')||
    DECODE(MGR,
            7566, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7566),
            7698, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7698),
            7782, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7782),
            7788, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7788),
            7839, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7839),
            7902, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7902),
            'Do Not Know')  Manager from empor
    SELECT Ename||' '||initcap('manager is ')||
    DECODE(MGR,
            7566, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7566),
            7698, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7698),
            7782, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7782),
            7788, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7788),
            7839, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7839),
            7902, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7902)) manager
    from empEdited by: user4587979 on Mar 8, 2009 9:52 PM

  • How to use decode function

    Hello Friends,
    I have a query that has different columns and I am not sure what the data type of each column is ...
    I want to use decode function which displays the following if the value of the column is like this ..
    if the value of column is -714E ie -700000000000000 then display as .A
    if the value of column is -814E ie -800000000000000 then display as .B
    NOTE ; don't know which column is having the value - and i don't know the data type of the column is ..
    got to use the decode function for all the columns selected ..
    I want to use decode function pls let me know how to write for this kind of requirement.
    appreciate your help in this rgds.
    thanks/kumar

    Dear Sir / Madam,
    Thanks for your understanding.
    Right now I am facing a unique problem.
    I am using decode function in a select statement. The columns are dynamic some columns are of type number and some are varchar datatypes. I want to apply decode function for every column irrespective of datatype.
    What i am finding difficult is if the column is a number datatype , the decode funciton is working good but if the column datatype is varchar or char datatype then i am getting ..
    here's the decode function..
    decode (CHAI.EVNDRIVE,
    -800000000000000,'.A',
    -700000000000000, '.B',
    -600000000000000 ,'.C',
    -500000000000000 , '.D',
    -400000000000000 , '.E',
    -300000000000000 , '.F',
    -200000000000000, '.G',
    -100000000000000 , '.H',
    -1000000000, '.R' ,CHAI.EVNDRIVE ) EVNDRIVE
    report error:
    ORA-01722: invalid number
    pls let me know how to over come this kind of scenario.
    is their a way to find whether the column datatype is number or char , so that i can check the column datatype before the decode funciton is applied ..
    thanks ..
    kumar

Maybe you are looking for

  • Can I edit a HD project in SD, then export HD from the original files?

    I have a project that has been shot in HDV that, for a couple of reasons, I have to edit on my laptop instead of my rather powerful desktop. As well as it being HDV (1080 50i), it's also going to need lots of effects adding to it. Now, my laptop is p

  • IWork won't allow small text to be antialiased in PDFs

    Are there any PDF / iWork / OS X experts out there who can please help with this one? I have three documents which were to be printed as A5 booklets. As a result I formatted them on A5 pages using small text (7 and 8 point). I know this sounds small

  • PO Mass Change

    Dear All, I need some inputs from you all regarding PO Mass change. In some for PO for my client the excise duty rates and CVD rates(in case of import PO has changed). Now i want to delete these PO and create new ones after coying them from previous

  • T440p wifi slow reconnect after sleep

    Hi, I have a T440p with the intel 7260AC wifi card. I recently upgraded my HDD to an SSD and did a clean windows 7 install. Now, when waking up from sleep, it alwas takes about a min before it reconnects to a wifi network. The reconnect used to be in

  • ![CDATA[ in to textarea, converion to

    I use the Spry DataSet to import externa data. In this data, text like 'a<b' is used. To fill the XML Spry dataSet from PhP I use CDATA like;      <DESCRIPTION>       <![CDATA[bla bla text with a<b or b>a, etc etc..]]>     </DESCRIPTION> In the webpa