0

I am trying to upload some string values into an Oracle table by means of powershell. However when I upload strings directly some characters are shown up like ? in the table.

Actually, I first parse a text and retrieve some results through regex as below:

if($wiki_link -match "http:\/\/en\.wikipedia\.org\/wiki\/(.*)") {$city = $matches[1]}

Then I wanna upload this $city variable into a table as below:

[System.Reflection.Assembly]::LoadWithPartialName("System.Data.OracleClient")
$connectionString = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(Host=xxxxxxxxx)(Port=1521)))(CONNECT_DATA=(SERVER = DEDICATED) (SERVICE_NAME =xxxxx)));user id=xxxxxx;password=xxxxx"
$connection = New-Object System.Data.OracleClient.OracleConnection($connectionString)
$connection.Open()
$cmd2=$connection.CreateCommand()
$cmd2.CommandText="insert into mehmet.goo_region (city) values ('$city')"
$rdr2=$cmd2.ExecuteNonQuery()

When I apply this method, the city named Elâzığ appears as Elaz?? in the table cell.

I guess I have to convert string into UTF-8 but I could not find a solution through web.

Thanks in advance...

mlee_jordan
  • 772
  • 4
  • 18
  • 50

1 Answers1

0

Try this, it should work:

$u = New-Object System.Text.UTF8Encoding
$s = $u.GetBytes("YourStringGoesHere")
$u.GetString($s)    ## this is your UTF-8 string

So your code becomes

$u = New-Object System.Text.UTF8Encoding
$s = $u.GetBytes($city)
$utf8city = $u.GetString($s)
Raf
  • 9,681
  • 1
  • 29
  • 41
  • Thanks @Raf for your response but I still get the same result even when I try your suggestion. – mlee_jordan Feb 27 '14 at 16:34
  • Then it looks like your Oracle client is bastardising the string, maybe this will help: http://stackoverflow.com/questions/1192281/how-to-save-unicode-data-to-oracle – Raf Feb 27 '14 at 17:09