Précédent   Forum des professionnels en informatique > Bases de données > Oracle > SQL
SQL Forum d'entraide sur le SQL pour 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 28/03/2008, 15h39   #1
Candidat au titre de Membre du Club
 
Inscription : janvier 2005
Messages : 37
Détails du profil
Informations forums :
Inscription : janvier 2005
Messages : 37
Points : 11
Points : 11
Par défaut Formatage de chaine pour l'execute immediate

Voilà j'ai une requete de creation de table temporaire
Code :
1
2
3
CREATE TABLE SWIFT_PRSW_FIELDS_TMP AS SELECT DISTINCT FIELD_NUMBER||OPTION_LETTER||'_'||REPLACE(UPPER(ct.LABEL), ' ', '') AS code,  vt.LABEL||'('||ct.LENGTH||')' AS type
FROM SWIFT_OPTION_level ol, SWIFT_OPTION o, SWIFT_MANDATORY_LEVEL ml, swift_type t ,SWIFT_OPTION_CONTENT oc, swift_CONTENT_TYPE ct, SWIFT_VAR_TYPE vt
WHERE ol.FK_OPTION = o.OID  AND ol.FK_MANDATORY_LEVEL = ml.OID AND oc.FK_CONTENT_TYPE = ct.OID AND oc.FK_OPTION = o.oid AND ct.FK_VAR_TYPE = vt.OID
Bon c'est pas super joli mais ça me donne le résultat attendu !
Maintenant je voudrais mettre faire cette création au sein d'une procedure PL/SQL. J'utilise donc le bout de code suivant :

Code :
execute immediate('create table SWIFT_PRSW_FIELDS_TMP as select distinct FIELD_NUMBER||OPTION_LETTER||_||REPLACE(UPPER(ct.LABEL), '' '', '''') as code, vt.LABEL||''(''||ct.LENGTH||'')'' as type from SWIFT_OPTION_level ol, SWIFT_OPTION o, SWIFT_MANDATORY_LEVEL ml, swift_type t ,SWIFT_OPTION_CONTENT oc, swift_CONTENT_TYPE ct, SWIFT_VAR_TYPE vt where ol.FK_OPTION = o.OID  and ol.FK_MANDATORY_LEVEL = ml.OID and oc.FK_CONTENT_TYPE = ct.OID and oc.FK_OPTION = o.oid and ct.FK_VAR_TYPE = vt.OID');
Ca compile mais à l'exécution j'ai un sushi :

Code :
1
2
3
4
5
ORA-06550: line 4, COLUMN 0:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
 
   ; <an identifier> <a double-quoted delimited-identifier>
The symbol ";" was substituted FOR "end-of-file" TO continue.
Je pense que c'est du a un problème de cotes ...
Ça fait 2 h que j'essaye tout et n'importe quoi quelle est la règle d'ajout de cotes ?


juste pour information la procedure complète
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
CREATE OR REPLACE PROCEDURE PROC_GEN_PRSW IS
TABLE_TO_CREATE  CONSTANT VARCHAR2(10) := 'PRSW2' ;
tmpVar NUMBER;
isAlreadyDefined int;
 
BEGIN
 
   -- loading all attended PRSW fields into a temporary table
 
 
 
   SELECT count(*) INTO isAlreadyDefined FROM user_tables WHERE table_name = TABLE_TO_CREATE;
 
   IF (isAlreadyDefined = 1)
     then					-- update
   	   tmpVar := 1;
     else					-- insert
	   -- creating table
 
	   -- get all fields
	   tmpVar := 1;
execute immediate('create table SWIFT_PRSW_FIELDS_TMP as select distinct FIELD_NUMBER||OPTION_LETTER||_||REPLACE(UPPER(ct.LABEL), '' '', '''') as code, vt.LABEL||''(''||ct.LENGTH||'')'' as type from SWIFT_OPTION_level ol, SWIFT_OPTION o, SWIFT_MANDATORY_LEVEL ml, swift_type t ,SWIFT_OPTION_CONTENT oc, swift_CONTENT_TYPE ct, SWIFT_VAR_TYPE vt where ol.FK_OPTION = o.OID  and ol.FK_MANDATORY_LEVEL = ml.OID and oc.FK_CONTENT_TYPE = ct.OID and oc.FK_OPTION = o.oid and ct.FK_VAR_TYPE = vt.OID');
   end IF;
 
   EXCEPTION
     WHEN NO_DATA_FOUND THEN
       NULL;
     WHEN OTHERS THEN
       RAISE;
END PROC_GEN_PRSW;
/
Voilà si quelqu'un a une piste ou une fonction qui pourrait m'aider ... à vot' bon coeur

Emilien
Azounet est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/03/2008, 15h46   #2
Rédacteur/Modérateur
 
Avatar de orafrance
 
Inscription : janvier 2004
Messages : 15 861
Détails du profil
Informations personnelles :
Âge : 35

Informations forums :
Inscription : janvier 2004
Messages : 15 861
Points : 16 212
Points : 16 212
ça donne quoi :

