Question

Mssql have a function parseURL.
But we have moved our database from mssql to mysql.

Mysql doesnot have parse url, Now we need to create parseURL function manually.

How to create parse url function in mysql?

this is mssql function

`

SET QUOTED_IDENTIFIER ON  
SET ANSI_NULLS ON  
GO  
CREATE      FUNCTION [dbo].[parseURL]  (@strURL varchar(1000))  
RETURNS varchar(1000)  
AS  
BEGIN  
IF CHARINDEX('http://',@strURL) > 0 OR CHARINDEX('https://',@strURL) > 0  
-- Ghetto-tastic  
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))  

-- Optional: Remove subdomains but differentiate between www.google.com and www.google.com.au  
IF (LEN(@strURL)LEN(REPLACE(@strURL,'.','')))/LEN('.') < 3 - if there are less than 3 periods  
SELECT @strURL = PARSENAME(@strURL,2) + '.' + PARSENAME(@strURL,1)  
ELSE -- It's likely a google.co.uk, or google.com.au  
SELECT @strURL = PARSENAME(@strURL,3) + '.' + PARSENAME(@strURL,2) + '.' + PARSENAME(@strURL,1)  
RETURN @strURL  
END  
GO  

`

Was it helpful?

Solution

SQL Server doesn't have a function called parseURL either. Wherever you're calling this function, run:

EXEC sp_helptext 'parseURL';

If you show us the definition of the function, we can help you translate it and create an equivalent function for MySQL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top