Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
My sql workbench code as follows

Database Mysql workbench

CREATE FUNCTION fn_parsehtml
(
p_htmldesc longtext
)
returns longtext
begin
declare v_first int; declare v_last int; declare v_len int;
set v_first = instr('<',p_htmldesc);
set v_last = instr('>',p_htmldesc,instr('<',p_htmldesc));
set v_len = (v_last - v_first) + 1;
while v_first > 0 AND v_last > 0 AND v_len > 0
do
-- -Stuff function is used to insert string at given position and delete number of characters specified from original string
set p_htmldesc = INSERT(p_htmldesc,v_first,v_len,'');
SET v_first = instr('<',p_htmldesc);
set v_last = instr('>',p_htmldesc,instr('<',p_htmldesc));
set v_len = (v_last - v_first) + 1;
end while;
return LTRIM(RTRIM(p_htmldesc));
end;

when i execute shows error as follows

Error Code: 1582. Incorrect parameter count in the call to native function 'instr'

What I have tried:

My sql workbench code as follows

Database Mysql workbench

CREATE FUNCTION fn_parsehtml
(
p_htmldesc longtext
)
returns longtext
begin
declare v_first int; declare v_last int; declare v_len int;
set v_first = instr('<',p_htmldesc);
set v_last = instr('>',p_htmldesc,instr('<',p_htmldesc));
set v_len = (v_last - v_first) + 1;
while v_first > 0 AND v_last > 0 AND v_len > 0
do
-- -Stuff function is used to insert string at given position and delete number of characters specified from original string
set p_htmldesc = INSERT(p_htmldesc,v_first,v_len,'');
SET v_first = instr('<',p_htmldesc);
set v_last = instr('>',p_htmldesc,instr('<',p_htmldesc));
set v_len = (v_last - v_first) + 1;
end while;
return LTRIM(RTRIM(p_htmldesc));
end;

when i execute shows error as follows

Error Code: 1582. Incorrect parameter count in the call to native function 'instr'
Posted
Updated 12-Dec-17 23:33pm

1 solution

The error message is quite clear:
There are more or less parameters than allowed for the function instr.

Have a look at the function documentation: MySQL :: MySQL 5.7 Reference Manual :: 12.5 String Functions[^]: instr requires two parameters.

But you are passing three here:
SQL
set v_last = instr('>',p_htmldesc,instr('<',p_htmldesc));

[EDIT]
You probably want to use
SQL
set v_first = instr(p_htmldesc, '<');
set v_last = instr(p_htmldesc, '>');
instead. Note also that the first parameter is the full string and the second the substring to be searched for. So you have to exchange the parameters compared to your code.
[/EDIT]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900