Bluehost.com Web Hosting $6.95

create function

This is a discussion on create function within the MySQL Database forums, part of the Database Forums category; I am trying to create the following function to loop through the characters of an input string. If even one ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-23-2007
drhinehart@gmail.com
 
Posts: n/a
Default create function

I am trying to create the following function to loop through the
characters of an input string. If even one of the characters is not a
'4' then return true, or else I want it to return false.

Here is the error message I keep getting:

"Script line: 2 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 'SET vindex = vindex + 1;
END WHILE

RETURN vcount;

END' at line 18"

Here is the function:

delimiter $
create function testChar (input VARCHAR(100))
RETURNS BOOLEAN
BEGIN

DECLARE inputlength INT;
DECLARE vindex INT;
DECLARE vcount BOOLEAN;

SET vcount = FALSE;
SET vindex = 1;
SET inputlength = LEN(input);

WHILE (vindex <= inputlength) DO
IF SUBSTRING(input, vindex, 1) != '4' THEN
SET vcount = TRUE;
RETURN vcount;
END IF
SET vindex = vindex + 1;
END WHILE

RETURN vcount;

END

Reply With Quote
  #2 (permalink)  
Old 04-24-2007
subtenante
 
Posts: n/a
Default Re: create function

On 23 Apr 2007 11:47:25 -0700, drhinehart@gmail.com wrote:


>
>WHILE (vindex <= inputlength) DO
> IF SUBSTRING(input, vindex, 1) != '4' THEN
> SET vcount = TRUE;
> RETURN vcount;
> END IF
> SET vindex = vindex + 1;
>END WHILE
>
>RETURN vcount;
>
>END


END IF ;
END RETURN ;

The end shall be ;-ed.
It's written in the bible.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:18 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0