Skip to content
Snippets Groups Projects
Commit 96e3874d authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Déplacement des requêtes SQL

parent 5513b36e
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 1956 deletions
SELECT
tas.id,
si.libelle statut_intervenant,
ta.code type_agrement,
tas.obligatoire,
tas.premier_recrutement,
tas.histo_destruction
FROM
type_agrement_statut tas
JOIN type_agrement ta ON ta.id = tas.type_agrement_id
JOIN statut_intervenant si ON si.id = tas.statut_intervenant_id
ORDER BY
statut_intervenant,
type_agrement;
SELECT source_code, libelle FROM statut_intervenant WHERE histo_destruction IS NULL;
INSERT INTO TYPE_AGREMENT_STATUT (
ID,
TYPE_AGREMENT_ID,
STATUT_INTERVENANT_ID,
OBLIGATOIRE,
PREMIER_RECRUTEMENT,
HISTO_CREATION,HISTO_CREATEUR_ID,
HISTO_MODIFICATION,HISTO_MODIFICATEUR_ID
) VALUES (
TYPE_AGREMENT_STATUT_ID_SEQ.NEXTVAL,
(SELECT id FROM type_agrement WHERE code = 'CONSEIL_RESTREINT'), -- CONSEIL_ACADEMIQUE | CONSEIL_RESTREINT
(SELECT id FROM statut_intervenant WHERE source_code = 'INTERMITTENT'),
1, -- OBLIGATOIRE
NULL, -- PREMIER_RECRUTEMENT
sysdate, (SELECT id FROM utilisateur WHERE username='lecluse'),
sysdate, (SELECT id FROM utilisateur WHERE username='lecluse')
);
INSERT INTO TYPE_AGREMENT_STATUT (
ID,
TYPE_AGREMENT_ID,
STATUT_INTERVENANT_ID,
OBLIGATOIRE,
PREMIER_RECRUTEMENT,
HISTO_CREATION,HISTO_CREATEUR_ID,
HISTO_MODIFICATION,HISTO_MODIFICATEUR_ID
) VALUES (
TYPE_AGREMENT_STATUT_ID_SEQ.NEXTVAL,
(SELECT id FROM type_agrement WHERE code = 'CONSEIL_ACADEMIQUE'), -- CONSEIL_ACADEMIQUE | CONSEIL_RESTREINT
(SELECT id FROM statut_intervenant WHERE source_code = 'INTERMITTENT'),
1, -- OBLIGATOIRE
1, -- PREMIER_RECRUTEMENT
sysdate, (SELECT id FROM utilisateur WHERE username='lecluse'),
sysdate, (SELECT id FROM utilisateur WHERE username='lecluse')
);
\ No newline at end of file
BEGIN
DBMS_SCHEDULER.disable(name=>'"OSE"."OSE_SRC_SYNC"');
END;
/
CREATE TABLE MV_INTERVENANT_DEMO
(
CODE VARCHAR2(9 CHAR)
, Z_CIVILITE_ID VARCHAR2(3 CHAR)
, NOM_USUEL VARCHAR2(120 BYTE)
, PRENOM VARCHAR2(60 BYTE)
, NOM_PATRONYMIQUE VARCHAR2(120 BYTE)
, DATE_NAISSANCE DATE
, Z_PAYS_NAISSANCE_ID VARCHAR2(9 BYTE)
, Z_DEP_NAISSANCE_ID VARCHAR2(9 BYTE)
, VILLE_NAISSANCE_CODE_INSEE VARCHAR2(15 BYTE)
, VILLE_NAISSANCE_LIBELLE VARCHAR2(78 BYTE)
, Z_PAYS_NATIONALITE_ID VARCHAR2(9 BYTE)
, TEL_PRO VARCHAR2(33 BYTE)
, TEL_MOBILE VARCHAR2(60 BYTE)
, EMAIL VARCHAR2(4000 BYTE)
, Z_STATUT_ID VARCHAR2(14 CHAR)
, Z_STRUCTURE_ID VARCHAR2(4000 CHAR)
, SOURCE_CODE VARCHAR2(9 CHAR)
, NUMERO_INSEE VARCHAR2(39 BYTE)
, NUMERO_INSEE_CLE VARCHAR2(40 CHAR)
, NUMERO_INSEE_PROVISOIRE NUMBER
, IBAN VARCHAR2(108 BYTE)
, BIC VARCHAR2(36 BYTE)
, Z_GRADE_ID VARCHAR2(4000 CHAR)
, Z_DISCIPLINE_ID_CNU VARCHAR2(6 BYTE)
, Z_DISCIPLINE_ID_SOUS_CNU VARCHAR2(6 BYTE)
, Z_DISCIPLINE_ID_SPE_CNU VARCHAR2(9 BYTE)
, Z_DISCIPLINE_ID_DIS2DEG VARCHAR2(15 BYTE)
, CRITERE_RECHERCHE VARCHAR2(4000 CHAR)
, DATE_FIN DATE
);
insert into MV_INTERVENANT_DEMO select * from mv_intervenant;
CREATE OR REPLACE VIEW SRC_INTERVENANT AS
WITH srci as (
SELECT
i.code,
c.id civilite_id,
i.nom_usuel, i.prenom, i.nom_patronymique,
COALESCE(i.date_naissance,TO_DATE('2099-01-01','YYYY-MM-DD')) date_naissance,
pnaiss.id pays_naissance_id,
dep.id dep_naissance_id,
i.ville_naissance_code_insee, i.ville_naissance_libelle,
pnat.id pays_nationalite_id,
i.tel_pro, i.tel_mobile, i.email,
si.id statut_id, si.source_code statut_code,
NVL(s.structure_niv2_id,s.id) structure_id,
src.id source_id, i.source_code,
i.numero_insee, i.numero_insee_cle, i.numero_insee_provisoire,
i.iban, i.bic,
g.id grade_id,
NVL( d.id, d99.id ) discipline_id,
i.critere_recherche,
COALESCE (si.ordre,99999) ordre,
MIN(COALESCE (si.ordre,99999)) OVER (PARTITION BY i.source_code) min_ordre
FROM
mv_intervenant_demo i
JOIN source src ON src.code = 'Harpege'
LEFT JOIN civilite c ON c.libelle_court = i.z_civilite_id
LEFT JOIN structure s ON s.source_code = i.z_structure_id
LEFT JOIN statut_intervenant si ON si.source_code = i.z_statut_id
LEFT JOIN grade g ON g.source_code = i.z_grade_id
LEFT JOIN pays pnaiss ON pnaiss.source_code = i.z_pays_naissance_id
LEFT JOIN pays pnat ON pnat.source_code = i.z_pays_nationalite_id
LEFT JOIN departement dep ON dep.source_code = i.z_dep_naissance_id
LEFT JOIN discipline d99 ON d99.source_code = '99'
LEFT JOIN discipline d ON
d.histo_destruction IS NULL
AND 1 = CASE WHEN -- si rien n'ac été défini
COALESCE( i.z_discipline_id_cnu, i.z_discipline_id_sous_cnu, i.z_discipline_id_spe_cnu, i.z_discipline_id_dis2deg ) IS NULL
AND d.source_code = '00'
THEN 1 WHEN -- si une CNU ou une spécialité a été définie...
COALESCE( i.z_discipline_id_cnu, i.z_discipline_id_sous_cnu, z_discipline_id_spe_cnu ) IS NOT NULL
THEN CASE WHEN -- alors on teste par les sections CNU et spécialités
(
',' || d.CODES_CORRESP_2 || ',' LIKE '%,' || i.z_discipline_id_cnu || NVL(i.z_discipline_id_sous_cnu,'') || ',%'
OR ',' || d.CODES_CORRESP_2 || ',' LIKE '%,' || i.z_discipline_id_cnu || NVL(i.z_discipline_id_sous_cnu,'00') || ',%'
)
AND ',' || NVL(d.CODES_CORRESP_3,'000') || ',' LIKE '%,' || NVL(CASE WHEN d.CODES_CORRESP_3 IS NOT NULL THEN z_discipline_id_spe_cnu ELSE NULL END,'000') || ',%'
THEN 1 ELSE 0 END ELSE CASE WHEN -- sinon on teste par les disciplines du 2nd degré
i.z_discipline_id_dis2deg IS NOT NULL
AND ',' || NVL(d.CODES_CORRESP_4,'') || ',' LIKE '%,' || i.z_discipline_id_dis2deg || ',%'
THEN 1 ELSE 0 END END -- fin du test
)
SELECT
null id,
i.code code, i.code supann_emp_id,
i.civilite_id,
i.nom_usuel, i.prenom, i.nom_patronymique,
i.date_naissance,
i.pays_naissance_id,
i.dep_naissance_id,
i.ville_naissance_code_insee, i.ville_naissance_libelle,
i.pays_nationalite_id,
i.tel_pro, i.tel_mobile, i.email,
COALESCE(
isai.statut_id,
CASE WHEN i.statut_code = 'AUTRES' AND d.statut_id IS NOT NULL THEN d.statut_id ELSE i.statut_id END
) statut_id,
i. structure_id,
i.source_id, i.source_code,
i.numero_insee, i.numero_insee_cle, i.numero_insee_provisoire,
i.iban, i.bic,
i.grade_id,
i.discipline_id,
unicaen_import.get_current_annee annee_id,
i.critere_recherche
FROM
srci i
LEFT JOIN intervenant i2 ON i2.source_code = i.source_code AND i2.annee_id = unicaen_import.get_current_annee
LEFT JOIN intervenant_saisie isai ON isai.intervenant_id = i2.id
LEFT JOIN dossier d ON d.intervenant_id = i2.id AND d.histo_destruction IS NULL
WHERE
i.ordre = i.min_ordre
UNION ALL
SELECT
null id,
i.code code, i.code supann_emp_id,
i.civilite_id,
i.nom_usuel, i.prenom, i.nom_patronymique,
i.date_naissance,
i.pays_naissance_id,
i.dep_naissance_id,
i.ville_naissance_code_insee, i.ville_naissance_libelle,
i.pays_nationalite_id,
i.tel_pro, i.tel_mobile, i.email,
COALESCE(i2.statut_id,i.statut_id) statut_id,
COALESCE(i2.structure_id,i.structure_id) structure_id,
i.source_id, i.source_code,
i.numero_insee, i.numero_insee_cle, i.numero_insee_provisoire,
i.iban, i.bic,
i.grade_id,
i.discipline_id,
unicaen_import.get_current_annee - 1 annee_id,
i.critere_recherche
FROM
srci i
LEFT JOIN intervenant i2 ON i2.source_code = i.source_code AND i2.annee_id = unicaen_import.get_current_annee - 1
WHERE
i.ordre = i.min_ordre
;
/
begin
unicaen_tbl.ACTIV_TRIGGERS := false;
end;
/
UPDATE intervenant SET
--nom_usuel = ,
--prenom = ,
--nom_patronymique = ,
date_naissance = TO_DATE('2000-01-01', 'yyyy-mm-dd'),
pays_naissance_id = (SELECT id FROM pays WHERE libelle_court = 'FRANCE'),
dep_naissance_id = (SELECT id FROM departement WHERE source_code = '014'),
ville_naissance_code_insee = '14118',
ville_naissance_libelle = 'CAEN',
pays_nationalite_id = (SELECT id FROM pays WHERE libelle_court = 'FRANCE'),
tel_pro = NULL,
tel_mobile = NULL,
email = 'prenom.nom@unicaen.fr',
numero_insee = CASE WHEN civilite_id = (SELECT id FROM civilite WHERE libelle_long = 'Monsieur') THEN '1000114789156' ELSE '2000114789156' END,
numero_insee_cle = CASE WHEN civilite_id = (SELECT id FROM civilite WHERE libelle_long = 'Monsieur') THEN '12' ELSE '59' END,
numero_insee_provisoire = 0,
iban = 'FR7630006000011234567890189',
bic = 'AGRIFRPPXXX'
;
-- penser à anonymiser d'abord les noms-prénoms (cf. script UnicaenCode correspondant) ! ! !
SELECT
'UPDATE dossier SET
nom_usuel = q''[' || i.nom_usuel || ']'',
nom_patronymique = q''[' || i.nom_patronymique || ']'',
prenom = q''[' || i.prenom || ']'',
date_naissance = TO_DATE(''2000-01-01'', ''yyyy-mm-dd''),
dept_naissance_id= ' || dep.id || ',
email_perso = null,
pays_naissance_id= ' || pays.id || ',
numero_insee = ' || i.numero_insee || i.numero_insee_cle || ',
numero_insee_est_provisoire = 0,
adresse = ''1, ESPLANADE DE LA PAIX, 14000, CAEN'',
email = ''prenom.nom@unicaen.fr'',
telephone = null,
rib = ''AGRIFRPPXXX-FR7630006000011234567890189''
WHERE intervenant_id = ' || i.id || ';'
|| '
' usql
FROM
intervenant i
JOIN dossier d ON d.intervenant_id = i.id
JOIN departement dep ON dep.source_code = '014'
JOIN pays ON pays.libelle_court = 'FRANCE';
update adresse_intervenant set
tel_domicile = null,
mention_complementaire=null,
batiment=null,
no_voie='1',
nom_voie='ESPLANADE DE LA PAIX',
localite=null,
code_postal='14000',
ville='CAEN',
pays_code_insee=100,
pays_libelle='FRANCE'
;
update fichier set
contenu = (select contenu from fichier where id=1),
type='application/pdf',
taille=16683,
description=null,
nom='fichier_' || id || '.pdf';
select * from fichier where id = 1;
/
begin
unicaen_tbl.ACTIV_TRIGGERS := true;
end;
/
UPDATE mv_intervenant_demo SET
--nom_usuel = ,
--prenom = ,
--nom_patronymique = ,
date_naissance = TO_DATE('2000-01-01', 'yyyy-mm-dd'),
z_pays_naissance_id = '100',
z_dep_naissance_id = '014',
ville_naissance_code_insee = '14118',
ville_naissance_libelle = 'CAEN',
z_pays_nationalite_id = '100',
tel_pro = NULL,
tel_mobile = NULL,
email = 'prenom.nom@unicaen.fr',
numero_insee = CASE WHEN z_civilite_id = 'M.' THEN '1000114789156' ELSE '2000114789156' END,
numero_insee_cle = CASE WHEN z_civilite_id = 'M.' THEN '12' ELSE '59' END,
numero_insee_provisoire = 0,
iban = 'FR7630006000011234567890189',
bic = 'AGRIFRPPXXX',
critere_recherche = ose_divers.str_reduce( nom_usuel || ' ' || nom_patronymique || ' ' || prenom )
;
/
BEGIN
DBMS_MVIEW.REFRESH('MV_INTERVENANT_RECHERCHE', 'C');
END;
/
WITH ll AS (
select l, rownum rn from (
select 'Acheteur' L FROM DUAL
union select 'Acheteur Informatique Et Télécom' L FROM DUAL
union select 'Actuaire' L FROM DUAL
union select 'Adjoint administratif' L FROM DUAL
union select 'Adjoint administratif territorial' L FROM DUAL
union select 'Adjoint technique de recherche et de formation' L FROM DUAL
union select 'Administrateur base de données' L FROM DUAL
union select 'Administrateur De Bases De Données' L FROM DUAL
union select 'Administrateur de biens' L FROM DUAL
union select 'Administrateur De Réseau' L FROM DUAL
union select 'Administrateur judiciaire' L FROM DUAL
union select 'Affréteur' L FROM DUAL
union select 'Agent administratif et agent des services techniques' L FROM DUAL
union select 'Agent de maintenance en mécanique' L FROM DUAL
union select 'Agent de maîtrise' L FROM DUAL
union select 'Agent de police municipale' L FROM DUAL
union select 'Agent de réservation' L FROM DUAL
union select 'Agent des services techniques de préfecture' L FROM DUAL
union select 'Agent immobilier' L FROM DUAL
union select 'Agent spécialisé de police technique et scientifique' L FROM DUAL
union select 'Agent technique de recherche et de formation' L FROM DUAL
union select 'Aide comptable' L FROM DUAL
union select 'Aide de laboratoire' L FROM DUAL
union select 'Aide médico-psychologique' L FROM DUAL
union select 'Aide soignant' L FROM DUAL
union select 'Aide soignant' L FROM DUAL
union select 'Aide technique de laboratoire' L FROM DUAL
union select 'Ambulancier' L FROM DUAL
union select 'Analyste financier' L FROM DUAL
union select 'Analyste programmeur' L FROM DUAL
union select 'Animateur' L FROM DUAL
union select 'Animateur' L FROM DUAL
union select 'Animateur de club de vacances' L FROM DUAL
union select 'Animateur de formation' L FROM DUAL
union select 'animateur environnement' L FROM DUAL
union select 'Animateur socioculturel' L FROM DUAL
union select 'Antiquaire' L FROM DUAL
union select 'Archéologue' L FROM DUAL
union select 'Architecte' L FROM DUAL
union select 'Architecte De Bases De Données' L FROM DUAL
union select 'Architecte De Réseau' L FROM DUAL
union select 'Architecte Matériel' L FROM DUAL
union select 'Archiviste' L FROM DUAL
union select 'Artiste-peintre' L FROM DUAL
union select 'Assistant de conservation' L FROM DUAL
union select 'Assistant de justice' L FROM DUAL
union select 'Assistant de ressources humaines' L FROM DUAL
union select 'Assistant de service social' L FROM DUAL
union select 'Assistant de service social' L FROM DUAL
union select 'Assistant des bibliothèques' L FROM DUAL
union select 'Assistant ingénieur' L FROM DUAL
union select 'Assistant médico-technique' L FROM DUAL
union select 'Assistant socio-éducatif' L FROM DUAL
union select 'Assistant son' L FROM DUAL
union select 'Assistant vétérinaire' L FROM DUAL
union select 'Assistante de gestion PMI/PME' L FROM DUAL
union select 'Assistante maternelle' L FROM DUAL
union select 'Assistante sociale' L FROM DUAL
union select 'Astronome' L FROM DUAL
union select 'Attaché de conservateur de patrimoine' L FROM DUAL
union select 'Attaché de police' L FROM DUAL
union select 'Attaché de préfecture' L FROM DUAL
union select 'Attaché de presse' L FROM DUAL
union select 'Auditeur Informatique' L FROM DUAL
union select 'Auteur-scénariste multimédia' L FROM DUAL
union select 'Auxiliaire de puériculture' L FROM DUAL
union select 'Auxiliaire de vie sociale' L FROM DUAL
union select 'Auxilliaire de vie' L FROM DUAL
union select 'Avocat' L FROM DUAL
union select 'Barman' L FROM DUAL
union select 'Bibliothécaire' L FROM DUAL
union select 'Bibliothécaire adjoint spécialisé' L FROM DUAL
union select 'Bijoutier joaillier' L FROM DUAL
union select 'Billettiste' L FROM DUAL
union select 'Bio-informaticien' L FROM DUAL
union select 'Biologiste, Vétérinaire, Pharmacien' L FROM DUAL
union select 'Bobinier de la construction électrique' L FROM DUAL
union select 'Boucher' L FROM DUAL
union select 'Boulanger' L FROM DUAL
union select 'Brasseur malteur' L FROM DUAL
union select 'Bronzier' L FROM DUAL
union select 'Bûcheron' L FROM DUAL
union select 'Cadreur' L FROM DUAL
union select 'Capitaine de Sapeur-Pompier' L FROM DUAL
union select 'Carreleur' L FROM DUAL
union select 'Carrossier réparateur' L FROM DUAL
union select 'Caviste' L FROM DUAL
union select 'Charcutier-traiteur' L FROM DUAL
union select 'Chargé de clientèle' L FROM DUAL
union select 'Chargé De Référencement' L FROM DUAL
union select 'Chargé de relations publiques' L FROM DUAL
union select 'Charpentier' L FROM DUAL
union select 'Chaudronnier' L FROM DUAL
union select 'Chef de chantier' L FROM DUAL
union select 'Chef de comptoir' L FROM DUAL
union select 'Chef de fabrication' L FROM DUAL
union select 'Chef de produits voyages' L FROM DUAL
union select 'Chef De Projet - Project Manager' L FROM DUAL
union select 'Chef de projet informatique' L FROM DUAL
union select 'Chef de projet multimedia' L FROM DUAL
union select 'Chef de publicité' L FROM DUAL
union select 'Chef de rayon' L FROM DUAL
union select 'Chef de service de Police municipale' L FROM DUAL
union select 'Chef opérateur' L FROM DUAL
union select 'Chercheur' L FROM DUAL
union select 'Chercheur En Informatique' L FROM DUAL
union select 'Chirurgien-dentiste' L FROM DUAL
union select 'Chocolatier confiseur' L FROM DUAL
union select 'Clerc de notaire' L FROM DUAL
union select 'Coiffeur' L FROM DUAL
union select 'Comédien' L FROM DUAL
union select 'Commis de cuisine' L FROM DUAL
union select 'Commissaire de police' L FROM DUAL
union select 'Commissaire priseur' L FROM DUAL
union select 'comportementaliste' L FROM DUAL
union select 'Comptable' L FROM DUAL
union select 'Concepteur De Jeux Électroniques' L FROM DUAL
union select 'Concepteur rédacteur' L FROM DUAL
union select 'Conducteur' L FROM DUAL
union select 'Conducteur de machine à imprimer simple' L FROM DUAL
union select 'Conducteur de machines' L FROM DUAL
union select 'Conducteur de machines agro' L FROM DUAL
union select 'Conducteur de taxi' L FROM DUAL
union select 'conducteur de train' L FROM DUAL
union select 'Conducteur de travaux' L FROM DUAL
union select 'Conducteur routier' L FROM DUAL
union select 'Conseiller en développement touristique' L FROM DUAL
union select 'Conseiller en économie sociale et familiale' L FROM DUAL
union select 'Conseiller socio-éducatif' L FROM DUAL
union select 'Conseiller territorial des activités physiques et sportives' L FROM DUAL
union select 'Conservateur de bibliothèque' L FROM DUAL
union select 'Conservateur du patrimoine' L FROM DUAL
union select 'Consultant E-Business' L FROM DUAL
union select 'Consultant En Conduite Du Changement' L FROM DUAL
union select 'Consultant En E-Learning' L FROM DUAL
union select 'Consultant En Gestion De La Relation Client' L FROM DUAL
union select 'Consultant En Technologies' L FROM DUAL
union select 'Consultant Erp' L FROM DUAL
union select 'Consultant Fonctionnel' L FROM DUAL
union select 'Consultant Informatique' L FROM DUAL
union select 'Contrôleur aérien' L FROM DUAL
union select 'Contrôleur de gestion' L FROM DUAL
union select 'Contrôleur de travaux' L FROM DUAL
union select 'Contrôleur des services techniques du matériel' L FROM DUAL
union select 'Contrôleur du travail' L FROM DUAL
union select 'Contrôleur en électricité et électronique' L FROM DUAL
union select 'Convoyeur de fonds' L FROM DUAL
union select 'Coordinatrice de crèches' L FROM DUAL
union select 'Correcteur' L FROM DUAL
union select 'Costumier-habilleur' L FROM DUAL
union select 'Couvreur' L FROM DUAL
union select 'Créateur de parfum' L FROM DUAL
union select 'Cuisinier' L FROM DUAL
union select 'Cyberdocumentaliste' L FROM DUAL
union select 'Danseur' L FROM DUAL
union select 'Décorateur-scénographe' L FROM DUAL
union select 'Délégué médical' L FROM DUAL
union select 'Déménageur' L FROM DUAL
union select 'Démographe' L FROM DUAL
union select 'Dépanneur tv électroménager' L FROM DUAL
union select 'Designer automobile' L FROM DUAL
union select 'Dessinateur de presse' L FROM DUAL
union select 'Dessinateur industriel' L FROM DUAL
union select 'Détective privé' L FROM DUAL
union select 'Développeur' L FROM DUAL
union select 'Diététicien' L FROM DUAL
union select 'Directeur artistique' L FROM DUAL
union select 'Directeur Commercial' L FROM DUAL
union select 'Directeur de collection' L FROM DUAL
union select 'Directeur de parc naturel' L FROM DUAL
union select 'Directeur De Projet' L FROM DUAL
union select 'Directeur de ressources humaines' L FROM DUAL
union select 'Directeur des soins' L FROM DUAL
union select 'Directeur Technique' L FROM DUAL
union select 'Docker' L FROM DUAL
union select 'Documentaliste' L FROM DUAL
union select 'Douanier' L FROM DUAL )
)
select
'update fonction_referentiel SET libelle_court = q''[' || ll.l || ']'', libelle_long = q''[' || ll.l || ']'' WHERE id = ' || fr.id || ';' usql
from
fonction_referentiel fr
JOIN ll ON ll.rn = fr.id
ORDER BY rownum;
DELETE FROM indic_modif_dossier;
SELECT
i.annee_id, i.nom_usuel, i.prenom, i.code, si.source_code
FROM
v_diff_intervenant i
JOIN statut_intervenant si ON si.id = i.statut_id
WHERE
import_action = 'insert'
AND si.source_code <> 'AUTRES' AND si.source_code <> 'BIATSS' AND si.source_code <> 'NON_AUTORISE'
AND rownum < 50
AND i.annee_id = 2017
-- activer l'année :
UPDATE ANNEE SET ACTIVE = '1' WHERE ID = 2016;
-- mettre à jour les dates de campagne de saisie
-- maj des paramètres
SELECT
'
INSERT INTO element_pedagogique (
ID,
LIBELLE,
ETAPE_ID,
STRUCTURE_ID,
PERIODE_ID,
TAUX_FI, TAUX_FC, TAUX_FA,
TAUX_FOAD,
FI, FC, FA,
SOURCE_ID, SOURCE_CODE,
HISTO_CREATION, HISTO_CREATEUR_ID,
HISTO_MODIFICATION, HISTO_MODIFICATEUR_ID,
ANNEE_ID,
DISCIPLINE_ID
) VALUES (
element_pedagogique_id_seq.nextval,
q''[' || ep.libelle || ']'',
' || ep.etape_id || ',
' || ep.structure_id || ',
' || NVL(to_char(ep.periode_id), 'NULL') || ',
' || TRIM(TO_CHAR(ep.taux_fi, '999.99')) || ', ' || TRIM(TO_CHAR(ep.taux_fc, '999.99')) || ', ' || TRIM(TO_CHAR(ep.taux_fa, '999.99')) || ',
' || TRIM(TO_CHAR(ep.taux_foad, '999.99')) || ',
' || TRIM(TO_CHAR(ep.fi, '999.99')) || ', ' || TRIM(TO_CHAR(ep.fc, '999.99')) || ', ' || TRIM(TO_CHAR(ep.fa, '999.99')) || ',
' || ep.source_id || ', q''[' || ep.source_code || ']'',
SYSDATE, ' || u.id || ',
SYSDATE, ' || u.id || ',
' || (ep.annee_id + 1) || ',
' || NVL(to_char(ep.discipline_id), 'NULL') || '
);
INSERT INTO chemin_pedagogique(
ID,
ELEMENT_PEDAGOGIQUE_ID,
ETAPE_ID,
ORDRE,
SOURCE_ID, SOURCE_CODE,
HISTO_CREATION, HISTO_CREATEUR_ID,
HISTO_MODIFICATION, HISTO_MODIFICATEUR_ID
) VALUES (
chemin_pedagogique_id_seq.nextval,
element_pedagogique_id_seq.currval,
' || ep.etape_id || ',
' || rownum || ',
' || ep.source_id || ', q''[' || e.source_code || '_' || ep.source_code || '_' || (ep.annee_id + 1) || ']'',
SYSDATE, ' || u.id || ',
SYSDATE, ' || u.id || '
);
' isql
FROM
element_pedagogique ep
JOIN etape e ON e.id = ep.etape_id
JOIN source s ON ep.source_id = s.id AND s.code = 'OSE'
JOIN utilisateur u ON u.username = 'lecluse'
WHERE
ep.annee_id = 2015
AND 1 = ose_divers.comprise_entre( ep.histo_creation, ep.histo_destruction )
;
-- réaliser l'import
-- modulateurs
SELECT
'INSERT INTO ELEMENT_MODULATEUR(
ID,
ELEMENT_ID,
MODULATEUR_ID,
HISTO_CREATION, HISTO_CREATEUR_ID,
HISTO_MODIFICATION, HISTO_MODIFICATEUR_ID
)VALUES(
ELEMENT_MODULATEUR_ID_SEQ.NEXTVAL,
' || ep2.id || ',
' || m.id || ',
SYSDATE, (SELECT id FROM utilisateur WHERE username=''lecluse''),
SYSDATE, (SELECT id FROM utilisateur WHERE username=''lecluse'')
);' isql
FROM
element_modulateur em
JOIN element_pedagogique ep ON ep.id = em.element_id
JOIN element_pedagogique ep2 ON ep2.source_code = ep.source_code
AND ep2.annee_id = ep.annee_id + 1
JOIN modulateur m ON m.id = em.modulateur_id
AND 1 = ose_divers.comprise_entre( m.histo_creation, m.histo_destruction )
JOIN type_modulateur tm ON tm.id = m.type_modulateur_id
AND 1 = ose_divers.comprise_entre( tm.histo_creation, tm.histo_destruction )
JOIN type_modulateur_ep tmep ON tmep.type_modulateur_id = m.type_modulateur_id
AND tmep.element_pedagogique_id = ep2.id
AND 1 = ose_divers.comprise_entre( tmep.histo_creation, tmep.histo_destruction )
WHERE
1 = ose_divers.comprise_entre( em.histo_creation, em.histo_destruction )
AND ep.annee_id = 2015;
-- centres de coûts
SELECT
'INSERT INTO CENTRE_COUT_EP(
ID,
CENTRE_COUT_ID,
ELEMENT_PEDAGOGIQUE_ID,
TYPE_HEURES_ID,
SOURCE_ID,
SOURCE_CODE,
HISTO_CREATION, HISTO_CREATEUR_ID,
HISTO_MODIFICATION, HISTO_MODIFICATEUR_ID
)VALUES(
CENTRE_COUT_EP_ID_SEQ.NEXTVAL,
' || CCE.CENTRE_COUT_ID || ',
' || ep2.id || ',
' || CCE.type_heures_id || ',
' || CCE.source_id || ',
''N-1toN_'' || CENTRE_COUT_EP_ID_SEQ.CURRVAL,
SYSDATE, (SELECT id FROM utilisateur WHERE username=''lecluse''),
SYSDATE, (SELECT id FROM utilisateur WHERE username=''lecluse'')
);' isql
FROM
centre_cout_ep cce
JOIN element_pedagogique ep ON ep.id = CCE.ELEMENT_PEDAGOGIQUE_ID
JOIN element_pedagogique ep2 ON ep2.source_code = ep.source_code
AND ep2.annee_id = ep.annee_id + 1
WHERE
1 = ose_divers.comprise_entre( cce.histo_creation, cce.histo_destruction )
AND ep.annee_id = 2015;
SELECT
'INSERT INTO ELEMENT_MODULATEUR(
ID,
ELEMENT_ID,
MODULATEUR_ID,
HISTO_CREATION, HISTO_CREATEUR_ID,
HISTO_MODIFICATION, HISTO_MODIFICATEUR_ID
)VALUES(
ELEMENT_MODULATEUR_ID_SEQ.NEXTVAL,
' || ep2.id || ',
' || m.id || ',
SYSDATE, (SELECT id FROM utilisateur WHERE username=''lecluse''),
SYSDATE, (SELECT id FROM utilisateur WHERE username=''lecluse'')
);' isql
FROM
element_modulateur em
JOIN element_pedagogique ep ON ep.id = em.element_id
JOIN element_pedagogique ep2 ON ep2.source_code = ep.source_code
AND ep2.annee_id = ep.annee_id + 1
JOIN modulateur m ON m.id = em.modulateur_id
AND 1 = ose_divers.comprise_entre( m.histo_creation, m.histo_destruction )
JOIN type_modulateur tm ON tm.id = m.type_modulateur_id
AND 1 = ose_divers.comprise_entre( tm.histo_creation, tm.histo_destruction )
JOIN type_modulateur_ep tmep ON tmep.type_modulateur_id = m.type_modulateur_id
AND tmep.element_pedagogique_id = ep2.id
AND 1 = ose_divers.comprise_entre( tmep.histo_creation, tmep.histo_destruction )
WHERE
1 = ose_divers.comprise_entre( em.histo_creation, em.histo_destruction )
AND ep.annee_id = 2015;
\ No newline at end of file
SELECT
i.nom_usuel,
i.prenom,
si.libelle
FROM
intervenant i
JOIN statut_intervenant si ON si.id = i.statut_id
JOIN type_intervenant ti ON ti.id = si.type_intervenant_id
JOIN (select intervenant_id from tbl_workflow group by intervenant_id having sum(realisation) = 0) w ON w.intervenant_id = i.id
WHERE
i.annee_id = 2017
AND ti.code = 'E'
--AND si.libelle = 'BIATSS'
;
select intervenant_id from tbl_workflow group by intervenant_id having sum(realisation) = 0
\ No newline at end of file
-- Destruction de toute un schéma de BDD !!! ATTENTION ARCHTUNG CAUTION
SELECT 'DROP TRIGGER ' || trigger_name || ';' dsql
FROM ALL_TRIGGERS WHERE owner='DEPLOY'
UNION SELECT 'ALTER TABLE ' || table_name || ' DROP CONSTRAINT ' || constraint_name || ';' dsql
FROM ALL_CONSTRAINTS WHERE owner='DEPLOY' AND constraint_type = 'R'
UNION SELECT 'DROP SEQUENCE ' || sequence_name || ';' dsql
FROM ALL_SEQUENCES WHERE sequence_owner='DEPLOY'
UNION SELECT 'DROP VIEW ' || view_name || ';' dsql
FROM ALL_VIEWS WHERE owner = 'DEPLOY'
UNION SELECT 'DROP MATERIALIZED VIEW ' || mview_name || ';' dsql
FROM ALL_MVIEWS WHERE owner = 'DEPLOY'
UNION SELECT 'DROP INDEX ' || index_name || ';' dsql
FROM ALL_INDEXES WHERE owner = 'DEPLOY'
UNION SELECT 'DROP PACKAGE ' || object_name || ';' dsql
FROM USER_OBJECTS WHERE object_type = 'PACKAGE'
UNION SELECT 'DROP TABLE ' || table_name || ';' dsql
FROM ALL_TABLES WHERE owner='DEPLOY'
-- répétition pour ne rien oublier!!!
UNION SELECT 'DROP TABLE ' || table_name || ';' dsql
FROM ALL_TABLES WHERE owner='DEPLOY'
-- jobs
--UNION SELECT '
--/
--BEGIN
-- DBMS_SCHEDULER.DROP_JOB(job_name => ''MAJ_ALL_TBL'', defer => false, force => true);
-- DBMS_SCHEDULER.DROP_JOB(job_name => ''OSE_CHARGENS_CALCUL_EFFECTIFS'', defer => false, force => true);
-- DBMS_SCHEDULER.DROP_JOB(job_name => ''OSE_FORMULE_REFRESH'', defer => false, force => true);
-- DBMS_SCHEDULER.DROP_JOB(job_name => ''OSE_SRC_SYNC'', defer => false, force => true);
-- DBMS_SCHEDULER.DROP_JOB(job_name => ''PURGE_EM_NON_FC'', defer => false, force => true);
--END;
--' dsql
--FROM dual
--;
select
ep.id id,
ep.source_code code,
ep.libelle libelle,
e.id etape_id,
cp.etape_id cp_id,
e.libelle etape_libelle
from
element_pedagogique ep
LEFT JOIN chemin_pedagogique cp ON cp.element_pedagogique_id = ep.id AND cp.histo_destruction IS NULL
JOIN etape e ON e.id = ep.etape_id OR e.id = cp.etape_id AND e.histo_destruction IS NULL
WHERE
ep.histo_destruction IS NULL
AND ep.source_id = ose_import.get_source_id('OSE');
order by
code, statut, etape_libelle;
select * from chemin_pedagogique cp where cp.element_pedagogique_id = 16773;
select * from element_pedagogique ep where id = 16773;
select * from etape where id = 1551;
select * from (
select ep.id,
rank() over (partition by ep.id order by cp.ordre) rang,
count(*) over (partition by ep.id) nb_ch,
ep.source_code, ep.libelle, e.libelle libelle_etape, e.niveau, gtf.libelle_court libelle_gtf, tf.libelle_long libelle_tf,
ep.source_code || ' ' || ep.libelle|| ' ' || e.source_code || ' ' || e.libelle || ' ' || gtf.LIBELLE_COURT || ' ' || e.NIVEAU || ' ' || tf.LIBELLE_COURT etape_info
from chemin_pedagogique cp
JOIN element_pedagogique ep ON cp.element_pedagogique_id = ep.id and ep.HISTO_DESTRUCTEUR_ID is null and sysdate between ep.VALIDITE_DEBUT and nvl(ep.VALIDITE_FIN, sysdate)
JOIN etape e ON cp.etape_id = e.id and e.HISTO_DESTRUCTEUR_ID is null and sysdate between e.VALIDITE_DEBUT and nvl( e.VALIDITE_FIN, sysdate)
JOIN TYPE_FORMATION tf on e.TYPE_FORMATION_ID = tf.ID
JOIN GROUPE_TYPE_FORMATION gtf on tf.GROUPE_ID = gtf.ID
JOIN structure s ON ep.structure_id = s.id
where ep.id = 16773
)
where rang = 1
\ No newline at end of file
INSERT INTO ETABLISSEMENT(
LIBELLE,
-- LOCALISATION,
-- DEPARTEMENT,
SOURCE_CODE,
ID, SOURCE_ID, HISTO_CREATEUR_ID, HISTO_MODIFICATEUR_ID
)VALUES(
'Formations continues inter-entreprises',
-- '',
-- '',
'fc-inter-entreprises',
ETABLISSEMENT_id_seq.nextval, OSE_IMPORT.GET_SOURCE_ID('OSE'), 1, 1
);
-- CREATE OR REPLACE FORCE VIEW "OSE"."V_TBL_SERVICE_EXPORT" ("SERVICE_ID", "ANNEE_ID", "TYPE_VOLUME_HORAIRE_ID", "ETAT_VOLUME_HORAIRE_ID", "TYPE_INTERVENANT_ID", "STRUCTURE_AFF_ID", "INTERVENANT_ID", "STRUCTURE_ENS_ID", "NIVEAU_FORMATION_ID", "ETAPE_ID", "ELEMENT_PEDAGOGIQUE_ID", "INTERVENANT_CODE", "INTERVENANT_NOM", "INTERVENANT_STATUT_LIBELLE", "INTERVENANT_TYPE_LIBELLE", "SERVICE_STRUCTURE_AFF_LIBELLE", "SERVICE_STRUCTURE_ENS_LIBELLE", "ETABLISSEMENT_LIBELLE", "ETAPE_CODE", "ETAPE_LIBELLE", "ELEMENT_CODE", "ELEMENT_LIBELLE", "COMMENTAIRES", "ELEMENT_PERIODE_LIBELLE", "ELEMENT_PONDERATION_COMPL", "ELEMENT_SOURCE_LIBELLE", "HEURES_SERVICE", "HEURES_REELLES", "HEURES_SERVICE_STATUTAIRE", "HEURES_SERVICE_DU_MODIFIE", "HEURES_ASSUREES", "HEURES_SOLDE", "HEURES_NON_PAYEES", "HEURES_REFERENTIEL") AS
SELECT
s.id service_id,
vh.id volume_horaire_id,
s.annee_id annee_id,
fr.type_volume_horaire_id type_volume_horaire_id,
evh.id etat_volume_horaire_id,
ti.id type_intervenant_id,
saff.id structure_aff_id,
i.id intervenant_id,
sens.id structure_ens_id,
enf.niveau_formation_id niveau_formation_id,
etp.id etape_id,
ep.id element_pedagogique_id,
i.source_code intervenant_code,
i.nom_usuel || ' ' || i.prenom intervenant_nom,
si.libelle intervenant_statut_libelle,
ti.libelle intervenant_type_libelle,
saff.libelle_court service_structure_aff_libelle,
sens.libelle_court service_structure_ens_libelle,
etab.libelle etablissement_libelle,
etp.source_code etape_code,
etp.libelle etape_libelle,
ep.source_code element_code,
ep.libelle element_libelle,
null commentaires,
p.libelle_court element_periode_libelle,
CASE WHEN fs.ponderation_service_compl = 1 THEN NULL ELSE fs.ponderation_service_compl END element_ponderation_compl,
src.libelle element_source_libelle,
vh.type_intervention_id type_intervention_id,
vh.heures heures_reelles,
si.service_statutaire heures_service_statutaire,
fsm.heures heures_service_du_modifie,
frvh.service_assure heures_assurees,
fr.heures_solde heures_solde,
0 heures_referentiel
FROM
formule_resultat_vh frvh
JOIN volume_horaire vh
JOIN service s ON s.id = vh.service_id
JOIN intervenant i ON i.id = s.intervenant_id AND ose_divers.comprise_entre( i.histo_creation, i.histo_destruction ) = 1
JOIN statut_intervenant si ON si.id = i.statut_id
JOIN type_intervenant ti ON ti.id = si.type_intervenant_id
JOIN structure sens ON sens.id = s.structure_ens_id
JOIN etablissement etab ON etab.id = s.etablissement_id
JOIN formule_resultat fr ON fr.intervenant_id = i.id AND fr.annee_id = s.annee_id AND fr.type_volume_horaire_id = vh.type_volume_horaire_id
JOIN etat_volume_horaire evh ON evh.id = fr.etat_volume_horaire_id
LEFT JOIN structure saff ON saff.id = s.structure_aff_id AND ti.code = 'P'
LEFT JOIN element_pedagogique ep ON ep.id = s.element_pedagogique_id
LEFT JOIN periode p ON p.id = vh.periode_id
LEFT JOIN source src ON src.id = ep.source_id
LEFT JOIN etape etp ON etp.id = ep.etape_id
LEFT JOIN v_etape_niveau_formation enf ON enf.etape_id = etp.id
LEFT JOIN v_formule_service_modifie fsm ON fsm.intervenant_id = i.id AND fsm.annee_id = s.annee_id
LEFT JOIN v_formule_service fs ON fs.id = s.id
LEFT JOIN formule_resultat_vh frvh ON frvh.volume_horaire_id = vh.id AND frvh.formule_resultat_id = fr.id
WHERE
ose_divers.comprise_entre( s.histo_creation, s.histo_destruction ) = 1
AND ose_divers.comprise_entre( vh.histo_creation, vh.histo_destruction ) = 1
;
UNION
SELECT
-1 service_id,
null volume_horaire_id,
sr.annee_id annee_id,
fr.type_volume_horaire_id type_volume_horaire_id,
fr.etat_volume_horaire_id etat_volume_horaire_id,
ti.id type_intervenant_id,
CASE WHEN ti.code = 'E' THEN NULL ELSE saff.id END structure_aff_id,
i.id intervenant_id,
sens.id structure_ens_id,
-1 niveau_formation_id,
-1 etape_id,
-1 element_pedagogique_id,
i.source_code intervenant_code,
i.nom_usuel || ' ' || i.prenom intervenant_nom,
si.libelle intervenant_statut_libelle,
ti.libelle intervenant_type_libelle,
saff.libelle_court service_structure_aff_libelle,
sens.libelle_court service_structure_ens_libelle,
null etablissement_libelle,
null etape_code,
null etape_libelle,
fonc.code element_code,
fonc.libelle_court element_libelle,
sr.commentaires commentaires,
null element_periode_libelle,
null element_ponderation_compl,
src.libelle element_source_libelle,
null type_intervention_id,
sr.heures heures_reelles,
si.service_statutaire heures_service_statutaire,
fsm.heures heures_service_du_modifie,
frr.service_assure heures_assurees,
fr.heures_solde heures_solde,
0 heures_non_payees,
sr.heures heures_referentiel
FROM
service_referentiel sr
JOIN fonction_referentiel fonc ON fonc.id = sr.fonction_id
JOIN intervenant i ON i.id = sr.intervenant_id AND ose_divers.comprise_entre( i.histo_creation, i.histo_destruction ) = 1
JOIN statut_intervenant si ON si.id = i.statut_id
JOIN type_intervenant ti ON ti.id = si.type_intervenant_id
JOIN structure sens ON sens.id = sr.structure_id
JOIN formule_resultat fr ON fr.intervenant_id = i.id
JOIN source src ON src.code = 'OSE'
LEFT JOIN structure saff ON saff.id = i.structure_id AND ti.code = 'P'
LEFT JOIN v_formule_service_modifie fsm ON fsm.intervenant_id = i.id AND fsm.annee_id = fr.annee_id
LEFT JOIN formule_resultat_referentiel frr ON frr.service_referentiel_id = sr.id AND frr.formule_resultat_id = fr.id
WHERE
ose_divers.comprise_entre( sr.histo_creation, sr.histo_destruction ) = 1;
-- CREATE OR REPLACE FORCE VIEW "OSE"."V_TBL_SERVICE_EXPORT_VH" ("SERVICE_ID", "ANNEE_ID", "TYPE_VOLUME_HORAIRE_ID", "ETAT_VOLUME_HORAIRE_ORDRE", "TYPE_INTERVENANT_ID", "STRUCTURE_AFF_ID", "INTERVENANT_ID", "STRUCTURE_ENS_ID", "NIVEAU_FORMATION_ID", "ETAPE_ID", "ELEMENT_PEDAGOGIQUE_ID", "TYPE_INTERVENTION_ID", "HEURES") AS
SELECT
vh.type_volume_horaire_id type_volume_horaire_id,
evh.ordre etat_volume_horaire_ordre,
ti.id type_intervenant_id,
CASE WHEN ti.code = 'E' THEN NULL ELSE saff.id END structure_aff_id,
i.id intervenant_id,
sens.id structure_ens_id,
enf.niveau_formation_id niveau_formation_id,
etp.id etape_id,
ep.id element_pedagogique_id,
vh.type_intervention_id type_intervention_id,
vh.heures heures
FROM
volume_horaire vh
JOIN v_volume_horaire_etat vhe ON vhe.volume_horaire_id = vh.id
JOIN service s ON s.id = vh.service_id AND ose_divers.comprise_entre( s.histo_creation, s.histo_destruction ) = 1
JOIN intervenant i ON i.id = s.intervenant_id AND ose_divers.comprise_entre( i.histo_creation, i.histo_destruction ) = 1
JOIN type_intervenant ti ON ti.id = i.type_id
JOIN structure saff ON saff.id = s.structure_aff_id
JOIN structure sens ON sens.id = s.structure_ens_id
JOIN etablissement etab ON etab.id = s.etablissement_id
JOIN etat_volume_horaire evh ON evh.id = vhe.etat_volume_horaire_id
LEFT JOIN element_pedagogique ep ON ep.id = s.element_pedagogique_id
LEFT JOIN etape etp ON etp.id = ep.etape_id
LEFT JOIN v_etape_niveau_formation enf ON enf.etape_id = etp.id
WHERE
ose_divers.comprise_entre( vh.histo_creation, vh.histo_destruction ) = 1;
type_volume_horaire_id
etat_volume_horaire_id
etat_volume_horaire_ordre
type_intervenant_id
intervenant_id
niveau_formation_id
etape_id
element_pedagogique_id
structure_aff_id
structure_ens_id
INTERVENANT_CODE
INTERVENANT_NOM
INTERVENANT_STATUT_LIBELLE
INTERVENANT_TYPE_LIBELLE
SERVICE_STRUCTURE_AFF_LIBELLE
SERVICE_STRUCTURE_ENS_LIBELLE
ETABLISSEMENT_LIBELLE
ETAPE_CODE
ETAPE_LIBELLE
ELEMENT_CODE
ELEMENT_LIBELLE
ELEMENT_PERIODE_LIBELLE
ELEMENT_PONDERATION_COMPL
ELEMENT_SOURCE_LIBELLE
COMMENTAIRES
HEURES_SERVICE_STATUTAIRE
HEURES_SERVICE_DU_MODIFIE
HEURES_REELLES
HEURES_ASSUREES
HEURES_SOLDE
HEURES_NON_PAYEES
HEURES_SERVICE
HEURES_REFERENTIEL
SERVICE_ID,
TYPE_INTERVENTION_ID,
HEURES;
select
vh.*
from
volume_horaire vh
--left join formule_resultat_vh frvh on frvh.volume_horaire_id = vh.id
WHERE
vh.histo_destruction IS NULL AND vh.motif_non_paiement_id IS NULL
/
SET SERVEROUTPUT ON;
/
begin
-- UNICAEN_OSE_FORMULE.DEBUG_RESULTAT_V2( 548, 2014, 1, 1, 104 );
ose_formule.calculer_tout;
end;
/
select * from intervenant where id = 528;
SELECT * FROM formule_resultat WHERE intervenant_id = (select id from intervenant where source_code = '18009');
update service set histo_destruction = sysdate, histo_destructeur_id = 1 where id = 16425;
SELECT
i.annee_id,
i.id i_id,
i.source_code i_code,
i.nom_usuel || ' ' || i.prenom i_nom,
fr.type_volume_horaire_id,
fr.etat_volume_horaire_id,
frs.service_id,
frs.id frs_id
FROM
formule_resultat_service frs
JOIN formule_resultat fr ON fr.id = FRS.FORMULE_RESULTAT_ID
JOIN intervenant i ON i.id = fr.intervenant_id
WHERE
i.id = 630
;
select
i_id, i_code, i_nom, round(hetd,2), round(sum(hetd_vh),2), count(*)
from (SELECT
fr.annee_id annee_id,
i.id i_id,
i.source_code i_code,
i.nom_usuel || ' ' || i.prenom i_nom,
fr.type_volume_horaire_id,
fr.etat_volume_horaire_id,
fr.service_assure-fr.referentiel hetd,
vh.service_id,
frvh.volume_horaire_id,
frvh.service_assure hetd_vh,
vh.heures
FROM
formule_resultat_vh frvh
JOIN formule_resultat fr ON fr.id = frvh.FORMULE_RESULTAT_ID
JOIN intervenant i ON i.id = fr.intervenant_id
JOIN volume_horaire vh ON vh.id = frvh.volume_horaire_id
JOIN v_volume_horaire_etat vhe ON vhe.volume_horaire_id = vh.id AND vhe.etat_volume_horaire_id >= fr.etat_volume_horaire_id
where
fr.etat_volume_horaire_id = 1
) t1
group by
i_id, i_code, i_nom, hetd
having round(hetd,10) <> round(sum(hetd_vh),10)
\ No newline at end of file
SELECT
i.*
FROM
all_indexes i
LEFT JOIN all_constraints c ON c.index_name = i.index_name
WHERE
i.owner='OSE'
AND c.constraint_name IS NULL;
-- enlever _IDX des indexes
select
'ALTER INDEX ' || index_name || ' RENAME TO ' || new_index_name || ';' isql
from (
SELECT
index_name, substr( index_name, 1, length(index_name)-4 ) new_index_name
FROM
all_indexes i
WHERE
owner='OSE'
AND substr( index_name, -3 ) = 'IDX') t1;
-- création d'indexes manquants
SELECT
'CREATE' || un || ' INDEX ' || constraint_name || ' ON ' || table_name || ' (' || cols || ') LOGGING;' isql
FROM (
SELECT
c.constraint_name,
c.constraint_type,
c.table_name,
c.r_constraint_name,
c.index_name,
ose_divers.implode('SELECT column_name FROM all_cons_columns WHERE owner=''OSE'' AND constraint_name=q''[' || c.constraint_name || ']''', ' ASC,') || ' ASC' cols,
CASE WHEN c.constraint_type IN ('P','U') THEN ' UNIQUE' ELSE '' END un
FROM
all_constraints c
LEFT JOIN all_indexes i ON i.index_name = c.constraint_name
WHERE
c.owner = 'OSE'
AND c.constraint_type IN ('P', 'U', 'R')
AND c.table_name NOT LIKE 'BIN$%'
AND c.index_name IS NULL AND i.index_name IS NULL
) t1;
SELECT * FROM all_tables where owner = 'OSE';
select * from all_views where owner='OSE';
select * from SYS.all_cons_columns;
-- CREATE INDEX INTERVENANT_HDFK_IDX ON INTERVENANT (HISTO_DESTRUCTEUR_ID ASC) TABLESPACE OSE_TS LOGGING;
-- CREATE UNIQUE INDEX INTERVENANT_SOURCE__UN ON INTERVENANT ( SOURCE_CODE ASC, ANNEE_ID ASC ) LOGGING;
--SUBSTR(constraint_name,0,26)
\ No newline at end of file
/**
* Création d'un nouvel indicateur.
*/
Insert into INDICATEUR (ID,CODE,TYPE,ORDRE,ENABLED) values (
indicateur_id_seq.nextval,
'AttenteValidationEnsPrevuPerm',
'Enseignements et référentiel',
'325',
'1'
);
select count(*) from v_indicateur_650;
-- 310
-- 330
-- 630
-- 640
-- 650
SELECT rownum id, t."ANNEE_ID",t."INTERVENANT_ID",t."STRUCTURE_ID" FROM
(
SELECT DISTINCT
w.annee_id,
w.intervenant_id,
w.structure_id
FROM
tbl_workflow w
JOIN tbl_workflow wc ON wc.intervenant_id = w.intervenant_id
WHERE
w.etape_code = 'SERVICE_VALIDATION_REALISE'
AND w.objectif > w.realisation
AND w.atteignable = 1
AND wc.etape_code = 'CLOTURE_REALISE'
AND wc.objectif = wc.realisation
) t;
select count(*) from tbl_workflow
\ No newline at end of file
SELECT * FROM
(
SELECT
'contrat' categorie,
ca.no_dossier_pers code,
ct.c_type_contrat_trav contrat_code,
tct.ll_type_contrat_trav contrat_libelle,
null type_population_code,
null type_population_libelle,
ca.d_deb_contrat_trav date_deb,
COALESCE(ca.d_fin_execution,ca.d_fin_contrat_trav) date_fin,
CASE WHEN
SYSDATE BETWEEN ca.d_deb_contrat_trav-1 AND COALESCE(ca.d_fin_execution,ca.d_fin_contrat_trav,SYSDATE)+1
THEN 1 ELSE 0 END actuel
FROM
contrat_avenant@harpprod ca
JOIN contrat_travail@harpprod ct ON ct.no_dossier_pers = ca.no_dossier_pers AND ct.no_contrat_travail = ca.no_contrat_travail
JOIN type_contrat_travail@harpprod tct ON tct.c_type_contrat_trav = ct.c_type_contrat_trav
WHERE
SYSDATE BETWEEN ca.d_deb_contrat_trav-184 AND COALESCE(ca.d_fin_execution,ca.d_fin_contrat_trav,SYSDATE)+184
UNION ALL
SELECT
'affectation' categorie,
a.no_dossier_pers code,
null contrat_code,
null contrat_libelle,
c.c_type_population type_population_code,
tp.ll_type_population type_population_libelle,
a.d_deb_affectation date_deb,
a.d_fin_affectation date_fin,
CASE WHEN
SYSDATE BETWEEN a.d_deb_affectation-1 AND COALESCE(a.d_fin_affectation,SYSDATE)+1
THEN 1 ELSE 0 END actuel
FROM
affectation@harpprod a
LEFT JOIN carriere@harpprod c ON c.no_dossier_pers = a.no_dossier_pers AND c.no_seq_carriere = a.no_seq_carriere
LEFT JOIN type_population@harpprod tp ON tp.c_type_population = c.c_type_population
WHERE
SYSDATE BETWEEN a.d_deb_affectation-184 AND COALESCE(a.d_fin_affectation,SYSDATE)+184
UNION ALL
SELECT
'chercheur' categorie,
ch.no_individu code,
null contrat_code,
null contrat_libelle,
null type_population_code,
null type_population_libelle,
ch.d_deb_str_trav date_deb,
ch.d_fin_str_trav date_fin,
CASE WHEN
SYSDATE BETWEEN ch.d_deb_str_trav-1 AND COALESCE(ch.d_fin_str_trav,SYSDATE)+1
THEN 1 ELSE 0 END actuel
FROM
chercheur@harpprod ch
WHERE
SYSDATE BETWEEN ch.d_deb_str_trav-184 AND COALESCE(ch.d_fin_str_trav,SYSDATE)+184
) i
WHERE
1=1
AND i.code = 128693;
\ No newline at end of file
select * from intervenant WHERE source_id =2;
INSERT INTO INTERVENANT (
ID, civilite_id, code, nom_usuel, prenom, nom_patronymique, date_naissance,
statut_id, structure_id, annee_id, pays_naissance_id, source_id, source_code,
histo_creation, histo_createur_id, histo_modification, histo_modificateur_id
) SELECT
1,--INTERVENANT_ID_SEQ.NEXTVAL id,
c.id, i.code, i.nom_usuel, i.prenom, i.nom_patronymique, TO_DATE(i.date_naissance, 'DD/MM/YYYY'),
i.statut_id, i.structure_id, i.annee_id, pn.id, s.id, i.code, sysdate, u.id, sysdate, u.id
FROM
(
SELECT
'99999948' code,
'Madame' civilite, -- Monsieur ou Madame
'Boukcker' nom_usuel,
'Anne' prenom,
'Boukcker' nom_patronymique,
'22/11/1967' date_naissance, -- varchar format 'DD/MM/YYYY'
31 statut_id,
102 structure_id,
2017 annee_id,
'FRANCE' pays_naissance
FROM dual
UNION SELECT
'99999948' code,
'Madame' civilite, -- Monsieur ou Madame
'Boukcker' nom_usuel,
'Anne' prenom,
'Boukcker' nom_patronymique,
'22/11/1967' date_naissance, -- varchar format 'DD/MM/YYYY'
31 statut_id,
102 structure_id,
2017 annee_id,
'FRANCE' pays_naissance
FROM dual
) i
JOIN civilite c ON c.libelle_long = i.civilite
JOIN pays pn ON pn.libelle_court = i.pays_naissance
JOIN source s ON s.code = 'OSE'
JOIN utilisateur u ON u.username = 'lecluse'
;
select * from pays where libelle_long like 'FR%'
;
select * from utilisateur
\ No newline at end of file
SELECT * FROM carriere@harpprod c WHERE c.no_dossier_pers = 18327;
SELECT * FROM contrat_travail@harpprod ct WHERE ct.no_dossier_pers = 18327;
SELECT * FROM contrat_avenant@harpprod ca WHERE ca.no_dossier_pers = 18327;
SELECT * FROM chercheur@harpprod ch WHERE ch.no_individu = 18327;
SELECT * FROM affectation@harpprod a WHERE a.no_dossier_pers = 18327;
SELECT * FROM affectation_recherche@harpprod ar WHERE ar.no_dossier_pers = 18327;
SELECT * FROM individu_fonct_struct@harpprod ifs WHERE ifs.no_dossier_pers = 18327;
-----------------------------------------------------------------------
-- Recherche de vacataires ayant le statut "Autres" et un persopass.
-----------------------------------------------------------------------
select i.nom_usuel, i.prenom, i.source_code, ucbn_ldap.hid2alias(i.source_code) login
from intervenant_exterieur ie
join intervenant i on i.id = ie.id
left join dossier d on d.intervenant_id = ie.id
where d.id is null and i.annee_id = 2014 and i.statut_id = 19
and ucbn_ldap.hid2alias(i.source_code) is not null
;
\ No newline at end of file
SELECT
'OSE' C_SOURCE,
i.code C_SRC_INDIVIDU,
s.source_code C_SRC_STRUCTURE,
4 TYPE_ID,
i.id || '_' || s.id ID_ORIG,
a.date_debut DATE_DEBUT,
a.date_fin DATE_FIN,
CASE WHEN i.structure_id = s.id THEN 1 ELSE 0 END T_PRINCIPALE
FROM
tbl_service ts
JOIN intervenant i ON i.id = ts.intervenant_id
JOIN annee a ON a.id = ts.annee_id
JOIN structure s ON s.id = ts.structure_id
WHERE
ts.type_volume_horaire_code = 'PREVU'
AND ts.valide > 0
AND SYSDATE BETWEEN a.date_debut AND a.date_fin -- pour ne prendre que les intervenants actuels
GROUP BY
i.id, i.code, i.structure_id,
s.id, s.source_code,
a.date_debut, a.date_fin
;
\ No newline at end of file
SELECT
annee, i_nom, i_code, sum(dues) dues, sum(payees) payees, sum(trop_paye) trop_paye
FROM
(SELECT
i.annee_id annee,
i.prenom || ' ' || i.nom_usuel i_nom,
i.source_code i_code,
AVG(frs.heures_compl_fi + frs.heures_compl_fa + frs.heures_compl_fc + frs.heures_compl_fc_majorees) dues,
SUM(mep.heures) payees,
SUM(mep.heures) - AVG(frs.heures_compl_fi + frs.heures_compl_fa + frs.heures_compl_fc + frs.heures_compl_fc_majorees) trop_paye
FROM
formule_resultat_service frs
JOIN formule_resultat fr ON fr.id = frs.formule_resultat_id
JOIN type_volume_horaire tvh ON tvh.id = fr.type_volume_horaire_id AND tvh.code = 'REALISE'
JOIN etat_volume_horaire evh ON evh.id = fr.etat_volume_horaire_id AND evh.code = 'valide'
JOIN intervenant i ON i.id = fr.intervenant_id
LEFT JOIN mise_en_paiement mep ON mep.formule_res_service_id = frs.id AND 1 = ose_divers.comprise_entre( mep.histo_creation, mep.histo_destruction )
GROUP BY
frs.service_id, i.id, i.prenom, i.nom_usuel, i.source_code, i.annee_id
HAVING
ABS(SUM(mep.heures) - AVG(frs.heures_compl_fi + frs.heures_compl_fa + frs.heures_compl_fc + frs.heures_compl_fc_majorees)) > 0.01
UNION ALL
SELECT
i.annee_id annee,
i.prenom || ' ' || i.nom_usuel i_nom,
i.source_code i_code,
AVG(frs.heures_compl_referentiel) dues,
SUM(mep.heures) payees,
SUM(mep.heures) - AVG(frs.heures_compl_referentiel) trop_paye
FROM
formule_resultat_service_ref frs
JOIN formule_resultat fr ON fr.id = frs.formule_resultat_id
JOIN type_volume_horaire tvh ON tvh.id = fr.type_volume_horaire_id AND tvh.code = 'REALISE'
JOIN etat_volume_horaire evh ON evh.id = fr.etat_volume_horaire_id AND evh.code = 'valide'
JOIN intervenant i ON i.id = fr.intervenant_id
LEFT JOIN mise_en_paiement mep ON mep.formule_res_service_ref_id = frs.id AND 1 = ose_divers.comprise_entre( mep.histo_creation, mep.histo_destruction )
GROUP BY
frs.service_referentiel_id, i.id, i.prenom, i.nom_usuel, i.source_code, i.annee_id
HAVING
ABS(SUM(mep.heures) - AVG(frs.heures_compl_referentiel)) > 0.01
) t1
GROUP BY
annee, i_nom, i_code
HAVING
sum(trop_paye) > 0;
SELECT
mep.id || ',' /*
mep.id mep_id,
i.id i_id, i.prenom || ' ' || i.nom_usuel intervenant,
s.id s_id, s.libelle_court structure,
p.id p_id, p.libelle_court periode_paiement,
cc.id cc_id, cc.source_code centre_cout,
th.id th_id, th.libelle_court type_heures,
ep.source_code,
mep.heures,
mep.DATE_MISE_EN_PAIEMENT,
to_char(mep.histo_creation, 'DD/MM/YYYY HH:MI:SS') mep_histo_creation,
mep.histo_createur_id,
mep.histo_modification,
mep.histo_destructeur_id*/
FROM
v_mep_intervenant_structure mis
JOIN mise_en_paiement mep ON mep.id = mis.mise_en_paiement_id
LEFT JOIN periode p on p.id = mep.periode_paiement_id
JOIN centre_cout cc ON cc.id = mep.centre_cout_id
JOIN type_heures th ON th.id = mep.type_heures_id
JOIN intervenant i on i.id = mis.intervenant_id
JOIN structure s on s.id = mis.structure_id
LEFT JOIN FORMULE_RESULTAT_SERVICE frs ON frs.id = MEP.FORMULE_RES_SERVICE_ID
LEFT JOIN service s ON s.id = frs.service_id
LEFT JOIN element_pedagogique ep ON ep.id = s.element_pedagogique_id
WHERE
--1 = ose_divers.comprise_entre( mep.histo_creation, mep.histo_destruction )
--AND i.source_code = '21472'
--AND mep.histo_modificateur_id=2504
i.id IN (
6167,
4834,
4978,
5404,
4968,
6184,
5747,
6322
)
-- AND s.id = 372
-- AND to_char(mep.histo_modification,'YYYY-MM-DD') = to_char(SYSDATE,'YYYY-MM-DD')
;
select * from tbl_paiement where intervenant_id = 7222;
delete from mise_en_paiement where id in (
);
--update mise_en_paiement set heures = 1.38 WHERE id = 446;
update mise_en_paiement set histo_destruction = sysdate, histo_destructeur_id = 4 where id IN (
29190,
29191,
29192,
29193,
29194,
29195,
29196,
29197,
29198,
29199,
29312,
29313,
29314,
29315,
29316,
29317,
29318,
29319,
29320,
29321,
29322,
29323,
29473,
29474,
29475,
29666,
29667,
31596,
31982,
31983,
31984,
31985,
31986,
31987,
31988,
31989,
31990,
31991,
31992,
31993,
31994,
31995,
31996,
31997,
31998,
31999,
32000,
32001,
32002,
32003,
32004,
32005,
33581,
33582,
33583,
33584,
33585,
33586,
33587,
33588,
33589,
33590,
33591,
33592,
33593,
33594,
33595,
33596,
33597,
33598,
33599,
33600,
33601,
33602,
33603,
33604,
33605,
33606,
33607,
33608,
33609,
33610,
33611,
34084,
34365,
34366,
34367,
34368,
34369,
34370,
34371,
34372,
34373,
34374,
34375,
34376,
34377,
34378,
34379,
34380,
34381,
34382,
34383,
34384,
34385,
34386,
34387,
34388,
34389,
34390,
34391,
34392,
34393,
34394,
34395,
34396,
34397,
34398,
34399,
34400,
34401,
34402,
34403,
34404,
34405,
34406,
34407,
34408,
34409,
34410,
34717,
34718,
34719,
34720,
34721,
34722,
34723,
34724,
34725,
34726,
34727,
34728,
34729,
34730,
34731,
34732,
34733,
34734,
34735,
34736,
34737,
34738,
34739,
34865,
34866,
34890,
35156,
35157,
35158,
35159,
35160,
35161,
35162,
35163,
35164,
35165,
35166,
35167,
35168,
35169,
35170,
35171,
35172,
35173,
35174,
35175,
35176,
35177,
35178,
35179,
35180,
35181,
35182,
35183,
35184,
35185,
35186,
35187,
35188,
35189,
35190,
35191,
35192,
35193,
35194,
35195,
35196,
35197,
35198,
35199,
35200,
35201,
35202,
35203,
35204,
35205,
35206,
35207,
35208,
35209,
35210,
38415,
38903,
38904,
38905,
43433,
43434,
43435,
43436,
43437,
43438,
43439,
43440,
43441,
43442,
43443,
43444,
43445,
43446,
43447,
43448,
43449,
43450,
43451,
43452,
43496
);
update mise_en_paiement set periode_paiement_id = 5, date_mise_en_paiement = to_date( '29/02/2016', 'DD/MM/YYYY') WHERE
id in (
24800,
24801,
24825,
24826,
24828,
24858,
24859,
24985,
24829,
24830,
24495,
24831
);
SELECT
*
FROM
(
WITH sp AS (
SELECT
mep.formule_res_service_id,
SUM( CASE WHEN th.code = 'fi' THEN mep.heures ELSE 0 END ) payees_fi,
SUM( CASE WHEN th.code = 'fa' THEN mep.heures ELSE 0 END ) payees_fa,
SUM( CASE WHEN th.code IN ('fc','fc_majorees') THEN mep.heures ELSE 0 END ) payees_fc
FROM
mise_en_paiement mep
JOIN type_heures th on th.id = mep.type_heures_id
WHERE
1 = ose_divers.comprise_entre(mep.histo_creation,mep.histo_destruction)
GROUP BY
mep.formule_res_service_id
)
SELECT
i.nom_usuel || i.prenom i_nom,
i.source_code i_code,
ep.source_code elmt,
frs.heures_compl_fi, payees_fi,
frs.heures_compl_fa, payees_fa,
frs.heures_compl_fc, payees_fc
FROM
formule_resultat_service frs
JOIN formule_resultat fr on fr.id = frs.formule_resultat_id
JOIN sp ON sp.formule_res_service_id = frs.id
JOIN intervenant i ON i.id = fr.intervenant_id
JOIN service s on s.id = frs.service_id
LEFT JOIN element_pedagogique ep ON ep.id = s.element_pedagogique_id
WHERE
frs.heures_compl_fi < sp.payees_fi
OR frs.heures_compl_fa < sp.payees_fa
OR frs.heures_compl_fc < sp.payees_fc
ORDER BY
i_nom, elmt
) t1
SELECT
id--, source_code, nom_usuel, prenom
FROM
(
select
i.id, i.source_code, i.nom_usuel, i.prenom, case when v.id is null then 1 else 0 end non_valid, case when mep.id is null then 0 else 1 end nb_mep
from
intervenant i
JOIN type_intervenant ti ON ti.id = i.type_id
JOIN service s ON s.intervenant_id = i.id AND 1 = ose_divers.comprise_entre( s.histo_creation, s.histo_destruction )
JOIN volume_horaire vh ON vh.service_id = s.id AND 1 = ose_divers.comprise_entre( vh.histo_creation, vh.histo_destruction )
JOIN type_volume_horaire tvh ON tvh.id = vh.type_volume_horaire_id
LEFT JOIN validation_vol_horaire vvh ON vvh.volume_horaire_id = vh.id
LEFT JOIN validation v ON v.id = vvh.validation_id AND 1 = ose_divers.comprise_entre( v.histo_creation, v.histo_destruction )
LEFT JOIN formule_resultat_service frs ON frs.service_id = s.id
LEFT JOIN mise_en_paiement mep ON mep.formule_res_service_id = frs.id AND 1 = ose_divers.comprise_entre( mep.histo_creation, mep.histo_destruction )
WHERE
tvh.code = 'REALISE'
AND ti.code = 'P'
--AND i.source_code = 732
UNION
select
i.id, i.source_code, i.nom_usuel, i.prenom, case when v.id is null then 1 else 0 end non_valid, case when mep.id is null then 0 else 1 end nb_mep
from
intervenant i
JOIN type_intervenant ti ON ti.id = i.type_id
JOIN service_referentiel s ON s.intervenant_id = i.id AND 1 = ose_divers.comprise_entre( s.histo_creation, s.histo_destruction )
JOIN volume_horaire_ref vh ON vh.service_referentiel_id = s.id AND 1 = ose_divers.comprise_entre( vh.histo_creation, vh.histo_destruction )
JOIN type_volume_horaire tvh ON tvh.id = vh.type_volume_horaire_id
LEFT JOIN validation_vol_horaire_ref vvh ON vvh.volume_horaire_ref_id = vh.id
LEFT JOIN validation v ON v.id = vvh.validation_id AND 1 = ose_divers.comprise_entre( v.histo_creation, v.histo_destruction )
LEFT JOIN formule_resultat_service_ref frs ON frs.service_referentiel_id = s.id
LEFT JOIN mise_en_paiement mep ON mep.formule_res_service_ref_id = frs.id AND 1 = ose_divers.comprise_entre( mep.histo_creation, mep.histo_destruction )
WHERE
tvh.code = 'REALISE'
AND ti.code = 'P'
--AND i.source_code = 732
) t1
GROUP BY
id, source_code, nom_usuel, prenom
HAVING
sum(non_valid) > 0 AND sum(nb_mep) > 0
order by
nom_usuel
;
select
'DELETE FROM mise_en_paiement WHERE id = ' || mep.id || ';'
--, mep.id, fr.intervenant_id
FROM
mise_en_paiement mep
LEFT JOIN formule_resultat_service_ref frsr ON frsr.id = mep.FORMULE_RES_SERVICE_REF_ID
LEFT JOIN formule_resultat_service frs ON frs.id = mep.FORMULE_RES_SERVICE_ID
LEFT JOIN formule_resultat fr ON fr.id = NVL( frs.formule_resultat_id, frsr.formule_resultat_id )
WHERE
fr.intervenant_id IN (
2004,1788,308,794,34,2134,2020,1623,1010,27,1328,1620,84,106,702,783,115,1900,309,111,442,1705,4,
314,338,600,1348,380,758,24,1041,68 );
select *from intervenant where source_code='36886';
select
i.source_code, i.nom_usuel, i.prenom, sum(case when v.id is null then 1 else 0 end) non_valid, sum(case when mep.id is null then 0 else 1 end) nb_mep
from
intervenant i
JOIN type_intervenant ti ON ti.id = i.type_id
JOIN service s ON s.intervenant_id = i.id AND 1 = ose_divers.comprise_entre( s.histo_creation, s.histo_destruction )
JOIN volume_horaire vh ON vh.service_id = s.id AND 1 = ose_divers.comprise_entre( vh.histo_creation, vh.histo_destruction )
JOIN type_volume_horaire tvh ON tvh.id = vh.type_volume_horaire_id
LEFT JOIN validation_vol_horaire vvh ON vvh.volume_horaire_id = vh.id
LEFT JOIN validation v ON v.id = vvh.validation_id AND 1 = ose_divers.comprise_entre( v.histo_creation, v.histo_destruction )
LEFT JOIN formule_resultat_service frs ON frs.service_id = s.id
LEFT JOIN mise_en_paiement mep ON mep.formule_res_service_id = frs.id AND 1 = ose_divers.comprise_entre( mep.histo_creation, mep.histo_destruction )
WHERE
tvh.code = 'REALISE'
AND ti.code = 'P'
AND i.source_code = 732
GROUP BY
i.source_code, i.nom_usuel, i.prenom;
select mep.*
from
intervenant i
JOIN type_intervenant ti ON ti.id = i.type_id
JOIN service s ON s.intervenant_id = i.id AND 1 = ose_divers.comprise_entre( s.histo_creation, s.histo_destruction )
JOIN volume_horaire vh ON vh.service_id = s.id AND 1 = ose_divers.comprise_entre( vh.histo_creation, vh.histo_destruction )
JOIN type_volume_horaire tvh ON tvh.id = vh.type_volume_horaire_id
LEFT JOIN validation_vol_horaire vvh ON vvh.volume_horaire_id = vh.id
LEFT JOIN validation v ON v.id = vvh.validation_id AND 1 = ose_divers.comprise_entre( v.histo_creation, v.histo_destruction )
LEFT JOIN formule_resultat_service frs ON frs.service_id = s.id
LEFT JOIN mise_en_paiement mep ON mep.formule_res_service_id = frs.id --AND 1 = ose_divers.comprise_entre( mep.histo_creation, mep.histo_destruction )
WHERE
tvh.code = 'REALISE'
AND ti.code = 'P'
AND i.source_code = 732
SELECT
-- Création de la séquence
'
CREATE SEQUENCE ' || SUBSTR(TABLE_NAME,0,23) || '_ID_SEQ INCREMENT BY 1 MAXVALUE 9999999999999999999999999999 MINVALUE 1 NOCACHE;
' ||
-- Création des champs
'
ALTER TABLE OSE.' || TABLE_NAME || ' ADD ( histo_creation DATE ) ;
ALTER TABLE OSE.' || TABLE_NAME || ' ADD ( histo_createur_id NUMBER (*,0) ) ;
ALTER TABLE OSE.' || TABLE_NAME || ' ADD ( histo_modification DATE ) ;
ALTER TABLE OSE.' || TABLE_NAME || ' ADD ( histo_modificateur_id NUMBER (*,0) ) ;
ALTER TABLE OSE.' || TABLE_NAME || ' ADD ( histo_destruction DATE ) ;
ALTER TABLE OSE.' || TABLE_NAME || ' ADD ( histo_destructeur_id NUMBER (*,0) ) ;
' ||
-- Affectation des valeurs si des champs ont déjà été créés
'
UPDATE OSE.' || TABLE_NAME || ' SET VALIDITE_DEBUT = SYSDATE WHERE VALIDITE_DEBUT IS NULL;
UPDATE OSE.' || TABLE_NAME || ' SET HISTO_CREATION = SYSDATE WHERE HISTO_CREATION IS NULL;
UPDATE OSE.' || TABLE_NAME || ' SET HISTO_CREATEUR_ID = 1 WHERE HISTO_CREATEUR_ID IS NULL;
UPDATE OSE.' || TABLE_NAME || ' SET HISTO_MODIFICATION = SYSDATE WHERE HISTO_MODIFICATION IS NULL;
UPDATE OSE.' || TABLE_NAME || ' SET HISTO_MODIFICATEUR_ID = 1 WHERE HISTO_MODIFICATEUR_ID IS NULL;
' ||
-- Application des contraintes NOT NULL
'
ALTER TABLE OSE.' || TABLE_NAME || ' MODIFY (HISTO_CREATION NOT NULL);
ALTER TABLE OSE.' || TABLE_NAME || ' MODIFY (HISTO_CREATEUR_ID NOT NULL);
ALTER TABLE OSE.' || TABLE_NAME || ' MODIFY (HISTO_MODIFICATION NOT NULL);
ALTER TABLE OSE.' || TABLE_NAME || ' MODIFY (HISTO_MODIFICATEUR_ID NOT NULL);
' ||
-- Création des valeurs par défaut
'
ALTER TABLE OSE.' || TABLE_NAME || ' MODIFY(HISTO_CREATION DEFAULT SYSDATE);
ALTER TABLE OSE.' || TABLE_NAME || ' MODIFY(HISTO_MODIFICATION DEFAULT SYSDATE);
' ||
-- Création des clés étrangères
'
ALTER TABLE OSE.' || TABLE_NAME || ' ADD CONSTRAINT ' || SUBSTR(TABLE_NAME,0,25) || '_HCFK FOREIGN KEY (HISTO_CREATEUR_ID) REFERENCES OSE.UTILISATEUR(ID);
ALTER TABLE OSE.' || TABLE_NAME || ' ADD CONSTRAINT ' || SUBSTR(TABLE_NAME,0,25) || '_HMFK FOREIGN KEY (HISTO_MODIFICATEUR_ID) REFERENCES OSE.UTILISATEUR(ID);
ALTER TABLE OSE.' || TABLE_NAME || ' ADD CONSTRAINT ' || SUBSTR(TABLE_NAME,0,25) || '_HDFK FOREIGN KEY (HISTO_DESTRUCTEUR_ID) REFERENCES OSE.UTILISATEUR(ID);
'
FROM
USER_TABLES
WHERE
TABLE_NAME IN (SELECT TABLE_NAME FROM USER_TAB_COLS WHERE COLUMN_NAME = 'HISTO_CREATION')
ORDER BY
TABLE_NAME;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment