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!

Similar Messages

  • 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

  • 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

  • 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

  • How to use "Rank" function  in Oracle?

    I need to display Top 15 records by using rank function.
    Here is my query...I need to pull top 15 FAQ's using the below query.. How can I use RANK function to display the Top 15 FAQ"s in the list.
    Select  distinct SUb1.FAQ,Sub1.FAQ_Hits,GU.display_Name_FMLS as displayname,ev.ParentLinkrecordid,ev.userid from User GU
    Join Event ev
    ON LOWER (ev.userid) IN (LOWER (GU.lanid), LOWER (Gu.racfid))
    Join (Select distinct sm.stem as FAQ,Sum(ev.Eventresults) as FAQ_Hits,ev.ParentLinkrecordid as Topic_ID from Event ev
    Join SubjectMatter sm
    ON (TO_CHAR (sm.smrecordid) = ev.eventdetail1) AND ev.eventdetail1 IS NOT NULL AND sm.smtype = 1
    Where (Upper(ev.eventsubtype) in (Upper('FAQ'),Upper('OPENFAQ')))
    AND TO_DATE (eventdatetime, 'yyyy-mm-dd hh24:mi:ss') >= TO_DATE ('20100601', 'yyyymmdd')
    and TO_DATE (eventdatetime, 'yyyy-mm-dd hh24:mi:ss') <= TO_DATE ('20100831', 'yyyymmdd')
    Group by sm.stem,ev.Parentlinkrecordid
    order by FAQ )sub1
    ON Sub1.Topic_ID = ev.ParentLinkrecordid)

    A few bits that I noticed in the query ...
    in (Upper('FAQ'),Upper('OPENFAQ'))1) Do you really a upper for a string which is already in upper case.
    Select distinct sm.stem as FAQ,Sum(ev.Eventresults) as FAQ_Hits,ev.ParentLinkrecordid as Topic_ID2) Do you need a distinct when you are using a GROUP function viz. SUM ?
    You rank query is as follows, I am not very good at the ANSI style JOIN so changed it slightly ... :-)
    Also notice the usage rank function in the "sub1" query.
    select distinct sub1.faq,
                    sub1.faq_hits,
                    gu.display_name_fmls as displayname,
                    ev.parentlinkrecordid,
                    ev.userid
    from user gu, event ev,
      (select rank() over (order by sum(ev.eventresults) desc) rnk,
              sum(ev.eventresults) as faq_hits,
              sm.stem as faq,         
              ev.parentlinkrecordid as topic_id
         from event ev, subjectmatter sm
        where (to_char(sm.smrecordid) = ev.eventdetail1)
          and ev.eventdetail1 is not null
          and sm.smtype = 1
          AND upper(ev.eventsubtype) in ('FAQ', 'OPENFAQ')
          and to_date(eventdatetime, 'yyyy-mm-dd hh24:mi:ss') >= to_date('20100601', 'yyyymmdd')
          and to_date(eventdatetime, 'yyyy-mm-dd hh24:mi:ss') <= to_date('20100831', 'yyyymmdd')
        group by sm.stem, ev.parentlinkrecordid
        order by faq) sub1
    where lower(ev.userid) in (lower(gu.lanid), lower(gu.racfid))
      and sub1.topic_id = ev.parentlinkrecordid)
      and sub1.rnk <= 15;Like mentioned above, some sample data would have helped.

  • How to use DLL function in Oracle Forms 5.0?

    for instance, the FindWindowA function in "user32.dll"
    please advise, thanks

    Take a look at ORA_FFI package.

  • How to use decode concept in htp.p?

    Hi All,
    How to use decode function in htp.p syntax?
    Thanks,
    Anoo..

    Hi,
    Could you please give more details on what you like to achieve? Decode function works only in sql query.
    You can first do sql query, and then do htp.p.
    Or you can use PL/SQL IF or CASE statements.
    You can also create custom decode function if you need.
    Regards,
    Oleg

  • How to use complex function as condition in Oracle Rule Decision Table?

    How to use complex function as condition in Oracle Rule Decision Table?
    We want to compare an incoming date range with the date defined in the rules. This date comparison is based on the input date in the fact & the date as defined for each rule. Can this be done in a decision table?

    I see a couple of problems here.
    First, what you posted below is not a syntactically valid query. It seems to be part of a larger query, specifically, this looks to be only the GROUP BY clause of a query.
    Prabu ammaiappan wrote:
    Hi,
    I Have a group function in the Query. Below is the Query i have used it,
    GROUP BY S.FREIGHTCLASS,
    R.CONTAINERKEY,
    S.SKU,
    S.DESCR ||S.DESCRIPTION2,
    S.PVTYPE,
    RD.LOTTABLE06,
    R.WAREHOUSEREFERENCE,
    RD.TOLOC,
    R.ADDWHO,
    R.TYPE,
    S.CWFLAG,
    S.STDNETWGT,
    S.ORDERUOM,
    R.ADDDATE,
    C.DESCRIPTION,
    (CASE WHEN P.POKEY LIKE '%PUR%' THEN 'NULL' ELSE to_char(P.PODATE,'dd/mm/yyyy') END),
    NVL((CASE WHEN R.ADDWHO='BOOMI' THEN RDD.SUPPLIERNAME END),SS.COMPANY),
    RDD.BRAND,
    S.NAPA,
    RD.RECEIPTKEY,
    R.SUSR4,
    P.POKEY,
    RDD.SUSR1,
    r.STATUS, DECODE(RDD.SUSR2,' ',0,'',0,RDD.SUSR2),
    rd.SUSR3Second, the answer to your primary question, "How do I add a predicate with with a MAX() function to my where clause?" is that you don't. As you discovered, if you attempt to do so, you'll find it doesn't work. If you stop and think about how SQL is processed, it should make sense to you why the SQL is not valid.
    If you want to apply a filter condition such as:
    trunc(max(RD.DATERECEIVED)) BETWEEN TO_DATE('01/08/2011','DD/MM/YYYY') AND TO_DATE('01/08/2011','DD/MM/YYYY')you should do it in a HAVING clause, not a where clause:
    select ....
      from ....
    where ....
    group by ....
    having max(some_date) between this_date and that_date;Hope that helps,
    -Mark

  • How can we use DECODE function in where clause.

    Hi Guys,
    I have to use DECODE function in where clause.
    like below
    select * from tab1,tab2
    where a.tab1 = b.tab2
    and decode(code, 'a','approved')
    in this manner its not accepting?
    Can any one help me on this or any other aproach?
    Thanks
    -LKR

    >
    I am looking for to decode the actual db value something in different for my report.
    like if A then Accepted
    elseif R then Rejected
    elseif D then Denied
    these conditions I have to check in where clause.
    >
    what are you trying to do?
    may be you are looking for
    select * from tab1,tab2
    where a.tab1 = b.tab2
    and
       (decode(:code, 'A','Accepted') = <table_column>
        or
        decode(:code, 'R','Rejected') = <table_column>
       or
        decode(:code, 'D','Denied') = <table_column>
       )

  • Oracle:how to use max() function in case expression

    how to use max() function in case expression, Please explain with any example

    Hope this helps and should be self explanatory
    with t as
    (select 1 col,100 col2 from dual union
    select 2 ,100 from dual union
    select 2 ,200 from dual union
    select 3,100  from dual union
    select 3,200  from dual  )
    select col, case when max(col2)=100 then 'with 100 range'
    when  max(col2)=200 then 'with 200 range' end  from t group by col

  • Using decode function without negative values

    Hi friends
    I am using oracle 11g
    I have at doubt regarding the following.
    create table Device(Did char(20),Dname char(20),Datetime char(40),Val char(20));
    insert into Device values('1','ABC','06/13/2012 18:00','400');
    insert into Device values('1','abc','06/13/2012 18:05','600');
    insert into Device values('1','abc','06/13/2012 18:55','600');
    insert into Device values('1','abc','06/13/2012 19:00','-32768');
    insert into Device values('1','abc','06/13/2012 19:05','800');
    insert into Device values('1','abc','06/13/2012 19:10','600');
    insert into Device values('1','abc','06/13/2012 19:15','900');
    insert into Device values('1','abc','06/13/2012 19:55','1100');
    insert into Device values('1','abc','06/13/2012 20:00','-32768');
    insert into Device values('1','abc','06/13/2012 20:05','-32768');
    Like this I am inserting data into table for every 5 minutes Here i need the result like
    output:
    Dname 18:00 19:00 20:00
    abc 400 -32768 -32768
    to retrieve this result i am using decode function
    SELECT Dname,
    MAX(DECODE ( rn , 1,val )) h1,
    MAX(DECODE ( rn , 2, val )) h2,
    FROM
    (SELECT Dname,Datetime,row_number() OVER
    (partition by Dname order by datetime asc) rn FROM Device
    where substr(datetime,15,2)='00' group by Dname.
    According to above data expected result is
    Dname 18:00 19:00 20:00
    abc 400 600(or)800 1100
    This means I dont want to display negative values instead of that values i want to show previous or next value.
    Edited by: 913672 on Jul 2, 2012 3:44 AM

    Are you looking for something like this?
    select * from
    select dname,
           datetime,
           val,
           lag(val) over (partition by upper(dname) order by datetime) prev_val,
           lead(val) over (partition by upper(dname) order by datetime) next_val,
           case when nvl(val,0)<0  and lag(val) over (partition by upper(dname) order by datetime) >0 then
             lag(val) over (partition by upper(dname) order by datetime)
           else 
             lead(val) over (partition by upper(dname) order by datetime)
           end gt0_val
    from device
    order by datetime
    where substr(datetime,15,2)='00';Please take a look at the result_column gt0_val.
    Edited by: hm on 02.07.2012 04:06

  • How to  use data function using characterstics variable for calculation on

    how to  use data function using characterstics variable for calculation on  attribute as key figure

    Hi Gayatri
    Did you not see my answer for CASE because CASE does indeed offer the use of the BETWEEN clause, but DECODE does not. Let me give you a little synopsis of DECODE.
    In its most simple form it takes 4 values and looks like this: DECODE(A, B, C, D)
    This essentially means, IF A = B THEN C ELSE D
    The trick to solving BETWEEN in a DECODE is to work out algoriths where A = B. Because we don't know how many values are between 00 and 99, although I could guess there were 100 we could of course have 100 parts in the DECODE but that would be awful. How about if we look at it another way and say this:
    IF PART_NUMBER < 'SDK00' THEN pay_amount
    ELSE IF PART_NUMBER > 'SDK99' THEN pay_AMOUNT
    ELSE pay_amount + 100
    This statement only had 2 hard coded values, but how to make DECODE work with less than? Easy, we use the LEAST function. The LEAST function takes 2 values and returns the one with the lowest value. So I use LEAST(PART_NUMBER, 'SDK00') then whenever the PART_NUMBER is lower than SDK00 it will be true. A similar situation exists for the opposite function GREATEST. Putting all of this together then, you can do this:
    DECODE(PART_NUMBER, GREATEST(PART_NUMBER, 'SDK00'), DECODE(PART_NUMBER, LEAST(PART_NUMBER, 'SDK99'), PAY_AMOUNT * 100, PAY_AMOUNT), PAY_AMOUNT)
    In English this can be read as follows:
    IF the PART_NUMBER is greater than or equal to SDK00 and the PART_NUMBER is less than or equal to SDK99 THEN PAY_AMOUNT x 100 ELSE 0
    Best wishes
    Michael

  • How to use FPRINT32 function in MF cobol

    Hi,
    How to use FPRINT32 function to check the value of any buffer defined in MF cobol code.
    When we tried, CALL FPRINT32 USING OUTPUT-FML
    OUTPUT-FML is a buffer which is defined in our cobol code.
    We are getting below error.
    ld: 0711-224 WARNING: Duplicate symbol: p_xargc
    ld: 0711-224 WARNING: Duplicate symbol: p_xargv
    ld: 0711-224 WARNING: Duplicate symbol: .tpsvrdone
    ld: 0711-224 WARNING: Duplicate symbol: .tpsvrinit
    ld: 0711-224 WARNING: Duplicate symbol: TPSVRINIT
    ld: 0711-224 WARNING: Duplicate symbol: .TPSVRINIT
    ld: 0711-224 WARNING: Duplicate symbol: tpsvrinit
    ld: 0711-224 WARNING: Duplicate symbol: tpsvrdone
    ld: 0711-224 WARNING: Duplicate symbol: .userlog
    ld: 0711-224 WARNING: Duplicate symbol: userlog
    ld: 0711-224 WARNING: Duplicate symbol: p_xrcfg
    ld: 0711-224 WARNING: Duplicate symbol: p_xrc
    ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
    ld: 0711-317 ERROR: Undefined symbol: .FPRINT32
    CMDTUX_CAT:1832: ERROR: can't execute cobcc -I$TUXDIR/include -L/lib -lpthreads -L/usr/local/opt/oracle/product/ostl133/lib/ -lclntsh -lrtl -lld -lm /lib/crt0_64.o -ldl -lc -lm -lpthreads -lodm -lbsd_r -lld -lperfstat -lm -lc_r -lpthreads /usr/local/opt/oracle/product/ostl133/precomp/lib/cobsqlintf.o /usr/local/opt/oracle/product/ostl133/lib/libclntsh.a -C linkcount=1024 -o BS-f804a.c -L${TUXDIR}/lib TPSVRINIT.o -brtl -qstaticinline -lcobatmis -ltux -lbuft -lfml -lfml32 -lengine -lpthread
    Please help in this regard,
    Thanks

    Hi,
    As far as I know there is no FPRINT32 function in the Tuxedo COBOL interface.
    The ATMI COBOL Function Reference for the latest Tuxedo 11.1.1.2.0 release at
    http://download.oracle.com/docs/cd/E18050_01/tuxedo/docs11gr1/rf3cbl/rf3cbl.html shows FINIT, FINIT32, FVFTOS, FVFTOS32, FVSTOF, and FVSTOF32 as the only supported COBOL interface functions related to FML.
    COBOL is better suited to dealing with the fixed record structure of views than with the variable record format of FML buffers. The COBOL interface offers functions to initialize and FML buffer and to convert an FML buffer to and from a VIEW so that preexisting services taking FML buffers as input or output parameters can be called, but the expectation is that the COBOL program will conver the FML buffer to a VIEW before accessing it.
    It is possible to call the Tuxedo C interface Fprint32() function from COBOL using standard interlanguage calling conventions. Also, you may want to check with other developers on your project to see if someone may have already implemented such a function.
    Regards,
    Ed

  • How to Use Decode for manipulating time

    How can i use Decode function to manipulate time...
    Example
    suppose ive employee and his time in...i want to display status field by using decode,which reflects if that employee came after 09:15:00 the status='L' else this will print 'P'
    i tried this
    SELECT pin_code,DECODE( to_char(ACCESS_TIME,'HH24:MI:SS'>'09:15:00','l','P'))STATUS
    FROM ATTENDANCE_REG
    this query hasn't work...
    waiting for reply
    Regards
    Danish Hayder

    SQL> select case when to_number(to_char(sysdate,'sssss')) > 33300 then 'L'
      2              else 'P' end status
      3  from dual;
    S
    L
    1 row selected.                                                                                                                                                                                                                                                                                                                                           

  • How to use nullif function

    hi frs
    how to use nullif function.
    i have used like below
    <?FTE_COUNT div nullif (FT_COUNT+PT_COUNT+PI_COUNT+TEMP_COUNT+I_COUNT),0)?>but not getting it.
    help pls.

    Hi,
    try <?xdofx: FTE_COUNT div decode(FT_COUNT+PT_COUNT+PI_COUNT+TEMP_COUNT+I_COUNT,0,null,FT_COUNT+PT_COUNT+PI_COUNT+TEMP_COUNT+I_COUNT)?>
    Regards
    Rainer

Maybe you are looking for