Solved

MySQL Function Error

Posted on 2014-01-10
4
485 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
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…

690 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