<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>水草树 &#187; CONCAT</title>
	<atom:link href="http://mifunny.info/tag/concat/feed" rel="self" type="application/rss+xml" />
	<link>http://mifunny.info</link>
	<description>走走停停看看，恍然大悟。</description>
	<lastBuildDate>Sat, 27 Aug 2011 18:25:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>存储过程中的分页（使用limit+concat） &#8211; MySQL邯郸学步</title>
		<link>http://mifunny.info/mysql-limit-page-with-concat-278.html</link>
		<comments>http://mifunny.info/mysql-limit-page-with-concat-278.html#comments</comments>
		<pubDate>Mon, 24 Aug 2009 13:54:25 +0000</pubDate>
		<dc:creator>LD</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[CONCAT]]></category>
		<category><![CDATA[limit]]></category>
		<category><![CDATA[分页]]></category>
		<category><![CDATA[存储过程]]></category>

		<guid isPermaLink="false">http://mifunny.info/mysql-limit-page-with-concat-278.html</guid>
		<description><![CDATA[MySQL存储过程不能直接使用limit加上变量的形式， 因为MySQL会把变量当成字段名。怎么办？ 有条弯路可走，使用CONCAT 方法把字符串连接在一起， 然后 EXECUTE， 得到结果集。 DELIMITER $$ DROP PROCEDURE IF EXISTS `test_p1`$$ CREATE PROCEDURE `test_p1`(IN param INT) BEGIN /* 获得10条记录 */ SET @sql = CONCAT('SELECT * FROM table_a LIMIT ', param, ' 10 ' ); PREPARE sqlstmt FROM @sql; EXECUTE sqlstmt; DEALLOCATE PREPARE sqlstmt; END$$ DELIMITER ; 其实可以再加上一些判断，使得同一个存储过程在不同参数下查询不同的表，或者匹配不同的条件。 这样做也方便前台的开发者理解、调用， 不用去记N多的存错过程名称，只要改个参数即可。 dp.SyntaxHighlighter.ClipboardSwf = 'http://mifunny.info/site/google-syntax-highlighter/Scripts/clipboard.swf'; [...]]]></description>
			<content:encoded><![CDATA[<p style="text-indent: 2em;">MySQL存储过程不能直接使用limit加上变量的形式， 因为MySQL会把变量当成字段名。怎么办？ 有条弯路可走，使用CONCAT 方法把字符串连接在一起， 然后 EXECUTE， 得到结果集。</p>
<p><span id="more-278"></span></p>
<link rel="stylesheet" href="http://mifunny.info/site/google-syntax-highlighter/Styles/SyntaxHighlighter.css" type="text/css" media="screen" />
<pre name="code" class="sql">
DELIMITER $$
DROP PROCEDURE IF EXISTS `test_p1`$$

CREATE PROCEDURE `test_p1`(IN param INT)
BEGIN
		/* 获得10条记录 */
		SET @sql = CONCAT('SELECT * FROM table_a  LIMIT ', param, '  10 ' );
		PREPARE sqlstmt FROM @sql;
		EXECUTE sqlstmt;
		DEALLOCATE PREPARE sqlstmt;

    END$$
DELIMITER ;
</pre>
<p style="text-indent: 2em;">其实可以再加上一些判断，使得同一个存储过程在不同参数下查询不同的表，或者匹配不同的条件。 这样做也方便前台的开发者理解、调用， 不用去记N多的存错过程名称，只要改个参数即可。 </p>
<p><script type="text/javascript" src="http://mifunny.info/site/google-syntax-highlighter/Scripts/shCore.js"></script><br />
<script type="text/javascript" src="http://mifunny.info/site/google-syntax-highlighter/Scripts/shBrushSql.js"></script><br />
<script type="text/javascript">
dp.SyntaxHighlighter.ClipboardSwf = 'http://mifunny.info/site/google-syntax-highlighter/Scripts/clipboard.swf';
dp.SyntaxHighlighter.HighlightAll('code');
</script></p>
<div class="zemanta-pixie"><img class="zemanta-pixie-img" alt="" src="http://img.zemanta.com/pixy.gif?x-id=b769bacd-d505-8ed4-99a8-9b14c9dd44c8" /></div>
]]></content:encoded>
			<wfw:commentRss>http://mifunny.info/mysql-limit-page-with-concat-278.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

