1. 程式人生 > >桃李春風一杯酒,江湖夜雨十年燈

桃李春風一杯酒,江湖夜雨十年燈

CREATE   FUNCTION `getTrackingID`(shippingInfoID BIGINT(20)) RETURNS VARCHAR(10000) CHARSET utf8
BEGIN
       DECLARE r_str VARCHAR(10000) DEFAULT ''; 
       
       DECLARE trackingID VARCHAR(100) DEFAULT ''; 
       DECLARE baseRate DECIMAL(16,2) DEFAULT 0.00; 
       DECLARE shiphurryCharge DECIMAL(16,2)DEFAULT 0.00; 
       DECLARE orderShippingDiscount DECIMAL(16,2)DEFAULT 0.00; 
       DECLARE weight DECIMAL(16,2)DEFAULT 0.00; 
       DECLARE no_more_departments SMALLINT DEFAULT 0.00; 
 
       DECLARE cur_srcs CURSOR  FOR 
   SELECT e.trackingID,e.baseRate,g.shiphurryCharge,e.orderShippingDiscount,g.weight  
   FROM  fedexlabel e
 JOIN  packagetype d ON  e.packageType_id = d.id
 JOIN  csvrecord g ON  g.trackingID = e.trackingID
WHERE d.shippingInfo_id=shippingInfoID;

DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET no_more_departments = 1;
DECLARE EXIT HANDLER FOR NOT FOUND SET no_more_departments=1; 
        SET no_more_departments=0; 
        SET r_str = '';
   
       OPEN cur_srcs;  
         FETCH cur_srcs INTO trackingID,baseRate,shiphurryCharge,orderShippingDiscount,weight;
         
         WHILE no_more_departments=0 DO
            SET r_str = CONCAT(r_str,'''',trackingID,',',baseRate,',',shiphurryCharge,',',orderShippingDiscount,',',weight) ; 
            
            FETCH cur_srcs INTO trackingID,baseRate,shiphurryCharge,orderShippingDiscount,weight;
        END WHILE;
              
       CLOSE cur_srcs;   
         
       RETURN r_str;
    END$$


DELIMITER ;