Solved

MySQL Function Error

Posted on 2014-01-10
4
480 Views
Last Modified: 2014-01-13
HI Experts

Can anyone see what is wrong with this procedure.
The select query works perfect and returns me the following varchar.

bridal hair accessories,bridal hair accessories south africa,bridal hair and makeup,bridal hair clips,bridal hair pinterest,bridal hair style,bridal hair tutorial,bridal hairstyles

I want to pass two parameters and then get back the string above.

=========================================================
ERROR Im Getting:

DECLARE DNA_Sup varchar;
[Err] 1064 - 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 '' at line 4

THE Procedure Function
=========================================================

CREATE DEFINER = CURRENT_USER PROCEDURE `NewProc`(IN `_profileid` int,IN `_theme_keywordsid` int)
    DETERMINISTIC
BEGIN
      DECLARE DNA_Sup varchar;
      SELECT
                        GROUP_CONCAT(theme_leywords_imp.SupportingKeyword)
      INTO       DNA_Sup
      FROM
                        theme_leywords_imp
      WHERE
                        #theme_leywords_imp.profileid = 2995 AND
                        #theme_leywords_imp.theme_keywordsid = 1827750
                        
theme_leywords_imp.profileid = _profileid AND
                        theme_leywords_imp.theme_keywordsid = _theme_keywordsid
      LIMIT 0,1;
                                                

      RETURN DNA_Sup;

END;


=========================================================
0
Comment
Question by:matthewdacruz
  • 2
  • 2
4 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39773166
this is incomplete:
      DECLARE DNA_Sup varchar;

you have to either specify a max size:
      DECLARE DNA_Sup varchar(100);

or to use the TEXT data type:
      DECLARE DNA_Sup TEXT;


anyhow, the actual error seems to be that you are missing a AND in your WHERE clause:

WHERE
                        #theme_leywords_imp.profileid = 2995 AND
                        #theme_leywords_imp.theme_keywordsid = 1827750  AND
                       
theme_leywords_imp.profileid = _profileid AND
                        theme_leywords_imp.theme_keywordsid = _theme_keywordsid
0
 

Author Comment

by:matthewdacruz
ID: 39774342
Hi Guy, thanks for the reply

I have applied changes but still get error on line 7

=====================
CREATE DEFINER = CURRENT_USER PROCEDURE `NewProc` (
      IN `_profileid` INT,
      IN `_theme_keywordsid` INT
) DETERMINISTIC
BEGIN
      DECLARE
            DNA_Sup VARCHAR (1000);

SELECT
      GROUP_CONCAT(
            theme_leywords_imp.SupportingKeyword
      ) INTO DNA_Sup
FROM
      theme_leywords_imp
WHERE
      theme_leywords_imp.profileid = _profileid
AND theme_leywords_imp.theme_keywordsid = _theme_keywordsid
LIMIT 0,
 1;

RETURN DNA_Sup;


END;
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39774649
http://dev.mysql.com/doc/refman/5.1/de/create-procedure.html
this part
CREATE PROCEDURE `NewProc`  ( ... )
must be later in the definition:
CREATE PROCEDURE `NewProc` (
      IN `_profileid` INT,
      IN `_theme_keywordsid` INT
)
DETERMINISTIC 
SQL SECURITY INVOKER
BEGIN
      DECLARE
            DNA_Sup VARCHAR (1000);

SELECT
      GROUP_CONCAT(
            theme_leywords_imp.SupportingKeyword
      ) INTO DNA_Sup
FROM
      theme_leywords_imp
WHERE
      theme_leywords_imp.profileid = _profileid
AND theme_leywords_imp.theme_keywordsid = _theme_keywordsid
LIMIT 0,
 1;

RETURN DNA_Sup;

END; 

Open in new window

0
 

Author Closing Comment

by:matthewdacruz
ID: 39776349
Thanks that did the trick
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question