Home > database >  The oracle database open the local file output garbled how to solve
The oracle database open the local file output garbled how to solve

Time:09-26

Use of oracle database, use pl/SQL developer to write a stored procedure, to open a local file, but the output of Chinese garbled words, the client and database code in Chinese no problem, I will turns into TXT file encoding UTF8 can display properly in the output Chinese, but because too much files individually no conversion code, database and other purposes also cannot modify the digital collections, so in a great god is there any way the stored procedure to realize temporary code conversion, file coding are GB2312, the following code
 
DECLARE
Fhandle utl_file. File_type;
Fp_buffer VARCHAR2 (4000);
File_name CLOB.
INT I;
The BEGIN
- file_name:='1. TXT';


Fhandle:=utl_file fopen (' WENSI_PRO ', '1. TXT', 'R');
File_name:=NULL;
I:=0;
WHILE I & lt;=5 LOOP

Utl_file. Get_line (fhandle fp_buffer);
File_name:=file_name | | CRH (13) | | fp_buffer;

IF fp_buffer='exit ($ret); 'THEN

The EXIT;

END the IF;

I:=I + 1;
END LOOP;

Dbms_output. Put_line (I);

Dbms_output. Put_line (file_name);

Utl_file. Fclose (fhandle);

The END;

CodePudding user response:

Reasons are already clear: inconsistent database and file character set
Solution only:
1. Change the database character set, this is not recommended,
2. Change the file character set, and only this, the best version of the game, GB2312 to utf-8
You can put all the name of the file saved to a temporary table, then use cycle: for rec in (select filename from the temporary table)
Open use: utl_file. Fopen (' WENSI_PRO, rec. Filename, 'R'); Can,

CodePudding user response:

This method is the method to realize I now

CodePudding user response:

If available, use it,

CodePudding user response:

But from the data source files are GB2312, every day a lot of the file, manually transcoding from volume

CodePudding user response:

reference 4 floor qq_38971349 response:
but from the data source files are GB2312, every day a lot file, manually transcoding from volume

This is not the problem of database, which requires the source system transcoding,
Sent the files into utf-8 send to you again,
  • Related