欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

MySQL函数创造

程序员文章站 2023-12-29 11:27:28
...

MySQL函数创建 ? DELIMITER $$CREATE FUNCTION funGetSKUContractorId(param_sku_number VARCHAR(32)) RETURNS INT(11)BEGINDECLARE contraactor_id_temp,parent_id_temp, i INT;SET i=0;SELECT MAX(contractor_id) , MAX(parent_id) INTO contraactor_id_tem

MySQL函数创建

?

DELIMITER $$

CREATE  FUNCTION funGetSKUContractorId(param_sku_number VARCHAR(32)) RETURNS INT(11)
BEGIN
DECLARE contraactor_id_temp,parent_id_temp, i INT;
SET i=0;
SELECT MAX(contractor_id) , MAX(parent_id)  INTO contraactor_id_temp, parent_id_temp  FROM 
erp$pro$product_sku ps 
JOIN erp$pro$product p ON ps.product_id = p.product_id
JOIN erp$pro$product_category pc ON p.product_id = pc.product_id
JOIN erp$pro$category c ON pc.category_id = c.category_id
WHERE ps.sku_number = param_sku_number ;

/*
*  因为现在分类最多只有四级,所以最多循环4次
*/
WHILE (i

?

?

?

示例2

?

DELIMITER $$

/**
*  根据定单号获取发货截止日期的函数
*/
CREATE FUNCTION funGetOrderDeliverDeadline(order_id INT)  

RETURNS VARCHAR(32)

BEGIN

RETURN  (SELECT MAX(DATE_ADD(so.create_time ,INTERVAL (SELECT IFNULL(MAX(produce_period),0)   FROM erp$sal$order_sku os1
JOIN erp$pro$product_sku ps1 ON os1.product_sku_id = ps1.product_sku_id
JOIN erp$sal$order_shipment osp1 ON os1.order_shipment_id = osp1.order_shipment_id
WHERE osp1.sales_order_id = order_id) DAY)) 'deadline_deliver_time'
FROM erp$sal$sales_order so WHERE so.sales_order_id = order_id);
END$$

DELIMITER ;

?

上一篇:

下一篇: