Je suis en train d'utiliser this script (qui extrait le domaine d'une URL):Essayer d'utiliser une fonction SQL dans MySQL
CREATE FUNCTION [dbo].[parseURL] (@strURL varchar(1000))
RETURNS varchar(1000)
AS
BEGIN
IF CHARINDEX('http://',@strURL) > 0 OR CHARINDEX('https://',@strURL) > 0
SELECT @strURL = REPLACE(@strURL,'https://','')
SELECT @strURL = REPLACE(@strURL,'http://','')
SELECT @strURL = REPLACE(@strURL,'www','')
-- Remove everything after "/" if one exists
IF CHARINDEX('/',@strURL) > 0 (SELECT @strURL = LEFT(@strURL,CHARINDEX('/',@strURL)-1))
RETURN @strURL
END
Cette commande SQL:
SELECT COUNT(*) as theCount, dbo.parseURL(url) as url FROM hit
WHERE url IS NOT NULL
GROUP BY dbo.parsedomain(url)
ORDER BY thecount DESC
Mais je m reçoit cette erreur:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[dbo].[parseURL] (@strURL varchar(1000)) RETURNS varchar(1000) AS BEGIN IF ' at line 1
Je suis relativement nouveau à la fois SQL et MySQL, donc pas sûr si l'erreur est SQL général ou My SQL-spécifique. Qu'est-ce que je rate?
La fonction est pour SQL Server, en utilisant TSQL - il ne fonctionnera jamais comme-est sur MySQL. –
Intéressant. Que recommanderiez-vous d'utiliser MySQL, alors? – Dan
Yup. Travailler sur une version MySQL ... Maintenant. – quantumSoup