Précédent   Forum du club des développeurs et IT Pro > Bases de données > Sybase
Sybase Forum sur la base de données Sybase. Avant de poster -> F.A.Q Sybase, Tutoriels Sybase
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 17/11/2011, 15h56   #1
Eskehnach
Futur Membre du Club
 
Homme
Développeur informatique
Inscription : août 2009
Messages : 15
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Manche (Basse Normandie)

Informations professionnelles :
Activité : Développeur informatique
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : août 2009
Messages : 15
Points : 18
Points : 18
Par défaut utilisation CASE en sybase

Bonjour,

Je doit créer 2 proc une en sybase et une en oracle.
J'utilise la fonction case en oracle et ca fonctionne par contre en sybase sa bloque

pour oracle je fait
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
44
45
46
47
48
49
50
51
52
53
54
55
 
CREATE OR REPLACE
procedure WEB_CSWEB_VILPORNET
 
IS
 
TypeInsert VARCHAR(70);
 
BEGIN
	--recupere la valeur de WEB_ALIM_VILPORNET pour connaiter le mode d'alimentation de la table WEB_VILPORNET
	SELECT nvl(max(INIVAL),'VOIEILOT') INTO TypeInsert
	FROM WEB_INI WHERE ININAME='WEB_ALIM_VILPORNET';
 
	case TypeInsert
		when 'GEOCODAGE' THEN 
			execute immediate('insert into web.web_vilpornet
								select codine,copos6,cmuabn,null
								from abo.xpbartp2 t
								where exists (select 1 from vnd.si05 s 
                                      where s.ccoins = t.ccoins)');
		when 'SPEC_FS' then 
			execute immediate('insert into web.web_vilpornet 
								select codine,copos6,cmuabn,null 
								from abo.xpbartp2 t 
								where exists (select 1 from abo.voieilot v 
                                      where v.voiins = codine 
                                      and voicodilo = ''I100'')');
		when 'VOIEILOT' then
			execute IMMEDIATE ('insert into web.web_vilpornet
                select codine,copos6,cmuabn,null 
								from abo.xpbartp2 t
								where exists (select 1 from abo.voieilot v 
                                      where v.voiins = codine)');
    WHEN 'SPEC_NM' THEN
      execute immediate ('insert into web.web_vilpornet
                select codine,copos6,cmuabn,null 
                from abo.xpbartp2 t
                where exists (select 1 from abo.voieilot v 
                                      where v.voiins = codine)');
      execute immediate ('insert into web.web_vilpornet
                select codine,copos6,cmuabn,null 
                from abo.XPBARTP2
                where substr(CODINE,1,6) IN (''006999'', ''083137'', ''020033'', ''006088'', ''020004'')
                and substr (codine,7,1) in (''X'', ''E'') ');
    /*pour toute autre valeur dans la table WEB_INI execution de la meme insertion que pour VOIEILOT
    ceci pour prévoir en cas de changement*/
		ELSE 
			execute IMMEDIATE ('insert into web.web_vilpornet
								select codine,copos6,cmuabn,null 
								from abo.xpbartp2 t
								where exists (select 1 from abo.voieilot v 
                                      where v.voiins = codine)');
	end case;
	commit;
end;
mais en sybase si je met ce code
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
 
USE web
 
/*declare @nomobj varchar(255)
if exists(select 1 from sysobjects where upper(name)=upper('WEB_CSWEB_VILPORNET') and type='P')
      begin
      select @nomobj=name  from sysobjects where upper(name)=upper('WEB_CSWEB_VILPORNET') and type='P'
      execute('drop procedure ' + @nomobj)
      end
go*/
 
CREATE proc WEB_CSWEB_VILPORNET
 
AS
 
declare @TypeInsert VARCHAR(70)
 
--recupere la valeur de WEB_ALIM_VILPORNET pour connaitre le mode d'alimentation de la table WEB_VILPORNET
SELECT @TypeInsert=isnull(INIVAL,'VOIEILOT') 
FROM WEB_INI WHERE ININAME='WEB_ALIM_VILPORNET'
 
SELECT case @TypeInsert
	when 'GEOCODAGE' THEN 
		execute('insert into web..web_vilpornet
					select codine,copos6,cmuabn,null
					from abo..xpbartp2 t
					where exists (select 1 from vnd..si05 s 
											where s.ccoins = t.ccoins)')
	when 'SPEC_FS' then 
		execute('insert into web..web_vilpornet 
					select codine,copos6,cmuabn,null 
					from abo..xpbartp2 t 
					where exists (select 1 from abo..voieilot v 
											where v.voiins = codine 
											and voicodilo = ''I100'')')
	when 'VOIEILOT'
		execute('insert into web..web_vilpornet
					select codine,copos6,cmuabn,null 
					from abo..xpbartp2 t
					where exists (select 1 from abo..voieilot v 
											where v.voiins = codine)')
	WHEN 'SPEC_NM' THEN
		execute('insert into web..web_vilpornet
					select codine,copos6,cmuabn,null 
					from abo..xpbartp2 t
					where exists (select 1 from abo..voieilot v 
											where v.voiins = codine)')
		execute('insert into web..web_vilpornet
					select codine,copos6,cmuabn,null 
					from abo..XPBARTP2
					where substr(CODINE,1,6) IN (''006999'', ''083137'', ''020033'', ''006088'', ''020004'')
					and substr (codine,7,1) in (''X'', ''E'') ')
	/*pour toute autre valeur dans la table WEB_INI execution de la meme insertion que pour VOIEILOT
	ceci pour prévoir en cas de changement*/
	ELSE 
		execute('insert into web..web_vilpornet
					select codine,copos6,cmuabn,null 
					from abo..xpbartp2 t
					where exists (select 1 from abo..voieilot v 
											where v.voiins = codine)')
end
go
et la j'ai des erreurs à la compile car il n'aime pas ma fonction execute.

est ce que quelqu'un à une idée
Merci
Eskehnach est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/11/2011, 17h29   #2
Jean.Cri1
Membre éclairé
 
Homme
Développeur informatique
Inscription : octobre 2006
Messages : 210
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : octobre 2006
Messages : 210
Points : 362
Points : 362
Il faut utiliser if then ... else if then ... else if ...
Le case marche pour remplacer des expressions par d'autres ( eventuellement calulées avec des fonctions internes ou des sous requetes ) mais pas dans ce cas la.
Jean.Cri1 est actuellement connecté   Envoyer un message privé Réponse avec citation 00
Vieux 17/11/2011, 17h37   #3
Eskehnach
Futur Membre du Club
 
Homme
Développeur informatique
Inscription : août 2009
Messages : 15
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Manche (Basse Normandie)

Informations professionnelles :
Activité : Développeur informatique
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : août 2009
Messages : 15
Points : 18
Points : 18
merci de ta réponse,

je voulais éviter de passer par la et savoir s'il y avait une instruction équivalente en sybase par rapport à oracle.
Eskehnach est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/11/2011, 11h04   #4
Jean.Cri1
Membre éclairé
 
Homme
Développeur informatique
Inscription : octobre 2006
Messages : 210
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Développeur informatique

Informations forums :
Inscription : octobre 2006
Messages : 210
Points : 362
Points : 362
Par contre tu peux l'ecrire autrement si tu n'aimes pas les if imbriqués :

Code :
1
2
3
4
5
6
7
8
DECLARE @exec varchar(4000)
SELECT @exec = case @TypeInsert 
                    when 'cas1' then 'instruction(s) 1'
                    when 'cas2' then 'instruction(s) 2'
                    else             'instruction(s) else'
               end
 
EXEC @exec
Jean.Cri1 est actuellement connecté   Envoyer un message privé Réponse avec citation 10
Vieux 18/11/2011, 16h05   #5
Eskehnach
Futur Membre du Club
 
Homme
Développeur informatique
Inscription : août 2009
Messages : 15
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France, Manche (Basse Normandie)

Informations professionnelles :
Activité : Développeur informatique
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : août 2009
Messages : 15
Points : 18
Points : 18
Citation:
Envoyé par Jean.Cri1 Voir le message
Code :
1
2
3
4
5
6
7
8
DECLARE @exec varchar(4000)
SELECT @exec = case @TypeInsert 
                    when 'cas1' then 'instruction(s) 1'
                    when 'cas2' then 'instruction(s) 2'
                    else             'instruction(s) else'
               end
 
EXEC @exec
Nickel c'est ce que je cherchais.
Le Seul hic c'est que j'ai des changement de schéma lors de mon exécution des procédure sql et ca il n'aime pas, là c'est un autre problème sinon ta solution me convient parfaitement
Eskehnach est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 14h17.


 
 
 
 
Partenaires

Hébergement Web