Created
January 13, 2015 17:49
-
-
Save AndrewLane/fec2cd17077bef46d58c to your computer and use it in GitHub Desktop.
NLS_SORT and Oracle 11g vs 12c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table sortme(data varchar2(1)); | |
insert into sortme(data) values('B'); | |
insert into sortme(data) values('a'); | |
insert into sortme(data) values('b'); | |
insert into sortme(data) values('A'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Query to be run is [SELECT data FROM (SELECT ROW_NUMBER() OVER (order by data ASC) | |
peta_rn, sortme.* from sortme) peta_paged WHERE peta_rn>0 AND peta_rn<=100] | |
Connection string is [User Id=qa3; password=*******; data source=emtqa01_web] | |
Data before 'alter session'... | |
---------- | |
A | |
B | |
a | |
b | |
Running [ALTER SESSION SET NLS_SORT=BINARY_AI] | |
Data after 'alter session'... | |
---------- | |
A | |
B | |
a | |
b | |
Connection string is [User Id=qa3iad; password=*******; data source=emtiadq1_web] | |
Data before 'alter session'... | |
---------- | |
A | |
B | |
a | |
b | |
Running [ALTER SESSION SET NLS_SORT=BINARY_AI] | |
Data after 'alter session'... | |
---------- | |
a | |
A | |
B | |
b | |
Press any key to continue . . . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Configuration; | |
using System.Text.RegularExpressions; | |
using Oracle.ManagedDataAccess.Client; | |
namespace SortDiagnostic | |
{ | |
class Program | |
{ | |
const string queryToRun = @"SELECT data FROM (SELECT ROW_NUMBER() OVER (order by data ASC) | |
peta_rn, sortme.* from sortme) peta_paged WHERE peta_rn>0 AND peta_rn<=100"; | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("Query to be run is [{0}]", queryToRun); | |
var connectionStrings = ConfigurationManager.AppSettings["connectionStringsToTry"].Split('|'); | |
foreach (var connStr in connectionStrings) | |
{ | |
TryDatabase(connStr); | |
} | |
} | |
static void TryDatabase(string connectionString) | |
{ | |
Console.WriteLine(); | |
Console.WriteLine(); | |
Console.WriteLine("Connection string is [{0}]", Regex.Replace(connectionString, "password=[^;]+;", "password=*******;")); | |
using (var conn = new OracleConnection { ConnectionString = connectionString }) | |
{ | |
conn.Open(); | |
using (var cmd = conn.CreateCommand()) | |
{ | |
Console.WriteLine("Data before 'alter session'..."); | |
Console.WriteLine("----------"); | |
SpitOutData(cmd); | |
//try to get the sorting to be accent insensitive | |
const string alterSessionSql = "ALTER SESSION SET NLS_SORT=BINARY_AI"; | |
cmd.CommandText = alterSessionSql; | |
cmd.ExecuteNonQuery(); | |
Console.WriteLine(); | |
Console.WriteLine("Running [{0}]", alterSessionSql); | |
Console.WriteLine(); | |
Console.WriteLine(); | |
Console.WriteLine("Data after 'alter session'..."); | |
Console.WriteLine("----------"); | |
SpitOutData(cmd); | |
} | |
} | |
} | |
static void SpitOutData(OracleCommand cmd) | |
{ | |
cmd.CommandText = queryToRun; | |
using (var reader = cmd.ExecuteReader()) | |
{ | |
while (reader.Read()) | |
{ | |
Console.WriteLine(reader.GetString(0)); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment