Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running SQL*Plus with bash causes wrong encoding

I have a problem with running SQL*Plus in the bash. Here is my code

#!/bin/bash

 curl http://192.168.168.165:8080/api_test/xsql/f_exp_order_1016.xsql > script.sql
 sqlplus /nolog << ENDL
 connect user/password 
 set sqlblanklines on
 start script.sql
 exit
 <<ENDL

I download the insert statements from our intranet, put it into sql file and run it through SQL*Plus. This is working fine. Only problem is that the file script.sql encoding looks like this application/x-empty; charset=binary (determined through file -bi). So it's causing inserting wrong characters to my DB which is something I really don't want.

So you could you please tell me how do I change the file encoding withou losing any data?And also any advices regarding to my script are welcomed, I am total newbie in Linux scripting:-)

I also tried change encoding with iconv and it didn't helped.

UPDATE

I don't know why but I deleted the file, run the script again few times and encoding is suddenly UTF-8, but characters are still broken both in file and DB, so it didn't solve anything

like image 832
Petr Mensik Avatar asked Mar 14 '26 23:03

Petr Mensik


1 Answers

Ok, the problem wasn't in the file (encoding was UTF-8 as it should be) but in the setting of Oracle NLS_LANG environmental variable. So solution was putting this line before executing SQL*Plus script

NLS_LANG="CZECH_CZECH REPUBLIC.UTF8" export NLS_LANG

like image 127
Petr Mensik Avatar answered Mar 17 '26 01:03

Petr Mensik