[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MySQL Function Error

Posted on 2014-01-10
4
Medium Priority
?
490 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 143

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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What we learned in Webroot's webinar on multi-vector protection.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

864 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