开发者

MySQL stored procedure - Problem outputting values

开发者 https://www.devze.com 2023-01-25 18:54 出处:网络
DROP PROCEDURE `uuu`// CREATE DEFINER=`auth_tracker`@`%` PROCEDURE `uuu`() BEGIN DECLARE a,b CHAR(50); DECLARE _output TEXT DEFAULT \'\';
DROP PROCEDURE `uuu`//

CREATE DEFINER=`auth_tracker`@`%` PROCEDURE `uuu`()
BEGIN

DECLARE a,b CHAR(50);
DECLARE _output TEXT DEFAULT '';

DECLARE cur1 CURSOR FOR SELECT attribute_name, value
   FROM user_product_attribute upa, product_attribute pa
  WHERE upa.user_product_id IN

    (  SELECT upa.user_product_id
         FROM user_product_attribute up开发者_JAVA百科a, user_product up, product_attribute pa, product p
        WHERE pa.attribute_name = 'username'
          AND pa.product_attribute_id = upa.product_attribute_id
          AND pa.product_id = p.product_id
          AND up.status = 'active'
          AND p.product_name = 'broadband'
          AND upa.value = 'lsolway-dsl' )

    AND upa.product_attribute_id = pa.product_attribute_id;

OPEN cur1;

read_loop: LOOP
  FETCH cur1 INTO a, b;
  SET _output = CONCAT(_output,a,b);
END LOOP;

SELECT _output;

END//

Hi guys, I am trying to get the SP to set the following output.. I cant see where i am going wrong.. Nothing is being returned.. The Query itself works fine standalone..


You're not defining any output parameters as far as I can tell. That would make it very difficult to get data back from a SQL stored procedure.


DECLARE an OUT param and stuff the value into that for output.

Also one suggestion, its always good to use @ for your local variables in stored procedures. such as @_output, @a and @b.


The subquery is the reason.. I am only using one cursor for a query that would need two.. Im not even sure subqueries are possible in an SP..

0

精彩评论

暂无评论...
验证码 换一张
取 消