DROP TABLE Cafe;
CREATE TABLE Cafe (
  Identifiant VARCHAR(20) PRIMARY KEY,
  Jetons INT NOT NULL CHECK (Jetons >= 0),
  Consommations INT NOT NULL CHECK (Consommations >= 0)
);

INSERT INTO Cafe VALUES ('Jean',10,2);
INSERT INTO Cafe VALUES ('Jacques',5,0);
COMMIT;

CREATE OR REPLACE PROCEDURE AjouteJetons(id VARCHAR2) AS
BEGIN
  UPDATE Cafe SET Jetons=Jetons+1 WHERE Identifiant=id;
END;
/

CREATE OR REPLACE FUNCTION NbConsommateursCafe RETURN INTEGER IS
  n INTEGER;
BEGIN
  SELECT COUNT(*) INTO n FROM Cafe;
  RETURN n;
END;
/
