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
| WITH ADRESSES_IP AS
(
SELECT '192.168.000.001' AS IP FROM DUAL UNION ALL
SELECT '192.168.000.002' FROM DUAL UNION ALL
SELECT '127.000.000.001' FROM DUAL
),
REGLES AS
(
SELECT '192.168*' AS REGLE, 'réseau local' AS NOM FROM DUAL UNION ALL
SELECT '192.168.000*' , 'réseau local / sous réseau 0' FROM DUAL UNION ALL
SELECT '192.168.000.002' , 'machine à toto' FROM DUAL UNION ALL
SELECT '192.168.000.001' , 'machine à dede' FROM DUAL UNION ALL
SELECT '127.000.000.001' , 'moi-meme' FROM DUAL
)
SELECT
AI.IP,
MAX(RG.REGLE) KEEP (DENSE_RANK FIRST ORDER BY LENGTH(RG.REGLE) DESC) AS REGLE,
MAX(RG.NOM) KEEP (DENSE_RANK FIRST ORDER BY LENGTH(RG.REGLE) DESC) AS NOM
FROM
ADRESSES_IP AI
INNER JOIN REGLES RG
ON AI.IP LIKE REPLACE(RG.REGLE, '*', '%')
GROUP BY
AI.IP;
IP REGLE NOM
--------------- --------------- ---------------
127.000.000.001 127.000.000.001 moi-meme
192.168.000.001 192.168.000.001 machine à dede
192.168.000.002 192.168.000.002 machine à toto |
Partager