PLS-00382 with decode

Hi,
I have a select statement with a decode.
SELECT decode(x_des_num,0,dc.name,avcs_common_util_db_pkg.f_get_des(x_des_num, x_des_type, 'NAME')) des_name,
                    decode(x_des_num,0,dc.num,avcs_common_util_db_pkg.f_get_des(x_des_num, x_des_type, 'NUM')) des_num,
                    dc.name,
                    wcs.shift_date,
                    s.name, ....
the type of x_des_num is number and the type of dc.name is varchar2.
when i put a to_char(c_des_num),'0' i still got the same error.
what is the problem?

Problem is solved.

Similar Messages

  • Error while replacing IF statements with DECODE function in procedure

    Hi All,
    I have created a procedure which has nested IF statements. Now I want to replace the IF statements with DECODE functions to improve performance.
    Procedure:
    IF (var_int_sev = '0')
    THEN
    var_sev := '2';
    ELSE
    SELECT sev
    INTO var_int_sev
    FROM errorconfig
    WHERE errorcode = var_errorcode;
    var_sev := var_int_sev;
    END IF;
    I converted the above IF statement into DECODE function as mentioned below:
    var_Sev := DECODE(var_int_sev,0,2,SELECT severity FROM errorconfig WHERE errorcode=var_ErrorCode)
    But it throws below error at the select statement used inside DECODE.
    Error(58,51): PLS-00103: Encountered the symbol "SELECT" when expecting one of the following: ( - + case mod new not null others <an identifier> <a double-quoted delimited-identifier> <a bind variable> avg count current exists max min prior sql stddev sum variance execute forall merge time timestamp interval date <a string literal with character set specification> <a number> <a single-quoted SQL string> pipe <an alternatively-quoted string literal with character set specification> <an alternativ
    Can someone help me in converting the IF to DECODE in the above case. Also how can we use a select statement inside decode.

    instead of trying to rewrite all your code and hoping that the performance will be better, it's a better option to investigate and find out which part of your application is slow
    read this:
    When your query takes too long ...

  • OWB3i - Validate with DECODE function

    Hi,
    in OWB 3i when I validate an expression defined inside an expression operator with DECODE() function (which is not include in default transformation) come this error:
    Line 1, Col 1:
    PLS-00204: function or pseudo-column 'DECODE' may be used inside a SQL statement only
    but it seems only a warning because when i generate the scripts and run no other error happen and all works fine.
    Regards

    Hi,
    Welcome to the forum!
    When you use a default value, the last argument to DECODE is the actual value you want as a default.
    For example:
    SELECT       ename
    ,       deptno
    ,       DECODE ( deptno
                 , 30     , 'Sales'
                      , 'All others'     -- Default value
                  )                 AS dname
    FROM      scott.emp
    ORDER BY  ename
    ;Output:
    ENAME          DEPTNO DNAME
    ADAMS              20 All others
    ALLEN              30 Sales
    BLAKE              30 Sales
    CLARK              10 All others
    FORD               20 All others
    JAMES              30 Sales
    JONES              20 All others
    KING               10 All others
    MARTIN             30 Sales
    MILLER             10 All others
    SCOTT              20 All others
    SMITH              20 All others
    TURNER             30 Sales
    WARD               30 Sales 
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    If you can show the problem using commonly available tables (such as those in the scott schema) then you don't need to post any sample data; just the results and the explanation.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • Problem with DECODE statement while migrating forms to 6i

    Hi,
    I'm migrating a form from 5 to 6i. When I compiled the form, I got this error witha decode statement.
    The error is
    Error 307 at line 15 column 7
    too many declarations of "DECODE" match this call
    The trigger has this code:
    IF :PRUN_RECS_INSERTED = 'Y' THEN
          RETURN ;
       END IF ;
       INSERT INTO GJBPRUN
        ( GJBPRUN_JOB,
          GJBPRUN_ONE_UP_NO,
          GJBPRUN_NUMBER,
          GJBPRUN_ACTIVITY_DATE,
          GJBPRUN_VALUE )
       SELECT :KEYBLCK_JOB,
              :ONE_UP_NO,
               GJBPDFT_NUMBER,
               SYSDATE,
          DECODE(GJBPDFT_VALUE, 'SYSDATE',
                          DECODE(GJBPDEF_LENGTH,'11',TO_CHAR(SYSDATE,'DD-MON-YYYY'), SYSDATE),
                          GJBPDFT_VALUE)
       FROM   GJBPDFT G, GJBPDEFEdited by: Charan on Mar 16, 2011 9:15 AM

    Hi Charan
    i think it's all about using both CHARACTER and DATE values at the same time in a DECODE statment u should either use char or date datatype.
    DECODE compares expr to each search value one by one. If expr is equal to a search, then Oracle Database returns the corresponding result. If no match is found, then Oracle returns default. If default is omitted, then Oracle returns null.
    e.g.
    If expr and search are character data, then Oracle compares them using nonpadded comparison semantics.
    expr, search, and result can be any of the datatypes CHAR, VARCHAR2, NCHAR, or NVARCHAR2.
    The string returned is of VARCHAR2 datatype and is in the same character set as the first result parameter.
    for more pls have a look here
    Hope this helps,
    Regards,
    Abdetu...

  • How to use count with decode

    I want to count several categories(say a b c d) under same count and some catogories under another count ..there I need to use count with decode pls let me know the syntacs to write my query..this is ergent
    regards
    Buddhike

    Something like this ?
    select count(decode(your_column,'a',1)) as "a",
           count(decode(your_column,'b',1)) as "b",
           count(decode(your_column,'c',1)) as "c",
           count(decode(your_column,'d',1)) as "d"
    from your_table;But maybe you can give us more details about what do you expected ?
    Nicolas.

  • PLS-00382 Error in procedure

    I have a procedure (below) that is invalid. Last night the instance of the database I'm working in got refreshed (data only) and a few of my procedures were invalidated, including this one. When I tried to recreate it I got the following error:
    PLS-00382: expression is of wrong type
    I don't understand why it's now not working (worked fine yesterday), or what this error means in relation to the statement.
    Does anyone know what I'm doing wrong here?
    Thanks,
    Pete
    SQL> CREATE OR REPLACE PROCEDURE nyp.WBS_NOTE
    2 IS
    3 CURSOR C_WBS_NOTES IS
    4 SELECT * FROM WBS_NOTES;
    5 V_WBS_ID NUMBER;
    6 V_WBSMEMO_ID NUMBER;
    7 V_PROJ_ID NUMBER;
    8 V_WBS_VAL VARCHAR2(200);
    9 V_WBS_PARENT VARCHAR2(200);
    10
    11 BEGIN
    12 UPDATE
    13 WBS_NOTES W
    14 SET W.TEXT = REPLACE(W.Text, 'CHR(13)', '
    15 ');
    16 INSERT INTO WBS_NOTE_PROJ_NOT_FOUND
    17 SELECT *
    18 FROM WBS_NOTES W WHERE EXISTS(
    19 SELECT 'A'
    20 FROM ACC_CONV_PROJ_NOT_FOUND P
    21 WHERE W.Project_num = P.Project_num);
    22 DELETE
    23 FROM WBS_NOTES W WHERE EXISTS(
    24 SELECT 'A'
    25 FROM ACC_CONV_PROJ_NOT_FOUND P
    26 WHERE W.Project_num = P.Project_num);
    27 FOR NOTES IN C_WBS_NOTES LOOP
    28 SELECT P.PROJ_ID
    29 INTO V_PROJ_ID
    30 FROM PROJECT P
    31 WHERE P.PROJ_SHORT_NAME = NOTES.PROJECT_NUM;
    32 V_WBS_VAL := NOTES.WBS;
    33 V_WBS_PARENT := SUBSTR(V_WBS_VAL, 1, INSTR(V_WBS_VAL, '.', -1) - 1);
    34 WHILE INSTR(V_WBS_PARENT, '.') <> 0 LOOP
    35 V_WBS_PARENT := SUBSTR(V_WBS_PARENT, INSTR(V_WBS_PARENT, '.') + 1, 200);
    36 END LOOP;
    37 V_WBS_VAL := SUBSTR(V_WBS_VAL, INSTR(V_WBS_VAL, '.') + 1, 200);
    38 WHILE INSTR(V_WBS_VAL, '.') <> 0 LOOP
    39 V_WBS_VAL := SUBSTR(V_WBS_VAL, INSTR(V_WBS_VAL, '.') + 1, 200);
    40 END LOOP;
    41 SELECT W.WBS_ID
    42 INTO V_WBS_ID
    43 FROM PROJWBS W
    44 , PROJWBS PW
    45 WHERE UPPER(W.WBS_NAME) = UPPER(V_WBS_VAL)
    46 AND PW.PROJ_ID = V_PROJ_ID
    47 AND PW.WBS_ID = W.PARENT_WBS_ID
    48 AND UPPER(PW.WBS_SHORT_NAME) = UPPER(V_WBS_PARENT);
    49 GETNEXTKEYS('wbsmemo_wbs_memo_id', 1, V_WBSMEMO_ID);
    50 EXECUTE IMMEDIATE
    51 ' INSERT INTO WBSMEMO ' ||
    52 ' SELECT ' || V_WBSMEMO_ID ||
    53 ', ''' || V_PROJ_ID || '''' ||
    54 ', ''' || V_WBS_ID || '''' ||
    55 ', MT.MEMO_TYPE_ID ' ||
    56 ', ''' || NOTES.TEXT || '''' ||
    57 ' FROM MEMOTYPE MT ' ||
    58 ' WHERE MT.MEMO_TYPE = ''' || NOTES.NTBKTYPE || '''';
    59 END LOOP;
    60 END;
    61 /
    Warning: Procedure created with compilation errors.
    SQL> SHOW ERRORS
    Errors for PROCEDURE NYP.WBS_NOTE:
    LINE/COL ERROR
    50/2 PL/SQL: Statement ignored
    51/2 PLS-00382: expression is of wrong type

    There could be data type mis-match within the time you re-compiled the program. Check the data type for which you are Inserting / Updating with the values you are actually using to populate.
    Note:
    Insert into TABLE1
    Select * from TABLE2.
    It is not advisible to have the above statement
    eventhough this will work as long as
    the fields in table TABLE1 and TABLE2 are same.
    Instead of "*" use the filed names.
    CRAMANA

  • PLS-00382

    Hi There,
    being really new to Oracle I was looking through the samples that are installed when you install Oracle. Under PACKAGES/SCOTT there is a single package that is valid, under PROCEDURES/SCOTT is a single procedure that is invalid, when compiling it gives the above errors.
    Could anyone shed some light into my darkness please.
    Thanks
    Steve

    The procdure source and error stack is.....
    SQL> create or replace procedure EmployeeInfoProc
    2 (empcursor IN OUT
    3 EmployeeInfo.EmployeeCursor)
    4 As
    5 Begin
    6 Open empcursor For
    7 select * from emp;
    8 End;
    9 /
    Warning: Procedure created with compilation errors.
    SQL> show errors
    Errors for PROCEDURE EMPLOYEEINFOPROC:
    LINE/COL ERROR
    6/1 PL/SQL: SQL Statement ignored
    7/1 PLS-00382: expression is of wrong type
    SQL>
    The version is 8.1.6 and the package and procedure are those that come with the software
    Thanks
    Steve

  • PLS-00382: expression is of wrong type

    Hi,
    oracle 9.2
    I have to write one simple procedure to retrieve some column records from the table.
    In the Begin... end block...I have written select statement
    Now, if i include all the columns in the select query then procedure gets compile without any error...but when I remove any one column or select specific columns in the select query of that procedure then I get below error..
    PLS-00382: expression is of wrong type
    can anybody explain ?
    Regards

    Hi,
    below has been defined in the declaration part and using the below defined cur3 for the OUT parameter.
         TYPE Rec3 IS RECORD
         col1          tab.col1%TYPE,
         col2          tab.col2%TYPE,
         col3          tab.col3%TYPE,
         col4          tab.col4%TYPE,
    TYPE Cur3 IS REF CURSOR RETURN Rec3 ;
    is it due to record type has been defined ?
    Regards

  • Problem with DECODE block in WHERE clause

    Hi,
    I'm facing problem with DECODE statement. I just simulated my problem in the simple way as follows. If I execute this following query, I should get "hello", but I'm not getting anything (ZERO rows returned).
    SELECT 'hello' FROM DUAL
    WHERE 'sample1' in (DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',
    2, '''sample4'', ''sample5'', ''sample6'''
    I think some problem is there in my WHERE clause.
    But When I'm exeucting the following query as a seperate query, then I'm getting the value of DECODE block properly, but didn;t understnad why its not returning the same way when I'm putting the same DECODE statement in WHERE clause.
    SELECT DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',
    2, '''sample4'', ''sample5'', ''sample6'''
    FROM DUAL;
    Please help me to get out of this problem. Thank you so much in advance.
    Thanks,
    Ramji.

    The value returned by SELECT DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',2, '''sample4'', ''sample5'', ''sample6''') FROM DUAL;
    'sample1', 'sample2', 'sample3' is a single string. Consider it x.
    SELECT 'hello' FROM DUAL WHERE 'sample1' in ( DECODE(1, 1, '''sample1'', ''sample2'', ''sample3''',2, '''sample4'', ''sample5'', ''sample6'''));
    is like SELECT 'hello' FROM DUAL WHERE 'sample1' in ('x');
    or
    SELECT 'hello' FROM DUAL WHERE 'sample1' in ('''sample1'', ''sample2'', ''sample3''') and not
    SELECT 'hello' FROM DUAL WHERE 'sample1' in ('sample1', 'sample2', 'sample3');
    For this same reason SELECT 'hello' FROM DUAL WHERE 'sample1' in (select '''sample1'', ''sample2'', ''sample3''' from dual);
    also does'nt work.
    Please use INSTR to find whether 'sample1' exists in the string 'sample1', 'sample2', 'sample3'.

  • Problems with decoding an latin1-encoded url

    Hi,
    i have a problem with decoding german umlaut-characters from an URL.
    I'm using Tomcat 5.5 on a Linux server and one on a windows machine for development. Both webapps have the same configurations.
    A servlet decodes the URL-String, parses it and stores the parsed data into a mysql-DB.
    For decoding the query-string i'm using org.apache.commons.codec.net.URLCodec.URLCodec.decode .
    Here's the code:
    String unparsedParameters = request.getQueryString();
    URLCodec codec = new URLCodec("ISO-8859-1");
    result = codec.decode(unparsedParameters);Here an example for a query-string: http://servername:8080/servlet/Import?Etwas%20wurde%20am%2025.08.2010%2010%3A16%3A50%20*ge%E4ndert*
    On the windows machine the word "*ge&auml;ndert*" is decoded correctly. But on the linux server i get "*ge?ndert*". It makes no difference if i write the result into the database or just into a logfile.
    Can anyone help?
    Thanks in advance.
    Edited by: sol1640 on Aug 26, 2010 5:59 AM

    Problem resolved.
    Instead of using the decode-method as described in my fist message now i'm doing the folowing:
    fURLDecodigCharset = "ISO8859-1";
    byte[] bytes = originalParam.getBytes(fURLDecodigCharset);
    byte[] decodeUrl = URLCodec.decodeUrl(bytes);
    result = new String (decodeUrl, fURLDecodigCharset);because the method "decode" decodes the string by using the defaultcharset. And that was the problem.
    >
    The default charset is determined during virtual-machine startup and typically depends upon the locale and charset of the underlying operating system.
    >
    Thats why i've got different behaviours on different systems.
    Thanks

  • PLS-00382 Type error in the select statement in the Cursor.

    Hi,
    I am trying to combine several different sql statements to form one large cursor for my java layer. I have attached the PL/SQL procedure that I am using and when I am trying to compile it is giving PLS-00382 error. Please help me.
    PL/SQL Code.
    CREATE OR REPLACE PROCEDURE test IS
    tmpVar NUMBER;
    TYPE checkRecord is RECORD (
    name1 APPS.EMCSV_R25_DIST_PROF_TBL.distmgrfname%TYPE,
         name2 APPS.EMCSV_R25_DIST_PROF_TBL.distmgrfname%TYPE,
         name3 APPS.EMCSV_R25_DIST_PROF_TBL.distmgrfname%TYPE,
         name4 APPS.EMCSV_R25_DIST_PROF_TBL.distmgrfname%TYPE,
         oppstatus1 APPS.EMCSV_R25_DIST_PROF_TBL.oppstatus%TYPE,
         oppcount1 APPS.EMCSV_R25_DIST_PROF_TBL.oppcount%TYPE,
         oppamount1 APPS.EMCSV_R25_DIST_PROF_TBL.oppamount%TYPE,
    oppstatus2 APPS.EMCSV_R25_DIST_PROF_TBL.oppstatus%TYPE,
         oppcount2 APPS.EMCSV_R25_DIST_PROF_TBL.oppcount%TYPE,
         oppamount2 APPS.EMCSV_R25_DIST_PROF_TBL.oppamount%TYPE,
         oppstatus3 APPS.EMCSV_R25_DIST_PROF_TBL.oppstatus%TYPE,
         oppcount3 APPS.EMCSV_R25_DIST_PROF_TBL.oppcount%TYPE,
         oppamount3 APPS.EMCSV_R25_DIST_PROF_TBL.oppamount%TYPE,
         oppstatus4 APPS.EMCSV_R25_DIST_PROF_TBL.oppstatus%TYPE,
         oppcount4 APPS.EMCSV_R25_DIST_PROF_TBL.oppcount%TYPE,
         oppamount4 APPS.EMCSV_R25_DIST_PROF_TBL.oppamount%TYPE);
    TYPE checkCur IS REF CURSOR RETURN checkRecord;
    checkCurVal checkCur;
    checkCurRec checkRecord;
    chechcurVal checkCur;
    NAME: test
    PURPOSE:
    REVISIONS:
    Ver Date Author Description
    1.0 3/8/2006 1. Created this procedure.
    NOTES:
    Automatically available Auto Replace Keywords:
    Object Name: test
    Sysdate: 3/8/2006
    Date and Time: 3/8/2006, 10:01:59 AM, and 3/8/2006 10:01:59 AM
    Username: (set in TOAD Options, Procedure Editor)
    Table Name: (set in the "New PL/SQL Object" dialog)
    BEGIN
    tmpVar := 0;
    OPEN checkCurVal FOR
    SELECT
         a.distmgrfname,
    a.distmgrlname,
         a.salesrepfname,
         a.salesreplname,
         cursor (
         SELECT b.oppstatus,
         b.oppcount,
         b.oppamount
         from APPS.EMCSV_R25_DIST_PROF_TBL b
         where b.userid = '100000001' AND
         b.reportid = 'ISARPTR25' AND
                   b.oppstatus = 'Open' AND
                   b.isoppstatusselected = 'Y'),
         cursor (
         SELECT c.oppstatus,
         c.oppcount,
         c.oppamount
         from APPS.EMCSV_R25_DIST_PROF_TBL c
         where c.userid = '100000001' AND
         c.reportid = 'ISARPTR25' AND
                   c.oppstatus = 'Commit' AND
                   c.isoppstatusselected = 'Y'),
         cursor (
         SELECT
         d.oppstatus,
         d.oppcount,
         d.oppamount
         from APPS.EMCSV_R25_DIST_PROF_TBL d
         where d.userid = '100000001' AND
         d.reportid = 'ISARPTR25' AND
                   d.oppstatus = 'Closed-Won' AND
                   d.isoppstatusselected = 'Y'),
         cursor (
         SELECT
         e.oppstatus,
         e.oppcount,
         e.oppamount
         from APPS.EMCSV_R25_DIST_PROF_TBL e
         where e.userid = '100000001' AND
         e.reportid = 'ISARPTR25' AND
                   e.oppstatus = 'Closed-Lost' AND
                   e.isoppstatusselected = 'Y')               
                   from APPS.EMCSV_R25_DIST_PROF_TBL a
         where a.userid = '100000001' AND
         a.reportid = 'ISARPTR25' AND
                   a.isoppstatusselected = 'Y' ;
         LOOP
         FETCH checkCurVal INTO checkCurRec;
              EXIT WHEN checkCurVal%NOTFOUND;
              DBMS_OUTPUT.PUT_LINE (checkCurRec.name1 ||
              checkCurRec.name2 ||
                                            checkCurRec.name3 ||
                                            checkCurRec.name4 ||
                                            checkCurRec.oppstatus1 ||
                                            checkCurRec.oppcount1 ||
                                            checkCurRec.oppamount1 ||
                                            checkCurRec.oppstatus2 ||
                                            checkCurRec.oppcount2 ||
                                            checkCurRec.oppamount2 ||
                                            checkCurRec.oppstatus3 ||
                                            checkCurRec.oppcount3 ||
                                            checkCurRec.oppamount3 ||
                                            checkCurRec.oppstatus4 ||
                                            checkCurRec.oppcount4 ||
                                            checkCurRec.oppamount4);                                        
         END LOOP;     
    END test;
    /

    Thanks for Replying.
    I am trying to build a cursor to fetch the records from the table. Table structure is something like this.
    reportid VARCHAR2(10) NOT NULL,
    distmgrid NUMBER DEFAULT 0,
    salesrepid NUMBER DEFAULT 0,
    distmgrfname VARCHAR2(40 CHAR) DEFAULT 'rfname',
    distmgrlname VARCHAR2(40 CHAR) DEFAULT 'rlname',
    salesrepfname VARCHAR2(40 CHAR) DEFAULT 'afname',
    salesreplname VARCHAR2(40 CHAR) DEFAULT 'aname',
    issalesrepselected CHAR(1 CHAR) DEFAULT 'Y',
    oppstatus VARCHAR2(40 CHAR) DEFAULT 'oppstatus',
    isoppstatusselected CHAR(1 CHAR) DEFAULT 'Y',
    oppcount NUMBER DEFAULT 0,
    oppamount NUMBER DEFAULT 0,
    oppquote NUMBER DEFAULT 0,
    Attribute1 VARCHAR2(10 CHAR),
    Attribute2 VARCHAR2(15 CHAR),
    Attribute3 NUMBER,
    Attribute4 NUMBER
    But from the above table, I am trying to build a report for which I need a cursor which I listed in the proc. Is it not possible to build a cursor within a cursor?
    Yes each individual cursor return only one row.

  • What is the use of profiles in oracle apps,could u pls explain with examples

    what is the use of profiles in oracle apps,could u pls explain with examples

    1b5595eb-fcfc-48cc-90d2-43ba913ea79f wrote:
    what is the use of profiles in oracle apps,could u pls explain with examples
    http://www.appspatrols.com/now/blog/understanding-profile-options-in-oracle-apps-oracle-e-business-suite
    http://www.oracle.com/pls/ebs121/search?word=Profile+Options&format=ranked&remark=quick_search
    Thanks,
    Hussein

  • Sql query for emp with decode

    How to get the required output with single query to acheive IF SAL>2500 and job='manager' then display job as 'seniormanager'.
    CREATE TABLE EMP(EMPNO NUMBER(4) NOT NULL,ENAME VARCHAR2(10),JOB VARCHAR2(9),MGR NUMBER(4),HIREDATE DATE,SAL NUMBER(7, 2),COMM NUMBER(7, 2),DEPTNO NUMBER(2));
    INSERT INTO EMP VALUES(7521, 'WARD', 'SALESMAN', 7698,TO_DATE('22-FEB-1981', 'DD-MON-YYYY'), 1250, 500, 30);
    INSERT INTO EMP VALUES(7566, 'JONES', 'MANAGER', 7839,TO_DATE('2-APR-1981', 'DD-MON-YYYY'), 2975, NULL, 20);
    INSERT INTO EMP VALUES(7698, 'BLAKE', 'MANAGER', 7839,TO_DATE('1-MAY-1981', 'DD-MON-YYYY'), 2850, NULL, 30);
    INSERT INTO EMP VALUES(7782, 'CLARK', 'MANAGER', 7839,TO_DATE('9-JUN-1981', 'DD-MON-YYYY'), 2450, NULL, 10);
    INSERT INTO EMP VALUES(7788, 'SCOTT', 'ANALYST', 7566,TO_DATE('09-DEC-1982', 'DD-MON-YYYY'), 3000, NULL, 20);
    IF SAL>2500 and job='manager' then display job as 'seniormanager'
    SELECT * FROM EMP
    expected output
    7521     WARD     SALESMAN         7698     22-FEB-81     1250     500     30
    7566     JONES     SENIORMANAGER     7839     02-APR-81     2975          20
    7698     BLAKE     SENIORMANAGER     7839     01-MAY-81     2850          30
    7782     CLARK     MANAGER          7839     09-JUN-81     2450          10
    7788     SCOTT     ANALYST           7566     09-DEC-82     3000          20

    Hi,
    The answer to "How do I ... using DECODE?", no matter how you fill in the blank, is "Don't use DECODE; use CASE instead." If you have to ask, then it's too complicated to do with DECODE.
    Here's one way using CASE:
    SELECT       empno, ename
    ,       CASE
               WHEN  job = 'MANAGER'
               AND   sal > 2500
               THEN  'SENIORMANAGER'
               ELSE  job
           END     AS d_job
    ,       mgr, hiredate, sal, comm, deptno
    FROM       emp
    ;If you really, really, really want to use DECODE:
    SELECT       empno, ename
    ,       DECODE ( job
                 , 'MANAGER'
               , DECODE ( SIGN (sal - 2500)
                        , 1
                     , 'SENIORMANAGER'
                     , job
               , job
               )     AS d_job
    ,       mgr, hiredate, sal, comm, deptno
    FROM       emp
    ;Nothing is literally too difficult to do in DECODE. Anything that case be done with CASE can also be done using DECODE, often using several times the amount of code. Bit which would you rther maintain: the CASE soltuion I posted first, of this DECODE soltuion. Which do you think will have more bugs? Which so you think will be faster? If you're using Oracle 8.1 (or higher) then don't use inefficient, high-maintenance code like this. Use CASE instead.
    Edited by: Frank Kulash on Dec 26, 2012 3:27 PM
    Added DECODE solution

  • Problem with decode!!!

    Hi guys,
    I have a problem with "decode"!
    How can I tell the decode expression
    that if a rowset don't exists --> then doing something.
    I've tried that with "NULL" but that don't works.
    here my code:
    I wanted that if tx.text doesn't exists then
    it returns fs.anlageschwerpunkt_lang, and otherwise
    it returns tx.Text.
    select
    decode(tx.Text,NULL,fs.anlageschwerpunkt_lang,tx.Text) Anlageschwerpunkt_1 from
    POI.Fondsstamm fs,
    Texte tx,
    Texttypstamm txy
    where
    tx.match='amfcomm'
    and tx.match=rtrim(fs.match)
    and tx.TEXTTYPID=txy.TEXTTYPID
    and txy.BEREICHSID=14
    and txy.texttyp='Marketingstrategie'
    I hope somebody of you can help me
    thanxx
    Schoeib

    I read Schoeibs question differently; no ROWS are being returned. In that case you cannot expect DECODE or any other function to do anything. Assuming that rows always exist in fs and txy and are only missing in tx, then you need an outer join. Note that the join of tx.match = rtrim(fs.match) has been altered to avoid outer joining to more than one table. As mentioned before, although the decode is OK, NVL could be used instead.
    select
    decode(tx.Text,NULL,fs.anlageschwerpunkt_lang,tx.Text) Anlageschwerpunkt_1 from
    POI.Fondsstamm fs,
    Texte tx,
    Texttypstamm txy
    where
    tx.match(+)='amfcomm'
    and rtrim(fs.match) = 'amfcomm'
    and tx.TEXTTYPID(+)=txy.TEXTTYPID
    and txy.BEREICHSID=14
    and txy.texttyp='Marketingstrategie'

  • ViewObjects Order by clause with DECODE

    Hello!
    I am using Jdeveloper 11g, version 11.1.1.2.0.
    The problem I'm having is this.
    If I use a DECODE statement in view objects ORDER BY clause, I get an error: "java.util.regex.PatternSyntaxException: Unmatched closing ')' near index 2".
    Let me give an example. I'll be using EmployeesView view object, which is using Employees entity from HR schema.
    This is a part of view objects XML.
    <ViewObject
    xmlns="http://xmlns.oracle.com/bc4j"
    Name="EmployeesView"
    Version="11.1.1.55.36"
    SelectList="Employees.EMPLOYEE_ID,
    Employees.FIRST_NAME,
    Employees.LAST_NAME,
    Employees.EMAIL,
    Employees.PHONE_NUMBER,
    Employees.HIRE_DATE,
    Employees.JOB_ID,
    Employees.SALARY,
    Employees.COMMISSION_PCT,
    Employees.MANAGER_ID,
    Employees.DEPARTMENT_ID"
    FromList="EMPLOYEES Employees"
    BindingStyle="OracleName"
    CustomQuery="false"
    PageIterMode="Full"
    UseGlueCode="false"
    OrderBy="Employees.MANAGER_ID">
    As you can see in this case, the Order by clause is very simple. This works like a charm.
    But, if put something like this "DECODE(Employees.MANAGER_ID, NULL, 1, 2)" in the Order by, I get an internal parsing error.
    I replicated this error on my home machine as well as on my work machine. I'm using the same version of Jdeveloper on both.
    Has anyone else stumbled upon this problem and solved it?
    Any thoughts would be greatly appreciated :)
    Kristjan

    The second example works, but the first one doesn't, unfortunately :/
    Also, the example I gave is unfortunately just that, a proof-of-concept example that there is a problem with DECODE if it is written inside the Order by clause.
    My real DECODE use case is a bit different. Like this: "DECODE(attribute, 'N', 1, 2) ASC".
    Since posting my original question, I did some research-by-example work and I discovered that this is not just a problem of DECODE, but more like a problem of brackets and commas.
    No database function that uses more than one parameter can be used in Order by clause.
    The reason is, if a function with more than one parameter is used, commas inside brackets have to be used. Something along the lines of: "database_function(param1, param2, ...)".
    The parser seems to have a problem with this kind of expressions.
    Is there a work around?
    Kristjan
    p.s.: Thank you for your quick response.

Maybe you are looking for