Précédent   Forum des professionnels en informatique > Bases de données > Oracle
Oracle Forum Oracle : le serveur, les outils, ... Voir F.A.Q Oracle Tutoriels Oracle
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 18/07/2007, 09h43   #1
Futur Membre du Club
 
Emilie Dorchies
Inscription : décembre 2004
Messages : 45
Détails du profil
Informations personnelles :
Nom : Emilie Dorchies

Informations forums :
Inscription : décembre 2004
Messages : 45
Points : 19
Points : 19
Envoyer un message via MSN à Cofondinde
Par défaut Commande MERGE sous ORACLE 9.2.0.6

Bonjour,

Je tente de mettre en oeuvre la commande MERGE comme alternative à un update de vue inline.

Mon script est le suivant :

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
 
MERGE INTO testdbruevn A
USING (
 SELECT	a.datsitu||a.cdfili||a.idestd ID,
  	(SELECT nvl(	(SELECT '1' FROM dual WHERE 0=(SELECT count(*) FROM tfixsyr WHERE a.coddev=tfixsyr.coddev)),'0') FROM dual) WK_STATUT1,
  	(SELECT nvl(	(SELECT '1' FROM dual WHERE 0=(SELECT count(*) FROM tguisyr WHERE a.codgui=tguisyr.codgui)),'0') FROM dual) WK_STATUT2,
  	(SELECT nvl(	(SELECT '1' FROM dual WHERE 0=(SELECT count(*) FROM tpcisyr WHERE a.numpci=tpcisyr.numpci)),'0') FROM dual) WK_STATUT3,
  	(SELECT nvl(	(SELECT '1' FROM dual WHERE (a.natinst = '50' AND a.codsec IN ('12','13','14','22','23','24')   
						OR      a.natinst = '51' AND a.codsec IN ('11','12','14','21','22','24')   
						OR      a.natinst = '52' AND a.codsec IN ('12','22')                       
						OR      a.natinst = '53' AND a.codsec IN ('12','22')                       
						OR      a.natinst = '54' AND a.codsec IN ('12','22')                       
						OR      a.natinst = '55' AND a.codsec IN ('12','13','22','23')             
						OR      a.natinst = '56' AND a.codsec IN ('11','13','21','23'))), '0') FROM dual)  WK_STATUT4,
  	(SELECT nvl(	(SELECT '1' FROM dual WHERE a.natid NOT IN ('I', 'S', 'R', 'C')), '0') FROM dual) WK_STATUT5,
  	(SELECT numpcemar FROM  tpcisyr WHERE a.numpci=numpci) WK_NUMPCEMAR,
  	b.codtit WK_CODTIT,
  	c.valtyptit WK_CODSEDOL,
  	d.codtyppdt WK_TYPPDT,
  	(SELECT b.crsdev FROM tfixsyr b WHERE  b.coddev = a.coddev AND to_char(b.datsitu,'YYYYMM') LIKE substr(a.datsitu,1,6)) WK_CRSDEV,
  	(SELECT b.nbrdec FROM tfixsyr b WHERE  b.coddev = a.coddev AND to_char(b.datsitu,'YYYYMM') LIKE substr(a.datsitu,1,6)) WK_NBRDEC,
  	case d.codtyppdt
  	when 'A' then 0
  	else a.valfac
  	end WK_VALFAC
  FROM    testdbruevn a, ttitbdr b, ttitcodbdr c, ttyptitbdr d
	WHERE	substr(a.datsitu,1,6)='&1'
	AND	a.cdfili = '&2'
	AND	a.idtitre=b.codisn
	AND	a.coddev = b.ca3isodevcot
	AND	b.codtit = c.codtit
	AND	c.codtyptit=7
	AND	b.codtyptit = d.codtyptit	
	) B   
