MySQL 获取农历日期函数

BEGIN
	declare temp_num 				int;
	declare chn_str 				varchar(10);
	declare num_str					varchar(20);
	declare res_day					varchar(20);
	declare i								int;
	declare j								int;

	set chn_str = '一二三四五六七八九';
	set temp_num = num + 0;
	set res_day = '';
	set i = 1;

	if temp_num > 0 and temp_num < 10 then
		set num_str = temp_num;
		set j = substring(num_str from 1 for 1);
		set res_day = concat('初',substring(chn_str from j for 1));
	end if;

	if temp_num = 10 then 
		set res_day = '初十'; 
	end if;
	
	if temp_num > 10 and temp_num < 20 then
			set num_str = temp_num;
			set j = substring(num_str from 2 for 1);
			set res_day = concat('十',substring(chn_str from j for 1));
	end if;

	if temp_num = 20 then
			set num_str = temp_num;
			set res_day = '二十';
	end if;

	if temp_num > 20 and temp_num < 30 then
			set num_str = temp_num;
			set j = substring(num_str from 2 for 1);
			set res_day = concat('二十',substring(chn_str from j for 1));
	end if;

	if temp_num = 30 then
			set num_str = temp_num;
			set res_day = '三十';
	end if;
	
	RETURN res_day;
END

你可能感兴趣的:(MySQL)