多读书,多做事,广交朋友,趣味丛生
分类: Mysql/postgreSQL
2012-08-04 18:09:45
1, 创建存储过程
DELIMITER $$
USE `test`$$
DROP procedure IF EXISTS `proc_style10_t`$$
USE `test`$$
create procedure test.proc_style10_t()
begin
DECLARE v_cmp_id INT;
DECLARE v_rpt_id INT;
DECLARE _done INT DEFAULT 0;
DECLARE cur_style10 CURSOR FOR SELECT DISTINCT cmp_id, rpt_cd FROM
csf.tmp_excel_data ted , csf.ms_report mr WHERE ted.rpt_cd = mr.rpt_index
AND mr.rpt_style_type = 10
AND mr.delete_accnt_id is null;
OPEN cur_style10;
REPEAT
FETCH cur_style10 INTO v_cmp_id, v_rpt_id;
IF NOT _done THEN
select v_cmp_id,v_rpt_id;
END IF;
UNTIL _done END REPEAT;
CLOSE cur_style10;
END;
2,调用存储过程
call test.proc_style10_t();
3,结果如下:
'495' '213'
'496' '217'