generated from DevLab-umontp/template-DiscordBot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreateTables.plsql
49 lines (45 loc) · 892 Bytes
/
CreateTables.plsql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
DROP TABLE Pseudos;
CREATE TABLE Affection (
idUser NUMBER,
idGuild NUMBER,
indexPseudo NUMBER(3),
CONSTRAINT pk_Affection PRIMARY KEY (idUser, idGuild)
);
CREATE TABLE Pseudos(
indexPseudo NUMBER(3),
CONSTRAINT pk_Pseudos PRIMARY KEY (indexPseudo)
);
CREATE OR REPLACE PROCEDURE init_pseudos(MaxPseudo_p INT) IS
MaxPseudo INT := MaxPseudo_p;
BEGIN
WHILE MaxPseudo >= 0
LOOP
INSERT INTO Pseudos
(
indexPseudo
)
VALUES
(
MaxPseudo
);
MaxPseudo := MaxPseudo - 1;
END LOOP;
END;
CREATE OR REPLACE FUNCTION recupere_pseudo_non_utilise (
idGuild_p INT) RETURN INT IS
resulta INT;
BEGIN
SELECT *
INTO resulta
FROM (
SELECT *
FROM pseudos
WHERE indexPseudo NOT IN (
SELECT indexPseudo
FROM Affection
WHERE idGuild = idGuild_p)
ORDER BY DBMS_RANDOM.RANDOM)
WHERE rownum = 1;
RETURN resulta;
END recupere_pseudo_non_utilise;
/