Advertisement
hamacker

Função em FirebirdSQL para converter BLOB/HTML em Texto Puro

Jan 2nd, 2020
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 1.09 KB | None | 0 0
  1. CREATE OR ALTER FUNCTION STR_UNHTML (
  2.     P_SOURCE_HTML blob sub_type 1 segment size 80)
  3. returns blob sub_type 1 segment size 80
  4. AS
  5. DECLARE variable TAGSTART INTEGER;
  6. DECLARE variable TAGFINISH INTEGER;
  7. DECLARE variable TAGFOUND blob sub_type text;
  8. DECLARE variable RESULT_TEXT blob sub_type text;
  9. BEGIN
  10.   -- essa procedure retorna um texto (blob) sem a porção de tags <html>, ex:
  11.   -- ret=STR_UNHTML('<html>texto<b> sem as tags</b></html>');   // resultado: texto puro sem as tags html
  12.   -- Util para tornar um texto HTML texto pesquisável.
  13.   result_text='';
  14.   p_source_html=TRIM(:p_source_html);
  15.  
  16.   tagstart = position ('<', :p_source_html);
  17.   WHILE (:tagstart > 0) DO
  18.   BEGIN
  19.     tagfinish = position ('>', :p_source_html, :tagstart);
  20.     IF (:tagfinish<:tagstart) THEN
  21.       tagfinish=char_length(:p_source_html);
  22.     tagfound = substring (:p_source_html FROM :tagstart FOR ((:tagfinish - :tagstart) + 1));
  23.     p_source_html = REPLACE (:p_source_html, :tagfound, '');
  24.     tagstart = position ('<', :p_source_html);
  25.   END
  26.   result_text = :p_source_html;
  27.  
  28.   RETURN result_text;
  29. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement