Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4842773
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类: Mysql/postgreSQL

2010-05-03 11:05:54

DELIMITER $$

DROP PROCEDURE IF EXISTS `test`.`sp_test`$$

CREATE PROCEDURE `test`.`sp_test`(IN table_name varchar(255),IN total int)
BEGIN
  set @stmt = concat('select * from ',table_name,' limit ?');
  prepare s1 from @stmt;
  set @s = total;
  execute s1 using @s;
  deallocate prepare s1;
END$$

DELIMITER ;


select * from test.song limit 10;
query result(10 records)
id name datetime rank
1 woshiduide1 2007-10-03 00:27:11 9
2 woshiduide2 2007-10-03 00:27:11 9
3 woshiduide3 2007-10-03 00:27:11 4
4 woshiduide4 2007-10-03 00:27:11 6
5 woshiduide5 2007-10-03 00:27:11 7
6 woshiduide6 2007-10-03 00:27:11 5
7 woshiduide7 2007-10-03 00:27:11 3
8 woshiduide8 2007-10-03 00:27:11 9
9 woshiduide9 2007-10-03 00:27:11 6
10 woshiduide10 2007-10-03 00:27:11 4

call sp_test('test.song',10);
query result(10 records)
id name datetime rank
1 woshiduide1 2007-10-03 00:27:11 9
2 woshiduide2 2007-10-03 00:27:11 9
3 woshiduide3 2007-10-03 00:27:11 4
4 woshiduide4 2007-10-03 00:27:11 6
5 woshiduide5 2007-10-03 00:27:11 7
6 woshiduide6 2007-10-03 00:27:11 5
7 woshiduide7 2007-10-03 00:27:11 3
8 woshiduide8 2007-10-03 00:27:11 9
9 woshiduide9 2007-10-03 00:27:11 6
10 woshiduide10 2007-10-03 00:27:11 4




DELIMITER $$

DROP PROCEDURE IF EXISTS `test`.`sp_test`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_test`(IN table_name varchar(255),
 IN page_begin int,IN page_end int)
BEGIN
  set @stmt = concat('select * from ',table_name,' limit ?,?');
  prepare s1 from @stmt;
  set @s1 = page_begin;
  set @s2 = page_end;
  execute s1 using @s1,@s2;
  deallocate prepare s1;
END$$

DELIMITER ;

select * from cs_test;
call sp_test('cs_test',2,3);


结果:
query result(9 records)
id name
1 csdn1
2 colorful1
3 bbs1
4 cu1
5 cu2
6 woshiduide\n\n\n\n\n
7 woshicuode
8 I'm wrong
9 I'
m right


query result(3 records)
id name
3 bbs1
4 cu1
5 cu2


阅读(860) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-06-01 06:21:33

MBT is based on Africa's indigenous people to create innovative walking barefoot, and wear this shoe can stimulate the body to relax the muscles so that the muscles of heat to be released, consumed calories, thus to achieve weight loss results. MBT's pursuit of beauty in order to satisfy customers, design a variety of styles, such as Mbt Chapa shoe, MBT Lami Shoe