Code :
1
2
SELECT 'create table SWIFT_PRSW_FIELDS_TMP as select distinct FIELD_NUMBER||OPTION_LETTER||_||REPLACE(UPPER(ct.LABEL), '' '', '''') as code, vt.LABEL||''(''||ct.LENGTH||'')'' as type from SWIFT_OPTION_level ol, SWIFT_OPTION o, SWIFT_MANDATORY_LEVEL ml, swift_type t ,SWIFT_OPTION_CONTENT oc, swift_CONTENT_TYPE ct, SWIFT_VAR_TYPE vt where ol.FK_OPTION = o.OID  and ol.FK_MANDATORY_LEVEL = ml.OID and oc.FK_CONTENT_TYPE = ct.OID and oc.FK_OPTION = o.oid and ct.FK_VAR_TYPE = vt.OID'
FROM DUAL;
Sinon, les exceptions sont inutiles, un COUNT ne fera jamais de no_data_found et un OTHERS fera toujours un RAISE
orafrance est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/03/2008, 16h01   #3
Candidat au titre de Membre du Club
 
Inscription : janvier 2005
Messages : 37
Détails du profil
Informations forums :
Inscription : janvier 2005
Messages : 37
Points : 11
Points : 11
Voici le résutat de select from dual :

Code :
1
2
3
4
5
6
CREATE TABLE SWIFT_PRSW_FIELDS_TMP AS SELECT DISTINCT FIELD_NUMBER||OPTION_LETTE
R||_||REPLACE(UPPER(ct.LABEL), ' ', '') AS code, vt.LABEL||'('||ct.LENGTH||')' a
s type FROM SWIFT_OPTION_level ol, SWIFT_OPTION o, SWIFT_MANDATORY_LEVEL ml, swi
ft_type t ,SWIFT_OPTION_CONTENT oc, swift_CONTENT_TYPE ct, SWIFT_VAR_TYPE vt whe
re ol.FK_OPTION = o.OID  AND ol.FK_MANDATORY_LEVEL = ml.OID AND oc.FK_CONTENT_TY
PE = ct.OID AND oc.FK_OPTION = o.oid AND ct.FK_VAR_TYPE = vt.OID
Malheureusement ça ne marche pas ...

Pour ce qui est des exception, c'est TOAD qui ma généré le squelette, j'en suis pas à faire le ménage =)
Azounet est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/03/2008, 16h07   #4
Rédacteur/Modérateur
 
Avatar de orafrance
 
Inscription : janvier 2004
Messages : 15 861
Détails du profil
Informations personnelles :
Âge : 35

Informations forums :
Inscription : janvier 2004
Messages : 15 861
Points : 16 212
Points : 16 212
Citation:
Envoyé par Azounet Voir le message
Malheureusement ça ne marche pas ...
mais encore ?
orafrance est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/03/2008, 16h10   #5
Membre confirmé
 
Avatar de DAB.cz
 
Inscription : octobre 2006
Messages : 221
Détails du profil
Informations forums :
Inscription : octobre 2006
Messages : 221
Points : 214
Points : 214
Code :
OPTION_LETTER||''_''||REPLACE
à la place de
Code :
OPTION_LETTER||_||REPLACE
DAB
DAB.cz est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/03/2008, 16h15   #6
Candidat au titre de Membre du Club
 
Inscription : janvier 2005
Messages : 37
Détails du profil
Informations forums :
Inscription : janvier 2005
Messages : 37
Points : 11
Points : 11
Citation:
Envoyé par orafrance Voir le message
mais encore ?
Peut être n'ais-je pas bien compris ce le but de ce select.

Voici ce que j'ai fait :
- J'ai fait le select from dual, dans SQL plus.
- copier coller le résultat dans un "execute immediate" au sein de ma procedure

Code :
execute immediate('create table SWIFT_PRSW_FIELDS_TMP as select distinct FIELD_NUMBER||OPTION_LETTER||_||REPLACE(UPPER(ct.LABEL), ' ', '') as code, vt.LABEL||'('||ct.LENGTH||')' as type from SWIFT_OPTION_level ol, SWIFT_OPTION o, SWIFT_MANDATORY_LEVEL ml, swift_type t ,SWIFT_OPTION_CONTENT oc, swift_CONTENT_TYPE ct, SWIFT_VAR_TYPE vt where ol.FK_OPTION = o.OID  and ol.FK_MANDATORY_LEVEL = ml.OID and oc.FK_CONTENT_TYPE = ct.OID and oc.FK_OPTION = o.oid and ct.FK_VAR_TYPE = vt.OID');
La procedure ne compile plus (normal probleme de cotes)


erreur:
Code :
1
2
3
PLS-00103: Encountered the symbol ", ') as code, vt.LABEL||" when expecting one of the following:
 
   . ( ) , * @ % & | = - + < / > at IN IS mod NOT range rem =>
Azounet est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/03/2008, 16h18   #7
Candidat au titre de Membre du Club
 
Inscription : janvier 2005
Messages : 37
Détails du profil
Informations forums :
Inscription : janvier 2005
Messages : 37
Points : 11
Points : 11
Citation:
Envoyé par DAB.cz Voir le message
Code :
OPTION_LETTER||''_''||REPLACE
à la place de
Code :
OPTION_LETTER||_||REPLACE
DAB
Yes bien joué DAB
Merci à Orafrance aussi !

Vive developpez
Azounet est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 28/03/2008, 16h18   #8
Rédacteur/Modérateur
 
Avatar de orafrance
 
Inscription : janvier 2004
Messages : 15 861
Détails du profil
Informations personnelles :
Âge : 35

Informations forums :
Inscription : janvier 2004
Messages : 15 861
Points : 16 212
Points : 16 212
bah faut doubler les quotes évidemment
orafrance 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 23h05.


 
 
 
 
Partenaires

Hébergement Web