0

I need to save a html file as utf 8. This is not about . Is this possible? In short my procedure is like this:

CREATE OR REPLACE PROCEDURE MY_PROCEDURE
  IS

vFil  UTL_FILE.FILE_TYPE;
vFilNavn   varchar2(250);
vLinje  varchar2(32767);

begin
vFil := UTL_FILE.FOPEN ('MY_DIRECTORY',vFilNavn||'.tmp','w',32767);
UTL_FILE.PUT_LINE(vFil,vLinje);
    end;

   FOR recB in (select row from (my_html_content) );

loop 
vLinje := recB.Rad;
UTL_FILE.PUT_LINE(vFil,substr(vLinje,1,32767));    
end loop;   

UTL_FILE.FCLOSE(vFil);
UTL_FILE.FRENAME('MY_DIRECTORY',vFilNavn||'.tmp', 'MY_DIRECTORY',vFilNavn||'.html',TRUE);
Johnny Gunn
  • 51
  • 1
  • 1
  • 2

1 Answers1

1

Use UTL_FILE.FOPEN_NCHAR instead of UTL_FILE.FOPEN.

See Oracle documentation UTL_FILE:

UTL_FILE expects that files opened by UTL_FILE.FOPEN in text mode are encoded in the database character set. It expects that files opened by UTL_FILE.FOPEN_NCHAR in text mode are encoded in the UTF8 character set.

FOPEN_NCHAR Function

Even though the contents of an NVARCHAR2 buffer may be AL16UTF16 or UTF8 (depending on the national character set of the database), the contents of the file are always read and written in UTF8.

Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
  • I assume like this: vFil := UTL_FILE.FOPEN_NCHAR ('MY_DIRECTORY',vFilNavn||'.tmp','w',32767); And also: UTL_FILE.PUT_NCHAR(vFil,substr(vLinje,1,32767)); ? Still I'm getting ORA-29298 Character set mismatch – Johnny Gunn Apr 07 '19 at 16:57
  • Can you make a simple select on the data. Is the output correct? – Wernfried Domscheit Apr 07 '19 at 17:32
  • Yes, it works fine without NCHAR. It is a html-code into varchar2. And the web-page also are as accepted. But the web-designer need the file to be saved as utf-8. My regional settings are Norwegian. – Johnny Gunn Apr 10 '19 at 08:16