Domanda

Ho una tabella in un database Oracle come questo

ID   | LABEL
------------
 1   |  label alpha 1
 2   |  label alpha 2
 3   |  label alpha a

quando faccio un prescelto in un'applicazione come Squirrel in questo modo:

select * FROM MA_TABLE order by LABEL asc

I ottenere:

ID   | LABEL
------------
 1   |  label alpha 1
 2   |  label alpha 2
 3   |  label alpha a

che va bene!

Ma quando eseguo la stessa richiesta utilizzando MyBatis:

<select id="selectMaTable" resultMap="resultMap" >
  Select * FROM MA_TABLE order by LABEL asc
</select>

I ottenere:

ID   | LABEL
------------
 3   |  label alpha a
 1   |  label alpha 1
 2   |  label alpha 2

I caratteri alfabetici vengono prima i caratteri numerici ... perché ??

Grazie in anticipo,

Antoine

Ps: sto usando org.mybatis: mybatis: Vaso: 3.0.5 e com.oracle:ojdbc6:jar:11.2.0.2.0 per l'accesso al database

Modifica: questo aiuto legato a me un po 'anche

Grazie alla osservazione di Soulcheck, ho scoperto che se cambio l'ordine dalla clausola ORDER BY con NLSSORT (ATL_SIT.ATL_SIT_LIB, 'NLS_SORT = BINARIO') funziona ...

Qualcuno sa come forzare NLS_SORT = BINARIO con myBatis? (Si è già impostato sul mio database Oracle in NLS_DATABASE_PARAMETERS)

È stato utile?

Soluzione

It looks like it might be a locale issue. Connect with squirrel and check what NLS_LANG it sets, then check what locale uses your java app. Another parameter that can influence sort is NLS_SORT.

You can check the value of both by issuing:

select parameter,value from NLS_DATABASE_PARAMETERS where parameter in('NLS_LANGUAGE','NLS_SORT');

Then you can test it in java by using:

Locale.getDefault()

and set it by using:

Locale.setDefault(Locale)

or by adding jvm parameters:

-Duser.country=en -Duser.language=en

edit

spring forums recommend creating a logon trigger which sets NLS_SORT environmental variable on user logon. It's not MyBatis, but jdbc anyway so should work in your case.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top