<?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>jQuery, Ajax, PHP, JSON, XML, Web Technologies &#187; String</title>
	<atom:link href="http://blog.chonla.com/tag/string/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.chonla.com</link>
	<description>คุยกันเรื่อง jQuery, Ajax, PHP, JSON, XML และ Web Technologies เป็นภาษาไทยกันดีกว่า</description>
	<lastBuildDate>Tue, 17 Jan 2012 18:27:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>เปรียบเทียบ String แบบ Case Sensitive ใน MySQL</title>
		<link>http://blog.chonla.com/2010/04/%e0%b9%80%e0%b8%9b%e0%b8%a3%e0%b8%b5%e0%b8%a2%e0%b8%9a%e0%b9%80%e0%b8%97%e0%b8%b5%e0%b8%a2%e0%b8%9a-string-%e0%b9%81%e0%b8%9a%e0%b8%9a-case-sensitive-%e0%b9%83%e0%b8%99-mysql/</link>
		<comments>http://blog.chonla.com/2010/04/%e0%b9%80%e0%b8%9b%e0%b8%a3%e0%b8%b5%e0%b8%a2%e0%b8%9a%e0%b9%80%e0%b8%97%e0%b8%b5%e0%b8%a2%e0%b8%9a-string-%e0%b9%81%e0%b8%9a%e0%b8%9a-case-sensitive-%e0%b9%83%e0%b8%99-mysql/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 16:31:42 +0000</pubDate>
		<dc:creator>chonla</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Case-Sensitivity]]></category>
		<category><![CDATA[Comparison]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://blog.chonla.com/?p=285</guid>
		<description><![CDATA[โดยปกติแล้วการเปรียบเทียบข้อความ (string comparison) ใน MySQL จะเป็นการเปรียบเทียบแบบ Case-Insensitive นั่นคือ ไม่สนใจตัวเล็กตัวใหญ่ หมายถึงว่า &#8220;cat&#8221; จะเท่ากับ &#8220;CAT&#8221; นั่นเอง ปัญหานี้จะพบเมื่อเราทำการเปรียบเทียบ String ที่เป็น Text ในบางครั้ง เราจำเป็นต้องเปรียบเทียบ string แบบ Case-Sensitive เช่น การค้นหา Key ที่ case ของตัวอักษรมีความสำคัญ เราสามารถทำได้หลายวิธี แบบแรกคือ การเปรียบเทียบด้วย Binary String เช่น mysql&#62; SET @s = BINARY 'MySQL'; mysql&#62; SELECT @s = 'mysql'; +--------------+ &#124; @s = 'mysql' &#124; +--------------+ &#124; 0 [...]]]></description>
			<content:encoded><![CDATA[<p>โดยปกติแล้วการเปรียบเทียบข้อความ (string comparison) ใน MySQL จะเป็นการเปรียบเทียบแบบ Case-Insensitive นั่นคือ ไม่สนใจตัวเล็กตัวใหญ่ หมายถึงว่า &#8220;cat&#8221; จะเท่ากับ &#8220;CAT&#8221; นั่นเอง ปัญหานี้จะพบเมื่อเราทำการเปรียบเทียบ String ที่เป็น Text ในบางครั้ง เราจำเป็นต้องเปรียบเทียบ string แบบ Case-Sensitive เช่น การค้นหา Key ที่ case ของตัวอักษรมีความสำคัญ เราสามารถทำได้หลายวิธี</p>
<p><span id="more-285"></span></p>
<p>แบบแรกคือ การเปรียบเทียบด้วย Binary String เช่น</p>
<pre>mysql&gt; <strong><code>SET @s = BINARY 'MySQL';</code></strong>
mysql&gt; <strong><code>SELECT @s = 'mysql';</code></strong></pre>
<pre>+--------------+
| @s = 'mysql' |
+--------------+
|            0 |
+--------------+</pre>
<p>แบบที่สองคือ การสั่งเปลี่ยน COLLATE ให้เป็นแบบที่สนับสนุนการเปรียบเทียบแบบ case-sensitive นั่นคือ latin1_bin หรือ latin1_general_cs เช่น</p>
<pre>mysql&gt; <strong><code>SET @s1 = 'MySQL' COLLATE latin1_bin,</code></strong>
    -&gt; <strong><code>    @s2 = 'mysql' COLLATE latin1_bin;</code></strong>
mysql&gt; <strong><code>SELECT @s1 = @s2;</code></strong>
+-----------+
| @s1 = @s2 |
+-----------+
|         0 |
+-----------+</pre>
<p>แบบที่ 3 ก็เป็นการเปลี่ยน Collation เช่นเดียวกัน แต่เป็นการไปตั้งค่าที่ field ใน table ของเราเลยครับ แค่เพียงเลือก field ที่ต้องการ และเปลี่ยน collation ให้เป็น latin1_bin หรือ latin1_general_cs ก็ใช้ได้แล้วครับ</p>
<p><strong>อ้างอิง</strong></p>
<ul>
<li><a href="http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html">http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html</a></li>
</ul>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fblog.chonla.com%2F2010%2F04%2F%25e0%25b9%2580%25e0%25b8%259b%25e0%25b8%25a3%25e0%25b8%25b5%25e0%25b8%25a2%25e0%25b8%259a%25e0%25b9%2580%25e0%25b8%2597%25e0%25b8%25b5%25e0%25b8%25a2%25e0%25b8%259a-string-%25e0%25b9%2581%25e0%25b8%259a%25e0%25b8%259a-case-sensitive-%25e0%25b9%2583%25e0%25b8%2599-mysql%2F&amp;title=%E0%B9%80%E0%B8%9B%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%9A%E0%B9%80%E0%B8%97%E0%B8%B5%E0%B8%A2%E0%B8%9A%20String%20%E0%B9%81%E0%B8%9A%E0%B8%9A%20Case%20Sensitive%20%E0%B9%83%E0%B8%99%20MySQL" id="wpa2a_2"><img src="http://blog.chonla.com/wp-content/plugins/add-to-any/share_save_171_16.gif" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.chonla.com/2010/04/%e0%b9%80%e0%b8%9b%e0%b8%a3%e0%b8%b5%e0%b8%a2%e0%b8%9a%e0%b9%80%e0%b8%97%e0%b8%b5%e0%b8%a2%e0%b8%9a-string-%e0%b9%81%e0%b8%9a%e0%b8%9a-case-sensitive-%e0%b9%83%e0%b8%99-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

