Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2016 March MySQL: UDF to remove HTML Tag from the String Data

MySQL: UDF to remove HTML Tag from the String Data

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

In this post, I am sharing a user defined function to remove all HTML tags from the string data of MySQL Server.

There are certain requirements like, store HTML document into the text column, but unfortunately it also contains HTML tags which required to remove.

I found a user defined function for removing all HTML Tags from the given string.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
DELIMITER $$
CREATE FUNCTION fn_RemoveHTMLTag (HtmlString text) RETURNS text
BEGIN
DECLARE StartTag, EndTag INT DEFAULT 1;
LOOP
SET StartTag = LOCATE("<", HtmlString, StartTag);
IF (!StartTag) THEN
RETURN HtmlString;
END IF;
SET EndTag = LOCATE(">", HtmlString, StartTag);
IF (!EndTag) THEN
SET EndTag = StartTag;
END IF;
SET HtmlString = INSERT(HtmlString, StartTag, EndTag - StartTag + 1, "");
END LOOP;
END;

Sample Execution:

1
SELECT fn_RemoveHTMLTag(' This is a Database Research and Development ');

Mar 24, 2016Anvesh Patel
MySQL: SELECT UTC_TIMESTAMP and CONVERT local date time to UTC time zonePostgreSQL: Using json_agg() aggregate table data into a JSON formatted array
Comments: 5
  1. kamal
    April 14, 2016 at 1:14 pm

    Good write-up, I’m normal visitor of one’s website, maintain up the excellent operate, and It is going to be a regular visitor for a long time.

  2. Jim
    March 15, 2017 at 5:59 am

    Not worked on my mysql. Doesn’t remove any html tags.

    • Anvesh Patel
      Anvesh Patel
      March 16, 2017 at 6:31 pm

      Hello jim, this demo is working for me and I am using MySQL 5.7. Would you please share your error details.

    • preeti
      January 3, 2020 at 8:29 am

      On running this function I get error .LOCATE does not exist

  3. preeti
    January 3, 2020 at 8:25 am

    I created this function using mysql query browser. It is created but when it is executed the error comes that: FUCNTION .LOCATE does not exist

Anvesh Patel
Anvesh Patel

Database Engineer

March 24, 2016 MySQLAnvesh Patel, database, database research and development, dbrnd, html, MySQL, MySQL Command, MySQL Database Administrator, MySQL Database Designing, MySQL Database Programming, MySQL Error, MySQL Performance Tunning, MySQL Query, MySQL Tips and Tricks, udf
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....