Using utl_encode.base64_encode within decode function

Hi, I want to use utl_encode.base64_encode within decode function. However, the result is not as expected.
select 'a', decode('a', '1', 'EQUAL to 1',
--'NOT EQUAL to 1'
utl_encode.base64_encode('a')
) result
from dual
A     RESULT
a     43673D3D
43673D3D is not a base64 encoded value of a
What is wrong with the sql?
Thanks

SQL> select 'a'
  2  ,      utl_encode.base64_encode(utl_raw.cast_to_raw('a')) raw_result
  3  ,      utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw('a'))) string_result
  4  from   dual;
' RAW_RESULT      STRING_RESULT
a 59513D3D        YQ==
1 row selected.Keep in mind that utl_encode.base64_encode returns a RAW and needs RAW input.
You'll probably need UTL_RAW to get your desired result.
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_encode.htm#CACECFHF

Similar Messages

  • Use netui tags within javascript function

    Is there anyway to use netui tags within a javascript function? I am trying to create a onChange event handler for a netui:select tag that will call a javascript function which will execute a few netui callMethod tags. The problem is that if the netui tags are embedded within a javascript function they are not translated into javascript. Is there some kind of function that I can wrap the embedded netui tags with so that they will be translated into javascript at runtime? Thanks.

    Hi,
    I am trying to embed JSP code within javascript
    t function, so that it can be called when the user
    leaves the page. No,you can't.
    JSP files are complied on server side while the javascript is the clint side code.
    if you really want to call the functio when the user leaves the page, you can call a function runs on the server side to set the session.
    regards

  • 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                           

  • Using select * into within a function

    What I'm wanting to do is to have a select query with many select fields and automatically create a new table (with the same schema) and insert the select result set in this new table.
    I can't seem to figure it out and doing the EXECUTE 'select * into dest_table from orig_table'; wouldn't work (not implemented yet).
    One reason I would like to do it this way is because the field attributes of orig_table may be different from one client to another.
    Thanks for any advice.

    Thanks very much.
    When I tried the execute immediate '...'; in the function I got an error stating: 'type "immediate" does not exist
    I tried to do some research on 'execute immediate' to see what might be the problem but couldn't find anything substantial to my cause.
    I just installed postgreSQL 8.2 this afternoon, and took all the installation defaults, so it may be something I need to configure.
    Anways, however, I just took the actual sql from the execute immediate call and that worked for me.
    Are there any pitfalls to doing it that way.
    Again, thanks for your quick and helpful reply.

  • 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

  • Using DECODE Function to change data

    I am trying to use the Decode function in a SQL statement to find a field that has a specific type, and when it finds that type, I want to blank out the results in a different field.
    For example:
    DECODE(ADDR_TYPE,'HOME',PHONE='') HOME_PHONE

    something like:
    SQL> with t as
      2   (select 219 id,
      3           'BUS' addr_type,
      4           '505-555-5555' phone
      5      from dual
      6    union
      7    select 219 id,
      8           'HOME' addr_type,
      9           null   phone
    10      from dual
    11    union
    12    select 220 id,
    13           'BUS' addr_type,
    14           '101-111-1111'   phone
    15      from dual
    16    union
    17    select 220 id,
    18           'HOME' addr_type,
    19           null   phone
    20      from dual
    21    union
    22    select 223 id,
    23           'BUS' addr_type,
    24           '202-222-2222'   phone
    25      from dual
    26    union
    27    select 224 id,
    28           'HOME' addr_type,
    29           '303-333-3333'   phone
    30      from dual
    31    union
    32    select 225 id,
    33           'BUS' addr_type,
    34           null   phone
    35      from dual
    36    union
    37    select 226 id,
    38           'HOME' addr_type,
    39           null   phone
    40      from dual)
    41  select a.id,
    42         a.addr_type,
    43         decode(a.addr_type,'BUS',phone,null) phone
    44    from (select id, addr_type, phone,
    45                 row_number() over (partition by id order by id, decode(addr_type,'BUS',1,2)) rn
    46            from t) a
    47   where a.rn = 1;
            ID ADDR PHONE
           219 BUS  505-555-5555
           220 BUS  101-111-1111
           223 BUS  202-222-2222
           224 HOME
           225 BUS
           226 HOME
    6 rows selected.
    SQL>

  • 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

  • Decode function - using comparison operators

    Can I use comparison operators in a decode function such as below:
    select tasknum, title, esthrs, assigndate,
    decode(assigndate, < '04-OCT-04', '--') accum_hrs
    from assignment
    thanks.

    Found my answer.

  • How to use a decode function

    I want to use the following with decode, recently started on BODS.
    Can you please provide the steps to use decode function
    in source tabke fieldname is ordid and in target fieldname is Orderid
    decode(Order_ID = 1709,lpad(Order_ID,7,'700'),Order_ID)
    thank you very much for the helpful i

    1) In the mapping tab of target column, click on Functions, select Miscellaneous Functions category, you can find decode function in it. Lpad can be found in String functions category.
    OR
    2) You can directly script this or paste this code at the mapping tab. In this case, remove the Order_ID from the script wherever used, drag and drop this column from the input schema of Query transform to avoid the syntax error. 
    Regards,
    Suneer

  • Using Like Operator in a decode function

    Hi,
    I am trying to find out if I can use the like operator in a decode function
    like:
    select decode(1234,like '%123%','123 is a match') from dual;
    this reults in error ORA-00936: missing expression
    is there any way to make this work?
    thank you

    SQL> ed
    Wrote file afiedt.buf
      1  WITH tbl AS (SELECT '201aaa' dt FROM DUAL UNION ALL
      2               SELECT '123bbb' dt FROM DUAL UNION ALL
      3               SELECT '567ccc' dt FROM DUAL UNION ALL
      4               SELECT 'ab123ddd' dt FROM DUAL
      5               )
      6  SELECT dt,CASE WHEN dt like '%123%' THEN 'Match'
      7         ELSE 'Not Matched'
      8         END With_case
      9        ,DECODE(REGEXP_SUBSTR(dt,'123'),NULL,'Not Match','Match')   With_Regexp
    10        ,DECODE(INSTR(dt,'123'),0,'Not Match','Match') With_Instr
    11        ,DECODE(REPLACE(dt,'123'),dt,'Not Match','Match') With_Replace
    12* FROM tbl
    SQL> /
    DT       WITH_CASE   WITH_REGE WITH_INST WITH_REPL
    201aaa   Not Matched Not Match Not Match Not Match
    123bbb   Match       Match     Match     Match
    567ccc   Not Matched Not Match Not Match Not Match
    ab123ddd Match       Match     Match     MatchEdited by: Saubhik on Jul 26, 2010 5:24 AM
    Edited by: Saubhik on Jul 26, 2010 5:40 AM
    Edited by: Saubhik on Jul 26, 2010 5:40 AM

  • Use of DECODE function in Discoverer 3.1

    Hi all,
    Is there any better way of using DECODE in Discoverer 3.1, i dont want to use that function in my Discoverer User edition or Admin ed.
    Many of my queries use the DECODE function.
    Your help is greatly appreciated.

    If you created an instance of your time class that you called myTime
    var myTime:Time = new Time(15,15,0);
    and later you wanted another instance with the same time you could write
    var myTime2:Time = myTime.clone()
    It is just there for convienience and doesn't have anything much to do with MVC

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

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

  • 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

