0% found this document useful (0 votes)
8 views13 pages

Intro

The document provides an overview of PL/SQL block structure, including variable declaration, data types, and basic control structures such as IF statements, CASE statements, and loops. It includes examples demonstrating the use of different data types and how to output results using DBMS_OUTPUT. The document serves as a guide for writing PL/SQL code with practical examples.

Uploaded by

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

Intro

The document provides an overview of PL/SQL block structure, including variable declaration, data types, and basic control structures such as IF statements, CASE statements, and loops. It includes examples demonstrating the use of different data types and how to output results using DBMS_OUTPUT. The document serves as a guide for writing PL/SQL code with practical examples.

Uploaded by

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

Introduction

PlSql
DECLARE
-- Déclarations des variables, constantes, curseurs,
types
BEGIN
-- Instructions exécutables
EXCEPTION
-- Gestion des erreurs/Exceptions
END;
/
Déclaration des variables
Les variables se déclarent dans la partie
DECLARE d’un bloc PL/SQL.

DECLARE
nom_variable TYPE [ := valeur_initiale ];
BEGIN
...
END;
Type Description Exemple

NUMBER(p,s) Nombre avec précision NUMBER(5,2)

VARCHAR2(n) Texte VARCHAR2(100)

DATE Date/Heure Oracle DATE := SYSDATE

vrai/faux (uniquement
BOOLEAN BOOLEAN := TRUE
PL/SQL)
DECLARE
Mydate DATE := SYSDATE;
Ecole varchar(20):='EMSI';
BEGIN
dbms_output.put_line(Ecole|| ' ' ||
TO_CHAR(Mydate,'mm-dd-yyyy'));
END;
DECLARE
N1 number(5,2) := 5.23;
N2 number(5,2) := 6;
BEGIN
dbms_output.put_line('La somme est : '|| To_char(N1+N2));
END;
DECLARE
v_nom employees.last_name%TYPE;
BEGIN
SELECT last_name INTO v_nom FROM employees WHERE
employee_id = 100;
DBMS_OUTPUT.PUT_LINE(v_nom);
END;
DECLARE
emp employees%ROWTYPE;
BEGIN
SELECT * INTO emp FROM employees WHERE employee_id = 100;
DBMS_OUTPUT.PUT_LINE(emp.first_name || ' ' || emp.last_name);
END;
DECLARE
score NUMBER := 15;
BEGIN
IF score > 10 THEN
DBMS_OUTPUT.PUT_LINE('Réussi');
END IF;
END;
DECLARE
age NUMBER := 16;
BEGIN
IF age >= 18 THEN
DBMS_OUTPUT.PUT_LINE('Majeur');
ELSE
DBMS_OUTPUT.PUT_LINE('Mineur');
END IF;
END;
/
DECLARE
jour NUMBER := 3;
BEGIN
CASE jour
WHEN 1 THEN DBMS_OUTPUT.PUT_LINE('Lundi');
WHEN 2 THEN DBMS_OUTPUT.PUT_LINE('Mardi');
WHEN 3 THEN DBMS_OUTPUT.PUT_LINE('Mercredi');
ELSE DBMS_OUTPUT.PUT_LINE('Jour inconnu');
END CASE;
END;
/
BEGIN
FOR i IN 1..5 LOOP
DBMS_OUTPUT.PUT_LINE('i = ' || i);
END LOOP;
END;
/
DECLARE
i NUMBER := 1;
BEGIN
WHILE i <= 5 LOOP
DBMS_OUTPUT.PUT_LINE('i = ' || i);
i := i + 1;
END LOOP;
END;
/

You might also like