Skip to Main Content
  • Questions
  • how to using Syntax Notation Version 1 (ASN.1). a simple version of Basic Encoding Rules (BER). encode

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, mohamd.

Asked: December 09, 2021 - 9:22 am UTC

Last updated: December 10, 2021 - 3:50 am UTC

Version: oracle 11g or oracle 19c

Viewed 1000+ times

You Asked

declare
massage varchar2(200) ;
massage2 varchar2(200) ;
massage_row RAW(32767); 
begin
massage:= '010c426f6273205265636f726473020F3331303132323339333530303030330314323032322d30342d32355431353a33303a30305a0407313030302e303005063135302e3030';
----massage_row:= utl_raw.cast_to_raw(massage);
 --massage:=utl_encode.text_encode(massage,'UTF8',UTL_ENCODE.BASE64);

massage:=utl_encode.text_encode (massage,'WE8ISO8859P1', UTL_ENCODE.BASE64);
--massage:=utl_encode.text_encode (massage,'UTF8', UTL_ENCODE.BASE64);
-- (massage,'WE8ISO8859P1', UTL_ENCODE.BASE64);
--massage:=utl_raw.cast_to_varchar2(massage);
--massage:=base64encode1(massage);
 -- FOR i IN 0 .. massage - 1  LOOP
 --   massage2 := massage2 || UTL_RAW.cast_to_varchar2(UTL_ENCODE.base64_encode(substr(massage, i , i  + 1)));
 -- END LOOP;
  
insert into massage VALUES (massage);
commit ;
end ;



this code give my result "MDEwYzQyNmY2MjczMjA1MjY1NjM2ZjcyNjQ3MzAyMEYzMzMxMzAzMTMyMzIzMzM5
MzMzNTMwMzAzMDMwMzMwMzE0MzIzMDMyMzIyZDMwMzQyZDMyMzU1NDMxMzUzYTMz
MzAzYTMwMzA1YTA0MDczMTMwMzAzMDJlMzAzMDA1MDYzMTM1MzAyZTMwMzA="

but i need to have "AQxCb2JzIFJlY29yZHMCDzMxMDEyMjM5MzUwMDAwMwMUMjAyMi0wNC0yNVQxNTozMDowMFoEBzEwMDAuMDAFBjE1MC4wMA=="

and Connor said...

Take a look here

https://asktom.oracle.com/pls/apex/asktom.search?tag=decoding-from-base64

You need to be careful with string sizes when encoding

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library