Maybe you are looking for

  • Downloading All Rows in OBIEE 11g

    Hi all, I'm just starting using OBIEE 11g, and found out the difference between 11g and 10g on the downloading of query result from the Answers. In OBIEE 10g: (1) Default rows shown in the table view is 25. (2) Clicking on "show all rows" will show a

  • Suppliers report

    Hi, all, today I have received a simple [first look] task. Daily upload on FTP a suppliers report with items sold. Within the sold items, there are concession and own-bought, the report is necessary only for the concession suppliers. The concession f

  • BUG in a standard SYSMAN report

    i've created a global and public report that can monitoring ALL our web application from a standard sysman report (created by default) "Services Monitoring Dashboard", with the difference that no initial parameter is requested (this report can monito

  • Dreamweaver MX 2004 on SR MBP

    Anyone managed to get Dreamweaver MX 2004 (Academic edition, if it matters) running on the new MBPs under Rosetta? I've read of other people seemingly getting it to run, but for me it just bounces in the dock a few times and dies: Exception: EXCBADAC

  • Question about Cisco Tec support Rep Live chat issue .

    Hello guys, I recently just tried to do a session of live tech support on cisco web site about a issue trying to get my router to change the speed of the wireless connection from 54mbps to the potiental maxium of 300mbps. Well This is my second time