{"id":2913,"date":"2018-07-07T17:16:02","date_gmt":"2018-07-08T00:16:02","guid":{"rendered":"https:\/\/database.guide\/?p=2913"},"modified":"2019-11-19T22:58:10","modified_gmt":"2019-11-20T05:58:10","slug":"ord-examples-mysql","status":"publish","type":"post","link":"https:\/\/database.guide\/ord-examples-mysql\/","title":{"rendered":"ORD() Examples &#8211; MySQL"},"content":{"rendered":"<p>In <a href=\"https:\/\/database.guide\/what-is-mysql\/\">MySQL<\/a>, the <code>ORD()<\/code> function returns the numeric value of the leftmost character of a given string. You provide the string as an argument.<\/p>\n<p>If the leftmost character is a multibyte character, the returned value is calculated from the numeric values of its constituent bytes. If the leftmost character is not a multibyte character, the return value is its ASCII code (which is the same result as when using the <a href=\"https:\/\/database.guide\/ascii-examples-mysql\/\"><code>ASCII()<\/code><\/a> function).<\/p>\n<p><!--more--><\/p>\n<h2>Syntax<\/h2>\n<p>The syntax goes like this:<\/p>\n<pre>ORD(str)\r\n<\/pre>\n<p>Where <code>str<\/code> is the string from which you want the numeric code of the leftmost character.<\/p>\n<h2>Example 1 &#8211; Basic Usage<\/h2>\n<p>Here&#8217;s an example to demonstrate.<\/p>\n<pre>SELECT ORD('MySQL');\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+----------------+\r\n| ASCII('MySQL') |\r\n+----------------+\r\n|             77 |\r\n+----------------+\r\n<\/pre>\n<p>So we can see that the numeric for the letter <em>M<\/em> is <em>77<\/em>. This is exactly the same result we&#8217;d get if using the <code>ASCII()<\/code> function, because the letter <em>M<\/em> falls within the ASCII range.<\/p>\n<p>Here&#8217;s an example with the two functions side by side:<\/p>\n<pre>SELECT \r\n  ASCII('M'),\r\n  ORD('M');\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+------------+----------+\r\n| ASCII('M') | ORD('M') |\r\n+------------+----------+\r\n|         77 |       77 |\r\n+------------+----------+\r\n<\/pre>\n<h2>Example 2 &#8211; Multibyte Characters<\/h2>\n<p>Here&#8217;s an example that uses multibyte characters.<\/p>\n<pre>SELECT \r\n  ORD('\u20ac'),\r\n  ORD('\u00e1'),\r\n  ORD('\u4eee'),\r\n  ORD('\u5e73'),\r\n  ORD('\u2713');\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+------------+-----------+------------+------------+------------+\r\n| ORD('\u20ac')   | ORD('\u00e1')  | ORD('\u4eee')  | ORD('\u5e73')  | ORD('\u2713')   |\r\n+------------+-----------+------------+------------+------------+\r\n|   14844588 |     50081 |   14990254 |   15055283 |   14851219 |\r\n+------------+-----------+------------+------------+------------+\r\n<\/pre>\n<h2>Example 2 &#8211; Case Sensitivity<\/h2>\n<p>Uppercase characters have a different numeric value to their lowercase counterparts. Example:<\/p>\n<pre>SELECT \r\n  ORD('A'),\r\n  ORD('a');\r\n<\/pre>\n<p>Result:<\/p>\n<pre>+----------+----------+\r\n| ORD('A') | ORD('a') |\r\n+----------+----------+\r\n|       65 |       97 |\r\n+----------+----------+\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In MySQL, the ORD() function returns the numeric value of the leftmost character of a given string. You provide the string as an argument. If the leftmost character is a multibyte character, the returned value is calculated from the numeric values of its constituent bytes. If the leftmost character is not a multibyte character, the &#8230; <a title=\"ORD() Examples &#8211; MySQL\" class=\"read-more\" href=\"https:\/\/database.guide\/ord-examples-mysql\/\" aria-label=\"Read more about ORD() Examples &#8211; MySQL\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[93,67],"class_list":["post-2913","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-functions","tag-string-functions"],"_links":{"self":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/2913","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/comments?post=2913"}],"version-history":[{"count":4,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/2913\/revisions"}],"predecessor-version":[{"id":2917,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/posts\/2913\/revisions\/2917"}],"wp:attachment":[{"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/media?parent=2913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/categories?post=2913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/database.guide\/wp-json\/wp\/v2\/tags?post=2913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}