0% found this document useful (0 votes)
7 views2 pages

Script Table

The document contains SQL commands for creating a table named ETUDIANT with various attributes and constraints, including a primary key. It also includes the definition of a function, NB_ANNE_2000, that calculates the number of years since 2000 based on a given date of birth. There are two versions of the function, with the second version using a different method to compute the years.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Script Table

The document contains SQL commands for creating a table named ETUDIANT with various attributes and constraints, including a primary key. It also includes the definition of a function, NB_ANNE_2000, that calculates the number of years since 2000 based on a given date of birth. There are two versions of the function, with the second version using a different method to compute the years.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

CREATE TABLE ETUDIANT

(
MATRICULE NUMBER DEFAULT seq_etudiant_NEXTVAL NOT NULL
, NOM VARCHAR2(20) NOT NULL
, COLUMN1 VARCHAR2(20)
, COLUMN2 NUMBER
, COLUMN3 VARCHAR2(20)
, CONSTRAINT ETUDIANT_PK PRIMARY KEY
(
MATRICULE
)
ENABLE
);

CREATE TABLE ETUDIANT


(
MATRICULE NUMBER DEFAULT seq_etudiant_NEXTVAL NOT NULL
, NOM VARCHAR2(20) NOT NULL
, PRENOM VARCHAR2(20)
, AGE NUMBER
, ID_FILIERE VARCHAR2(20)
);

alter table "SYS"."ETUDIANT" add constraint PK_ETUDIANT primary key("MATRICULE")

CREATE OR REPLACE FUNCTION NB_ANNE_2000


(
DATE_NAISS IN NUMBER
) RETURN NUMBER AS
BEGIN
declare NB_ANNEE number;

if EXTRACT(year(DATE_NAISS)<=2000) then

NB_ANNEE = -1;

else

NB_ANNEE = DATE_NAISS - 2000;

RETURN NB_ANNEE;
END NB_ANNE_2000;

CREATE OR REPLACE FUNCTION NB_ANNE_2000


(
DATE_NAISS IN NUMBER
) RETURN NUMBER AS
BEGIN
RETURN div (months_BETWEEN(DATE_NAISS, 2000), 12);
END NB_ANNE_2000;

You might also like