我正在尝试在共享中拆分时更新所有价格列。 计算价格我写的函数,当我从命令提示符调用函数时工作正常。但是当我从内部游标调用函数来更新所有行时,它会使用null更新行;
CREATE PROCEDURE updateshareprice(in p_isin varchar(50),in p_date date)
BEGIN
DECLARE v_finished INTEGER DEFAULT 0;
DECLARE v_cisin varchar(50);
DECLARE v_nisin varchar(50);
DECLARE v_activitydate date;
DEClARE v_split varchar(20);
DEClARE v_PREV_CLOSE float(10,4);
DEClARE v_OPEN_PRICE float(10,4);
DEClARE v_HIGH_PRICE float(10,4);
DEClARE v_LOW_PRICE float(10,4);
DEClARE v_LAST_PRICE float(10,4);
DEClARE v_AVG_PRICE float(10,4);
DEClARE v_CLOSE_PRICE float(10,4);
DEClARE v_symbol varchar(20);
DEClARE v_date date;
DEClARE updateprice_cursor CURSOR FOR
select date1,isin,symbol,PREV_CLOSE,OPEN_PRICE,HIGH_PRICE,LOW_PRICE,LAST_PRICE,AVG_PRICE,CLOSE_PRICE
from nse_backup
where isin = p_isin
and date1 < p_date
order by date1 desc;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_finished = 1;
select split
INTO @v_split
from companysharehistory
where isin = p_isin
and activitydate=p_date
order by activitydate desc LIMIT 1;
OPEN updateprice_cursor;
get_info: LOOP
FETCH updateprice_cursor
INTO v_date,v_nisin,v_symbol,v_PREV_CLOSE,
v_OPEN_PRICE,v_HIGH_PRICE,v_LOW_PRICE,v_LAST_PRICE,v_AVG_PRICE,v_CLOSE_PRICE;
IF v_finished = 1 THEN
LEAVE get_info;
END IF;
update nse_backup set
PREV_CLOSE=adjustSharePriceBeforeActivity(v_PREV_CLOSE,v_split),
OPEN_PRICE=adjustSharePriceBeforeActivity(v_OPEN_PRICE,v_split),
HIGH_PRICE=adjustSharePriceBeforeActivity(v_HIGH_PRICE,v_split),
LOW_PRICE=adjustSharePriceBeforeActivity(v_LOW_PRICE,v_split),
LAST_PRICE=adjustSharePriceBeforeActivity(v_LAST_PRICE,v_split),
AVG_PRICE=adjustSharePriceBeforeActivity(v_AVG_PRICE,v_split),
CLOSE_PRICE=adjustSharePriceBeforeActivity(v_CLOSE_PRICE,v_split)
where isin = p_isin
and date1 = v_date;
END LOOP get_info;
CLOSE updateprice_cursor;
END //
DELIMITER ;
我打电话给退货价格的功能,它在命令提示符下正常工作,有人可以指导我在哪里做错了吗
DELIMITER $$
CREATE FUNCTION adjustSharePriceBeforeActivity(price float, ratio varchar(20)) RETURNS float(10,4)
DETERMINISTIC
BEGIN
declare firstratio INT unsigned;
declare secondratio int unsigned;
declare priceAfterafterchange float(10,4);
set secondratio = CAST(SUBSTRING_INDEX(ratio,':',-1) AS UNSIGNED);
set firstratio = CAST(SUBSTRING_INDEX(ratio,':',1) AS UNSIGNED) ;
set priceAfterafterchange = price/(firstratio/secondratio);
RETURN (priceAfterafterchange);
END;
$$
DELIMITER ;