Solved

MySQL Function Error

Posted on 2014-01-10
4
477 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]
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks that did the trick
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now