ON ((SELECT A.datsitu||A.cdfili||A.idestd FROM testdbruevn A)=B.ID) 
WHEN MATCHED THEN
  UPDATE SET A.statut1=B.WK_STATUT1
  UPDATE SET A.statut2=B.WKSTATUT2
  UPDATE SET A.statut3=B.WKSTATUT3
  UPDATE SET A.statut4=B.WKSTATUT4
  UPDATE SET A.statut5=B.WKSTATUT5
  UPDATE SET A.numpcemar=B.WKNUMPCEMAR
  UPDATE SET A.codtit=B.WKCODTIT
  UPDATE SET A.codsedol=B.WKCODSEDOL
  UPDATE SET A.typpdt=B.WKTYPPDT
  UPDATE SET A.crsdev=B.WKCRSDEV
  UPDATE SET A.nbrdec=B.WKNBRDEC
  UPDATE SET A.valfac=B.WKVALFAC
WHEN NOT MATCHED THEN
 UPDATE SET A.statut1=B.WK_STATUT1
;


Cependant, à l'execution il retourne une :

ORA-00905: missing keyword

Pouvez-vous m'aider à la faire fonctionner.

Merci d'avance !
Cofondinde est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/07/2007, 10h07   #2
Membre éprouvé
 
Avatar de chrifo
 
Inscription : juillet 2006
Messages : 445
Détails du profil
Informations forums :
Inscription : juillet 2006
Messages : 445
Points : 418
Points : 418
Bonjour,
essayez
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
MERGE INTO testdbruevn A
USING (
 SELECT	a.datsitu||a.cdfili||a.idestd ID,
  	(SELECT nvl(	(SELECT '1' FROM dual WHERE 0=(SELECT count(*) FROM tfixsyr WHERE a.coddev=tfixsyr.coddev)),'0') FROM dual) WK_STATUT1,
  	(SELECT nvl(	(SELECT '1' FROM dual WHERE 0=(SELECT count(*) FROM tguisyr WHERE a.codgui=tguisyr.codgui)),'0') FROM dual) WK_STATUT2,
  	(SELECT nvl(	(SELECT '1' FROM dual WHERE 0=(SELECT count(*) FROM tpcisyr WHERE a.numpci=tpcisyr.numpci)),'0') FROM dual) WK_STATUT3,
  	(SELECT nvl(	(SELECT '1' FROM dual WHERE (a.natinst = '50' AND a.codsec IN ('12','13','14','22','23','24')   
						OR      a.natinst = '51' AND a.codsec IN ('11','12','14','21','22','24')   
						OR      a.natinst = '52' AND a.codsec IN ('12','22')                       
						OR      a.natinst = '53' AND a.codsec IN ('12','22')                       
						OR      a.natinst = '54' AND a.codsec IN ('12','22')                       
						OR      a.natinst = '55' AND a.codsec IN ('12','13','22','23')             
						OR      a.natinst = '56' AND a.codsec IN ('11','13','21','23'))), '0') FROM dual)  WK_STATUT4,
  	(SELECT nvl(	(SELECT '1' FROM dual WHERE a.natid NOT IN ('I', 'S', 'R', 'C')), '0') FROM dual) WK_STATUT5,
  	(SELECT numpcemar FROM  tpcisyr WHERE a.numpci=numpci) WK_NUMPCEMAR,
  	b.codtit WK_CODTIT,
  	c.valtyptit WK_CODSEDOL,
  	d.codtyppdt WK_TYPPDT,
  	(SELECT b.crsdev FROM tfixsyr b WHERE  b.coddev = a.coddev AND to_char(b.datsitu,'YYYYMM') LIKE substr(a.datsitu,1,6)) WK_CRSDEV,
  	(SELECT b.nbrdec FROM tfixsyr b WHERE  b.coddev = a.coddev AND to_char(b.datsitu,'YYYYMM') LIKE substr(a.datsitu,1,6)) WK_NBRDEC,
  	case d.codtyppdt
  	when 'A' then 0
  	else a.valfac
  	end WK_VALFAC
  FROM    testdbruevn a, ttitbdr b, ttitcodbdr c, ttyptitbdr d
	WHERE	substr(a.datsitu,1,6)='&1'
	AND	a.cdfili = '&2'
	AND	a.idtitre=b.codisn
	AND	a.coddev = b.ca3isodevcot
	AND	b.codtit = c.codtit
	AND	c.codtyptit=7
	AND	b.codtyptit = c.codtyptit	
	) B   
