• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 492
  • Last Modified:

MySQL Function Error

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
matthewdacruz
Asked:
matthewdacruz
  • 2
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
matthewdacruzAuthor Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
matthewdacruzAuthor Commented:
Thanks that did the trick
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now