Petr Mensik
Petr Mensik

Reputation: 27496

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

Upvotes: 3

Views: 3320

Answers (2)

Petr Mensik
Petr Mensik

Reputation: 27496

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

Upvotes: 1

Adam Musch
Adam Musch

Reputation: 13583

Try using the --data-ascii switch on the curl command.

Upvotes: 0

Related Questions