ON (A.datsitu||A.cdfili||A.idestd=B.ID) 
WHEN MATCHED THEN
  UPDATE SET A.statut1=B.WK_STATUT1
  UPDATE SET A.statut2=B.WKSTATUT2
  UPDATE SET A.statut3=B.WKSTATUT3
  UPDATE SET A.statut4=B.WKSTATUT4
  UPDATE SET A.statut5=B.WKSTATUT5
  UPDATE SET A.numpcemar=B.WKNUMPCEMAR
  UPDATE SET A.codtit=B.WKCODTIT
  UPDATE SET A.codsedol=B.WKCODSEDOL
  UPDATE SET A.typpdt=B.WKTYPPDT
  UPDATE SET A.crsdev=B.WKCRSDEV
  UPDATE SET A.nbrdec=B.WKNBRDEC
  UPDATE SET A.valfac=B.WKVALFAC
WHEN NOT MATCHED THEN
 UPDATE SET A.statut1=B.WK_STATUT1
;
chrifo est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/07/2007, 10h16   #3
Futur Membre du Club
 
Emilie Dorchies
Inscription : décembre 2004
Messages : 45
Détails du profil
Informations personnelles :
Nom : Emilie Dorchies

Informations forums :
Inscription : décembre 2004
Messages : 45
Points : 19
Points : 19
Envoyer un message via MSN à Cofondinde
Bonjour,

Cela ne fonctionne pas non plus,
Il retourne la même erreur et la situe (pour ce que ça vaut) au niveau du second update de la clause WHEN MATCHED THEN.

Mettre en commentaire les update de la cette clause en n'en laissant qu'un seul ne change rien. L'erreur est alors plalc au niveau de l'update de la clause WHEN NOT NATCHED.
Cofondinde est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 18/07/2007, 16h18   #4
Candidat au titre de Membre du Club
 
Inscription : juillet 2007
Messages : 21
Détails du profil
Informations forums :
Inscription : juillet 2007
Messages : 21
Points : 11
Points : 11
A mon humble avis, la clause not matched signifie que le join entre les 2 tables n'existe pas,
donc, tu ne peux pas faire de update t1.xx = t2.yy

L'insert sera lui possible dans la clause not matched ...
JahPil78 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 19/07/2007, 19h34   #5
McM
Expert Confirmé Sénior
 
Inscription : juillet 2003
Messages : 3 450
Détails du profil
Informations forums :
Inscription : juillet 2003
Messages : 3 450
Points : 4 209
Points : 4 209
Comme c'est pas beau les
Code :
1
2
3
(SELECT nvl(	(SELECT '1' FROM dual 
WHERE 0=(SELECT count(*) FROM tfixsyr WHERE a.coddev=tfixsyr.coddev)),'0') 
FROM dual) WK_STATUT1


A remplacer par
Code :
1
2
3
4
(SELECT NVL(max('1'),'0') 
FROM tfixsyr 
WHERE a.coddev=tfixsyr.codd
AND ROWNUM = 1) WK_STATUT1
__________________
More Code : More Bugs. Less Code : Less Bugs
McM est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 19/07/2007, 19h42   #6
McM
Expert Confirmé Sénior
 
Inscription : juillet 2003
Messages : 3 450
Détails du profil
Informations forums :
Inscription : juillet 2003
Messages : 3 450
Points : 4 209
Points : 4 209
La clause UPDATE doit être unique dans le merge.
Code :
1
2
3
4
5
6
7
8
9
10
11
12
UPDATE SET A.statut1=B.WK_STATUT1,
  A.statut2=B.WKSTATUT2,
  A.statut3=B.WKSTATUT3,
  A.statut4=B.WKSTATUT4,
  A.statut5=B.WKSTATUT5,
  A.numpcemar=B.WKNUMPCEMAR,
  A.codtit=B.WKCODTIT,
  A.codsedol=B.WKCODSEDOL,
  A.typpdt=B.WKTYPPDT,
  A.crsdev=B.WKCRSDEV,
  A.nbrdec=B.WKNBRDEC,
  A.valfac=B.WKVALFAC
Et le NOT MATCHED, tu peux pas faire d'UPDATE mais un INSERT
__________________
More Code : More Bugs. Less Code : Less Bugs
McM est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 03h35.


 
 
 
 
Partenaires

Hébergement Web