0% found this document useful (0 votes)
3 views3 pages

Prosit 1 PL SQL

The document contains PL/SQL code examples demonstrating the use of anonymous blocks, including operations such as calculating sums, generating lists, reading user input, and computing factorials. It also includes a section that interacts with the HR schema to retrieve employee names, counts, and salary statistics for a specific department. The code utilizes DBMS_OUTPUT for displaying results and requires user input for certain variables.

Uploaded by

hnachamine
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Prosit 1 PL SQL

The document contains PL/SQL code examples demonstrating the use of anonymous blocks, including operations such as calculating sums, generating lists, reading user input, and computing factorials. It also includes a section that interacts with the HR schema to retrieve employee names, counts, and salary statistics for a specific department. The code utilizes DBMS_OUTPUT for displaying results and requires user input for certain variables.

Uploaded by

hnachamine
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

PROSIT 1 PL SQL

1. Bloc Anonyme:

SET SERVEROUTPUT ON;

DECLARE
-- b
x NUMBER := 44.5;
y NUMBER := 61.8;

-- d, e, f
A NUMBER;
B NUMBER;
C NUMBER;

fact NUMBER := 1;
BEGIN
-- a. Date d’aujourd’hui
DBMS_OUTPUT.PUT_LINE('Date aujourd''hui : ' || SYSDATE);

-- b. Somme des deux réels


DBMS_OUTPUT.PUT_LINE('Somme = ' || (x + y));

-- c. Liste 1 à 10
DBMS_OUTPUT.PUT_LINE('Liste 1 à 10 :');
FOR i IN 1..10 LOOP
DBMS_OUTPUT.PUT(i || ' ');
END LOOP;
DBMS_OUTPUT.NEW_LINE;

-- Liste décroissante 100 → 0 (pas 2)


DBMS_OUTPUT.PUT_LINE('Liste 100 à 0 :');
FOR i IN REVERSE 0..50 LOOP
DBMS_OUTPUT.PUT((i*2) || ' ');
END LOOP;
DBMS_OUTPUT.NEW_LINE;
-- d. Lire A et B
A := &A;
B := &B;

DBMS_OUTPUT.PUT_LINE('Somme = ' || (A+B));


DBMS_OUTPUT.PUT_LINE('Produit = ' || (A*B));

-- e. Lire A, B, C et comparer
A := &A1;
B := &B1;
C := &C1;

IF A > B AND B > C THEN


DBMS_OUTPUT.PUT_LINE('C < B < A');
ELSIF A > C AND C > B THEN
DBMS_OUTPUT.PUT_LINE('B < C < A');
ELSIF B > A AND A > C THEN
DBMS_OUTPUT.PUT_LINE('C < A < B');
ELSE
DBMS_OUTPUT.PUT_LINE('Autre ordre');
END IF;

-- f. Factoriel
A := &N;

FOR i IN 1..A LOOP


fact := fact * i;
END LOOP;

DBMS_OUTPUT.PUT_LINE('Factoriel = ' || fact);

END;
/

2. Sous le schéma HR

SET SERVEROUTPUT ON;


DECLARE
v_nom employees.last_name%TYPE;
v_count NUMBER;
v_min NUMBER;
v_max NUMBER;
BEGIN
-- a. Nom employé id = 110
SELECT last_name INTO v_nom
FROM employees
WHERE employee_id = 110;

DBMS_OUTPUT.PUT_LINE('Nom employé : ' || v_nom);

-- b. Nombre employés département 50


SELECT COUNT(*) INTO v_count
FROM employees
WHERE department_id = 50;

DBMS_OUTPUT.PUT_LINE('Nombre employés dept 50 : ' || v_count);

-- c. Salaire min et max département 50


SELECT MIN(salary), MAX(salary)
INTO v_min, v_max
FROM employees
WHERE department_id = 50;

DBMS_OUTPUT.PUT_LINE('Salaire MIN : ' || v_min);


DBMS_OUTPUT.PUT_LINE('Salaire MAX : ' || v_max);

END;
/

You might also like