mysql儲存過程及拼接字串的用法
DROP PROCEDURE IF EXISTS insert_historytable;
DELIMITER //
CREATE PROCEDURE insert_historytable()
BEGIN
##定義判斷變數
DECLARE 1_id varchar(50);
DECLARE 1_dissolved_oxygen FLOAT;
DECLARE 1_conductivity FLOAT;
DECLARE 1_turbidity FLOAT;
DECLARE 1_ph FLOAT;
DECLARE 1_water_temperature FLOAT;
DECLARE 1_report_date TIMESTAMP;
DECLARE 1_name varchar(500);
## 定義查詢變數
DECLARE _cur CURSOR FOR
SELECT id,dissolved_oxygen,conductivity,turbidity,ph,water_temperature,report_date FROM sys_salvage_point_data1;
### 迴圈賦初始值
DECLARE CONTINUE HANDLER FOR NOT FOUND SET 1_id=NULL;
### 開啟
OPEN _cur;
## 賦值
FETCH _cur INTO 1_id,1_dissolved_oxygen,1_conductivity,1_turbidity,1_ph,1_water_temperature,1_report_date;
###迴圈判斷
WHILE (1_id is not null ) DO
SET 1_name=CONCAT('<ph>',1_ph,'<ph/>','<conductivity>',1_conductivity,'<conductivity/>');
select 1_id,1_dissolved_oxygen,1_conductivity,1_turbidity,1_ph,1_water_temperature,1_report_date,1_name;
## 賦值下一個遊標
FETCH _cur INTO 1_id,1_dissolved_oxygen,1_conductivity,1_turbidity,1_ph,1_water_temperature,1_report_date;
END WHILE;
## 關閉
CLOSE _cur;
END//
DELIMITER ;
CALL insert_historytable(); #呼叫儲存過程