0

Hello I'm converting a string {"view": 1, "date": "2020-10-13", "cuit": 30000000007, "ptoVta": 10, "tipoCmp": 1, "nroCmp": 94, " amount ": 12100," currency ":" DOL "," ctz ": 65," tipoDocRec ": 80," nroDocRec ": 20000000001," tipoCodAut ":" E "," codAut ": 70417054367476} to base64 with the following function

CREATE OR REPLACE function CRISOL.returnsbase64 (ptext varchar2) RETURN VARCHAR2 IS
vResult varchar2 (1000);
BEGIN
    --Create encoded value
    vResult: = '';
    vResult: = utl_encode.text_encode (ptext, 'WE8ISO8859P1', UTL_ENCODE.BASE64);
     
- dbms_output.put_line (vResult);
    
    return vResult;

EXCEPTION
   WHEN OTHERS
   THEN
      RAISE_APPLICATION_ERROR (
         -20800,
         'Problems in the function returnsbase64 when converting:' || ptext || ' Error; '|| SQLERRM,
         TRUE);

END;

turns it well

e78idmVyIjoxLCJmZWNoYSI6IjIwMjAtMTAtMTMiLCJjdWl0IjozMDAwMDAwMDAw
NywicHRvVnRhIjoxMCwidGlwb0NtcCI6MSwibnJvQ21wIjo5NCwiaW1wb3J0ZSI6
MTIxMDAsIm1vbmVkYSI6IkRPTCIsImN0eiI6NjUsInRpcG9Eb2NSZWMiOjgwLCJu
cm9Eb2NSZWMiOjIwMDAwMDAwMDAxLCJ0aXBvQ29kQXV0IjoiRSIsImNvZEF1dCI6
NzA0MTcwNTQzNjc0NzZ9

but I need you to not have line breaks

Is there any solution?

jwvh
  • 50,871
  • 7
  • 38
  • 64
  • 1
    Line breaks in Base64 strings are ignored, they should not harm anything. Maybe check this one: https://stackoverflow.com/questions/3804279/base64-encoding-and-decoding-in-oracle/3806265#40852152 – Wernfried Domscheit Feb 19 '21 at 17:51

1 Answers1

0

The comment by @WernfriedDomscheit is right, the line breaks are ignored; but if you are dealing with an application that wants it as one nice long string, just do something like this, using the regexp_replace function to change carriage returns and line feeds to null:

regexp_replace
(
     utl_encode.text_encode (ptext, 'WE8ISO8859P1', UTL_ENCODE.BASE64)
   , chr(10) || '|'  || chr(13)
   , null
) 
Mark Stewart
  • 2,046
  • 4
  • 22
  • 32