azerty3333.py

Created by joelkouakou2080

Created on March 12, 2024

1.85 KB


exo 1
DECLARE
    v_max_client_id NUMBER;
BEGIN
    -- Récupérer le client de clé primaire la plus élevée
    SELECT MAX(client_id) INTO v_max_client_id FROM clients;
    
    -- Insérer le client récupéré dans la table personnel
    INSERT INTO personnel (client_id, nom, prenom)
    SELECT client_id, nom, prenom
    FROM clients
    WHERE client_id = v_max_client_id;
    
    COMMIT; -- Valider la transaction
END;
/
-----------------------------
exo 2
DECLARE
    v_compte_id NUMBER;
BEGIN
    -- Créer un compte courant pour chaque employé
    FOR emp IN (SELECT employee_id FROM employees) LOOP
        -- Insertion du compte courant et récupération de l'identifiant
        INSERT INTO compte_courant (employee_id, solde) VALUES (emp.employee_id, 0) RETURNING compte_id INTO v_compte_id;
        
        -- Effectuer un dépôt en espèces de 300 000 FCFA sur chaque compte courant
        UPDATE compte_courant SET solde = solde + 300000 WHERE compte_id = v_compte_id;
    END LOOP;
    
    COMMIT; -- Valider la transaction
END;
/
--------------------------
exo 3
DECLARE
    v_solde_actuel NUMBER;
BEGIN
    -- Ouvrir un livret d'épargne pour chaque personne
    FOR pers IN (SELECT personnel_id FROM personnel) LOOP
        INSERT INTO compte_epargne (personnel_id, solde) VALUES (pers.personnel_id, 0);
    END LOOP;
    
    -- Faire un virement du compte courant vers le compte épargne
    FOR cc IN (SELECT * FROM compte_courant) LOOP
        SELECT solde INTO v_solde_actuel FROM compte_courant WHERE compte_id = cc.compte_id;
        IF v_solde_actuel > 100000 THEN
            UPDATE compte_courant SET solde = solde - 200000 WHERE compte_id = cc.compte_id;
            UPDATE compte_epargne SET solde = solde + 200000 WHERE personnel_id = cc.personnel_id;
        END IF;
    END LOOP;
    
    COMMIT; -- Valider la transaction
END;
/

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.