Précédent   Forum des professionnels en informatique > Bases de données > Firebird > SQL
SQL Forum d'entraide sur le SQL pour Firebird
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 29/12/2010, 17h23   #1
Inscrit
 
Inscription : mai 2004
Messages : 758
Détails du profil
Informations forums :
Inscription : mai 2004
Messages : 758
Points : 287
Points : 287
Par défaut Problème de tri pour un varchar

Bonjour à tous

voici mon problème, dans ma base de donnée sous firebird 2.5
j'ai les données suivantes de type varchar en ISO5559_1, voici l'odre de tri que je veux avoir :
Code :
1
2
3
4
5
6
7
8
9
10
 
AS/GF/1
AS/GF/2
AS/GF/3
AS/GF/4
AS/GF/5
AS/GF/10
AS/GF/11
AS/GF/20
AS/GF/21
et voila l'ordre de tri que j'ai sous mon editeur IBmanager
Code :
1
2
3
4
5
6
7
8
9
10
11
 
 
AS/GF/1
AS/GF/10
AS/GF/10
AS/GF/11
AS/GF/20
AS/GF/21
AS/GF/3
AS/GF/4
AS/GF/5
comment faire ?
merci pour votre aide
devalender est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 29/12/2010, 18h35   #2
Expert Confirmé

 
Homme Philippe Makowski
Consultant spécialité Firebird
Inscription : mai 2002
Messages : 2 213
Détails du profil
Informations personnelles :
Nom : Homme Philippe Makowski
Âge : 49
Localisation : France

Informations professionnelles :
Activité : Consultant spécialité Firebird
Secteur : Conseil

Informations forums :
Inscription : mai 2002
Messages : 2 213
Points : 3 315
Points : 3 315
soit changer AS/GF/1
pour AS/GF/01

soit utiliser cette fonctionnalité
http://firebirdsql.org/rlsnotesh/rls...5-intl-numsort
__________________
Philippe Makowski
IBPhoenix - Firebird
Membre de l'April
makowski est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/01/2011, 10h55   #3
Inscrit
 
Inscription : mai 2004
Messages : 758
Détails du profil
Informations forums :
Inscription : mai 2004
Messages : 758
Points : 287
Points : 287
Bonne et heureuse Année 2011 à tous
Citation:
soit changer AS/GF/1
pour AS/GF/01
impossible car les données sont déja utliser pour un autre processus.
Citation:
soit utiliser cette fonctionnalité
http://firebirdsql.org/rlsnotesh/rls...5-intl-numsort
j'ai bien lu mais je ne vois pas comment utiliser concretement pour mon cas.
parce que dans mon cas j'utilise le ISO5559_1

Merçi
devalender est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/01/2011, 11h40   #4
Membre Expert
 
Avatar de Barbibulle
 
Frédéric
Inscription : octobre 2002
Messages : 1 722
Détails du profil
Informations personnelles :
Nom : Frédéric
Âge : 42

Informations forums :
Inscription : octobre 2002
Messages : 1 722
Points : 2 025
Points : 2 025
Citation:
Envoyé par devalender Voir le message
j'ai bien lu mais je ne vois pas comment utiliser concretement pour mon cas.
parce que dans mon cas j'utilise le ISO5559_1 :calim2
Je pense que tu parles plutot du ISO8859_1.

Pour ce qui est de la réponse de Makowski, il te faut créer un nouveau type de tri :
Code :
1
2
CREATE collation unicode_num FOR utf8
FROM unicode 'NUMERIC-SORT=1';
Après tu n'as plus qu'a l'utiliser :

Code :
1
2
SELECT ColonneISO8859_1 FROM matable
ORDER BY ColonneISO8859_1 collate unicode_num;
Je n ai pas encore installé fb 2.5 donc je n ai pas testé.

Peut être te faudra t'il faire un cast avant.

Code :
1
2
3
Select ColonneISO8859_1 from matable
order by cast(ColonneISO8859_1 as 'le même type que la colonne ColonneISO8859_1' character set utf8) collate unicode_num
;
Je me demande si type of column fonctionne ici (hum... va falloir que je l'installe cette 2.5) :
Code :
1
2
3
SELECT ColonneISO8859_1 FROM matable
ORDER BY cast(ColonneISO8859_1 AS TYPE OF COLUMN matable.ColonneISO8859_1 CHARACTER SET utf8) collate unicode_num
;
Par contre je ne suis pas certain qu'il va utiliser l'index si tu en as un sur cette colonne.
Il te faudra créer un index avec le bon collate.
Barbibulle est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/01/2011, 11h38   #5
Inscrit
 
Inscription : mai 2004
Messages : 758
Détails du profil
Informations forums :
Inscription : mai 2004
Messages : 758
Points : 287
Points : 287
excuser moi pour ma reponse tardive , j'ai access a internet a plein temps
merci pour ta reponse je pense que je vais m'y mettre et ensuite revenir pour poster les resultats
devalender est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/01/2011, 16h59   #6
Expert Confirmé

 
Homme Philippe Makowski
Consultant spécialité Firebird
Inscription : mai 2002
Messages : 2 213
Détails du profil
Informations personnelles :
Nom : Homme Philippe Makowski
Âge : 49
Localisation : France

Informations professionnelles :
Activité : Consultant spécialité Firebird
Secteur : Conseil

Informations forums :
Inscription : mai 2002
Messages : 2 213
Points : 3 315
Points : 3 315
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
SQL> CREATE TABLE TESTTRI (COLA VARCHAR(10) CHARACTER SET ISO8859_1 COLLATE FR_FR);
SQL> INSERT INTO TESTTRI (COLA) VALUES ('AS/GF/1');
SQL> INSERT INTO TESTTRI (COLA) VALUES ('AS/GF/2');
SQL> INSERT INTO TESTTRI (COLA) VALUES ('AS/GF/3');
SQL> INSERT INTO TESTTRI (COLA) VALUES ('AS/GF/4');
SQL> INSERT INTO TESTTRI (COLA) VALUES ('AS/GF/5');
SQL> INSERT INTO TESTTRI (COLA) VALUES ('AS/GF/10');
SQL> INSERT INTO TESTTRI (COLA) VALUES ('AS/GF/11');
SQL> INSERT INTO TESTTRI (COLA) VALUES ('AS/GF/20');
SQL> INSERT INTO TESTTRI (COLA) VALUES ('AS/GF/21');
SQL> COMMIT;
SQL> SELECT COLA FROM TESTTRI ORDER BY COLA;
 
COLA       
========== 
AS/GF/1    
AS/GF/10   
AS/GF/11   
AS/GF/2    
AS/GF/20   
AS/GF/21   
AS/GF/3    
AS/GF/4    
AS/GF/5    
 
SQL> CREATE collation unicode_num FOR utf8
CON> FROM unicode 'NUMERIC-SORT=1';
SQL> COMMIT;
SQL> SELECT COLA FROM TESTTRI ORDER BY CAST(COLA AS VARCHAR(10) CHARACTER SET UTF8) COLLATE unicode_num;
 
COLA       
========== 
AS/GF/1    
AS/GF/2    
AS/GF/3    
AS/GF/4    
AS/GF/5    
AS/GF/10   
AS/GF/11   
AS/GF/20   
AS/GF/21   
 
SQL>
__________________
Philippe Makowski
IBPhoenix - Firebird
Membre de l'April
makowski est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/01/2011, 17h03   #7
Expert Confirmé

 
Homme Philippe Makowski
Consultant spécialité Firebird
Inscription : mai 2002
Messages : 2 213
Détails du profil
Informations personnelles :
Nom : Homme Philippe Makowski
Âge : 49
Localisation : France

Informations professionnelles :
Activité : Consultant spécialité Firebird
Secteur : Conseil

Informations forums :
Inscription : mai 2002
Messages : 2 213
Points : 3 315
Points : 3 315
Citation:
Envoyé par Barbibulle Voir le message
Je me demande si type of column fonctionne ici
non
en utilisant tu ne peux pas changer de jeux de caractère

par contre tu peux tricher un peu et faire :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
SELECT _UTF8 ''||COLA FROM TESTTRI ORDER BY 1 COLLATE unicode_num;
 
CONCATENATION                            
======================================== 
AS/GF/1                                  
AS/GF/2                                  
AS/GF/3                                  
AS/GF/4                                  
AS/GF/5                                  
AS/GF/10                                 
AS/GF/11                                 
AS/GF/20                                 
AS/GF/21                                 
 
SQL>
__________________
Philippe Makowski
IBPhoenix - Firebird
Membre de l'April
makowski est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/01/2011, 17h08   #8
Membre Expert
 
Avatar de Barbibulle
 
Frédéric
Inscription : octobre 2002
Messages : 1 722
Détails du profil
Informations personnelles :
Nom : Frédéric
Âge : 42

Informations forums :
Inscription : octobre 2002
Messages : 1 722
Points : 2 025
Points : 2 025
non ma question sur type of column ce n'était pas pour changer le charset.

C'était pour savoir si :

Code :
SELECT COLA FROM TESTTRI ORDER BY CAST(COLA AS TYPE OF COLUMN TESTTRI.COLA CHARACTER SET UTF8) COLLATE unicode_num;
fonctionnait ?
Barbibulle est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/01/2011, 17h12   #9
Expert Confirmé

 
Homme Philippe Makowski
Consultant spécialité Firebird
Inscription : mai 2002
Messages : 2 213
Détails du profil
Informations personnelles :
Nom : Homme Philippe Makowski
Âge : 49
Localisation : France

Informations professionnelles :
Activité : Consultant spécialité Firebird
Secteur : Conseil

Informations forums :
Inscription : mai 2002
Messages : 2 213
Points : 3 315
Points : 3 315
je t'ai répondu, c'est non, puisque tu changes de charset
Code :
1
2
3
4
5
6
7
8
9
10
11
12
SQL> SELECT COLA FROM TESTTRI ORDER BY CAST(COLA AS TYPE OF COLUMN TESTTRI.COLA CHARACTER SET UTF8) COLLATE unicode_num;
Statement failed, SQLSTATE = 42000
Dynamic SQL Error
-SQL error code = -104
-Token unknown - line 1, COLUMN 76
-CHARACTER
SQL> SELECT COLA FROM TESTTRI ORDER BY CAST(COLA AS TYPE OF COLUMN TESTTRI.COLA) COLLATE unicode_num;
Statement failed, SQLSTATE = HY004
Dynamic SQL Error
-SQL error code = -204
-DATA type unknown
-COLLATION UNICODE_NUM FOR CHARACTER SET ISO8859_1 IS NOT defined
__________________
Philippe Makowski
IBPhoenix - Firebird
Membre de l'April
makowski est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/01/2011, 17h17   #10
Membre Expert
 
Avatar de Barbibulle
 
Frédéric
Inscription : octobre 2002
Messages : 1 722
Détails du profil
Informations personnelles :
Nom : Frédéric
Âge : 42

Informations forums :
Inscription : octobre 2002
Messages : 1 722
Points : 2 025
Points : 2 025
ah j'avais mal interprété ta réponse.

Merci
Barbibulle est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 12h25.


 
 
 
 
Partenaires

Hébergement Web