Having problem loading text files into database as clob.
- Oracle version: Oracle Database 11g EE Release 11.2.0.2.0
- NLS_LANG: RUSSIAN_RUSSIA.CL8MSWIN1251
- NLS_CHARACTERSET: AL32UTF8
code to load text files:
DECLARE
L_BFILE BFILE;
L_CLOB CLOB;
file_name VARCHAR2(300);
BEGIN
file_name := 'test.txt';
L_BFILE := BFILENAME('DIR', file_name);
if (dbms_lob.fileexists(l_bfile) = 1) then
INSERT INTO TEST T
VALUES (SEQ_TEST.NEXTVAL, EMPTY_CLOB(),file_name) return r_data into l_clob;
L_BFILE := BFILENAME('DIR', file_name);
DBMS_LOB.FILEOPEN(L_BFILE, DBMS_LOB.FILE_READONLY);
DBMS_LOB.LOADFROMFILE(L_CLOB, L_BFILE, DBMS_LOB.GETLENGTH(L_BFILE));
DBMS_LOB.FILECLOSE(L_BFILE);
COMMIT;
end if;
END;
Text files are UTF8. After loading into database, I run select and get squares instead of russian characters. Please help!
Try LOADCLOBFROMFILE instead of LOADFROMFILE.
From the manual: