mysql 存储过程,游标参数

wwwsoftwares 2010-04-27 11:09:15
create procedure proc_cms(beginindex int,rowsize int)/*传输当前索引和插入条数*/

begin
declare done int default 0;
declare seq int default 0;
declare flag int default 0;
declare seqtitle varchar(2000) default '';
declare cms_size int default 0;/*总记录条数*/
declare sqlsa varchar(2000) default '';
declare cur1 cursor for select t1.seq_id,t1.seg_title from cms_db.tbl_catalog_segment t1 limit beginindex,rowsize;
declare continue handler for SQLSTATE '02000' set done = 1;/*定义错误*/
set @limit_str = concat(' limit ',beginindex,',',rowsize);

select count(*) into cms_size from cms_db.tbl_catalog_segment; /*查询表的总记录*/
open cur1;/*开游标*/
fetch cur1 into seq,seqtitle;
/*循环体*/
while (flag!=100) DO
set flag = flag+1;
insert into nufrontsoft.tbl_temp set nufrontsoft.tbl_temp.seq = seq,nufrontsoft.tbl_temp.seqtitle=seqtitle;
fetch cur1 into seq,seqtitle;
end while;
close cur1;
/*select flag , cms_size; */
end;

我limit加上参数就报语法错误 我也试过其他的方式都不行 希望高手指点下啊
...全文
324 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
llpyemao 2010-12-11
  • 打赏
  • 举报
回复
mysql就是个垃圾数据库系统,写存储过程极端不方便
wwwsoftwares 2010-04-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wwwwb 的回复:]
动态执行
set @sql=concat('create table tt as select t1.seq_id,t1.seg_title from cms_db.tbl_catalog_segment t1 limit ',beginindex,',',rowsize);
prepare asql from @sql;
execute asql;
declare cur1 cursor……
[/Quote]
declare cur1 和 tt代表的是什么啊
wwwwb 2010-04-28
  • 打赏
  • 举报
回复
动态执行
set @sql=concat('create table tt as select t1.seq_id,t1.seg_title from cms_db.tbl_catalog_segment t1 limit ',beginindex,',',rowsize);
prepare asql from @sql;
execute asql;
declare cur1 cursor for select * from tt;
....
wwwsoftwares 2010-04-28
  • 打赏
  • 举报
回复
多谢 , 这样可以用其他方式替代吗
ACMAIN_CHM 2010-04-27
  • 打赏
  • 举报
回复
limit 后不能使用变量,只能使用常数。

56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