MySQL存储过程 - 输出值的问题

时间:2010-11-18 12:41:17

标签: mysql stored-procedures

我试图运行以下存储过程,但它没有给出任何输出.. 如果我在不使用OUT参数的情况下选择输出值,它可以正常工作..

SELECT PWORD,REPLYATTR; - 这很好用

但“正确”做到这一点并不是出于某种原因,任何想法的人?

DROP PROCEDURE `uuu`//

CREATE DEFINER=`auth_tracker`@`%` PROCEDURE `uuu`( IN USERNAME varchar(100), 
                                                   OUT REPLYATTR varchar(100),
                                                   OUT PWORD varchar(100) )

BEGIN

DECLARE USER_PROD_ID INTEGER; 
DECLARE ATTR VARCHAR(100); 
DECLARE VAL VARCHAR(100); 
DECLARE no_more_rows BOOLEAN; -- Loop exit condition; set by NOT FOUND handler

DECLARE PoolHint VARCHAR(100) DEFAULT NULL;
DECLARE FramedIP VARCHAR(100) DEFAULT NULL; 
DECLARE FramedRoute VARCHAR(100) DEFAULT NULL;  

-- DECLARE PWORD VARCHAR(100) DEFAULT NULL;
-- DECLARE REPLYATTR VARCHAR(100);


DECLARE cur1 CURSOR 
    FOR 
 SELECT attribute_name, value
   FROM user_product_attribute upa, product_attribute pa
  WHERE upa.product_attribute_id = pa.product_attribute_id
    AND upa.user_product_id = USER_PROD_ID;

-- Declare handler to set loop exit condition
DECLARE CONTINUE HANDLER FOR NOT FOUND SET no_more_rows = TRUE;

-- Main logic 
SELECT upa.user_product_id
  INTO USER_PROD_ID
  FROM user_product_attribute upa, 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      = USERNAME

 LIMIT 1;

  -- Open the cursor
  OPEN cur1;

  -- Start Looping
  the_loop: LOOP

  -- Get Attrib + value
  FETCH cur1
    INTO ATTR, VAL;

  -- Exit if no rows
  IF no_more_rows THEN
    CLOSE cur1;
    LEAVE the_loop;
  END IF;

  -- Grab certain vars
  IF ATTR = 'poolhint' THEN SET PoolHint := VAL; END IF;
  IF ATTR = 'Framed-IP-Address' THEN SET FramedIP := VAL; END IF;
  IF ATTR = 'Framed-Route' THEN SET FramedRoute := VAL; END IF;
  IF ATTR = 'password' THEN SET PWORD := VAL; END IF;

  -- End Loop    
  END LOOP the_loop;

-- Concat 
IF (FramedIP IS NOT NULL) THEN SET REPLYATTR := CONCAT('Framed-IP-Address=',FramedIP);
ELSEIF (PoolHint IS NOT NULL) THEN SET REPLYATTR := CONCAT('PoolHint=',PoolHint);  
END IF;

-- Add Route
IF (FramedIP IS NOT NULL AND FramedRoute IS NOT NULL) 
THEN SET REPLYATTR := CONCAT(REPLYATTR,',Framed-Route="',FramedRoute,'"');
END IF;

END//

1 个答案:

答案 0 :(得分:1)

你是怎么称呼这个程序的?

如果在调用proc时传递用户定义的变量,那么你应该得到你想要的输出。

示例:

CALL uuu('bobby',@replyattr,@pname);
SELECT @replyattr,@pname;