{"id":1455,"date":"2021-09-13T14:37:15","date_gmt":"2021-09-13T06:37:15","guid":{"rendered":"https:\/\/blog.odliken.top\/?p=1455"},"modified":"2021-09-13T14:37:15","modified_gmt":"2021-09-13T06:37:15","slug":"mysql%e5%9f%ba%e7%a1%80%e4%b9%8b%e5%b8%b8%e7%94%a8%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/blog.odjbinail.cn\/?p=1455","title":{"rendered":"MySQL\u57fa\u7840\u4e4b\u5e38\u7528\u51fd\u6570"},"content":{"rendered":"<h2>\u6559\u5b66\u51fd\u6570\u7684\u4f7f\u7528<\/h2>\n<p><a href=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2021\/09\/2021091305463086.png\" rel=\"box\" class=\"fancybox\"><img data-original=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2021\/09\/2021091305463086.png\"  alt=\"\" \/><\/a><\/p>\n<noscript><img decoding=\"async\" src=\"https:\/\/blog.odjbinail.cn\/wp-content\/uploads\/2021\/09\/2021091305463086.png\" alt=\"\" \/><\/a><\/p><\/noscript>\n<h2>\u5b57\u7b26\u4e32\u5e38\u7528\u51fd\u6570<\/h2>\n<ul>\n<li>\u7528 MySQL \u8bed\u53e5\u5c06 10002554.333 \u8f6c\u6362\u4e3a\u4fdd\u7559\u4e00\u4f4d\u5c0f\u6570\u7684\u5343\u5206\u4f4d\u5212\u5206\u7684\u6807\u51c6\u6570\u5b57\u683c\u5f0f\uff08\uff09SELECT FORMAT(10002554.333,1);<\/li>\n<li>\u82e5\u6709\u4e00\u5b57\u7b26\u4e32 !!Hello! World!!! \uff0c\u4e0b\u9762\u54ea\u6761\u8bed\u53e5\u53ef\u4ee5\u5c06\u91cc\u9762\u6240\u6709\u7684 ! \u53f7\u90fd\u53bb\u6389 SELECT REPLACE('!!hello! world!!!','!','');<\/li>\n<\/ul>\n<pre class=\"prettyprint linenums\" ><code>-- \u6d4b\u8bd5\u5b57\u7b26\u4e32\u51fd\u6570\n-- CHAR_LENGTH():\u5f97\u5230\u5b57\u7b26\u4e32\u7684\u5b57\u7b26\u6570\nSELECT CHAR_LENGTH(&#039;abc&#039;);\n-- LENGTH():\u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\nSELECT LENGTH(&#039;abc&#039;);\n-- CONCAT(s1,s2,....):\u5c06\u5b57\u7b26\u4e32\u5408\u5e76\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\nSELECT CONCAT(&#039;a&#039;,&#039;b&#039;,&#039;c&#039;);\n-- \u5982\u679c\u5b57\u7b26\u4e32\u4e2d\u5305\u542b NULL\uff0c\u8fd4\u56de\u62fc\u63a5\u7ed3\u679c\u5c31\u662f NULL\nSELECT CONCAT(&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,null);-- null\n-- CONCAT_WS(x,s1,s2,s2....)\uff1a\u4ee5\u6307\u5b9a\u5206\u9694\u7b26\u62fc\u63a5\u5b57\u7b26\u4e32\nSELECT CONCAT_WS(&#039;-&#039;,&#039;a&#039;,&#039;b&#039;,&#039;c&#039;);--  a-b-c\n-- \u5982\u679c null \u5728\u62fc\u63a5\u7684\u5185\u5bb9\u4e2d\uff0c\u5219\u8f6c\u5316\u6210\u7a7a\u5b57\u7b26\u4e32\nSELECT CONCAT_WS(&#039;-&#039;,&#039;a&#039;,&#039;b&#039;,&#039;c&#039;,null);\n-- \u5982\u679c\u5206\u9694\u7b26\u4e3a null\uff0c\u62fc\u63a5\u7684\u7ed3\u679c\u4e3a null\nSELECT CONCAT_WS(null,&#039;a&#039;,&#039;b&#039;,&#039;c&#039;);-- null\n-- \u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u5927\u5199\u6216\u8005\u5c0f\u5199 UPPER()| UCASE() LOWER()[\u5c0f\u5199] |LCASE()\nSELECT UPPER(&#039;hello king&#039;),UCASE(&#039;hello imooc&#039;),LOWER(&#039;HELLO ADMIN&#039;),LCASE(&#039;HELLO EVERYBODY&#039;);\n-- \u5b57\u7b26\u4e32\u7684\u53cd\u8f6c REVERSE()\nSELECT REVERSE(&#039;abc&#039;); --cba\n-- LEFT()|RIGHT():\u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u524d\u51e0\u4e2a\u5b57\u7b26\u6216\u8005\u540e\u51e0\u4e2a\u5b57\u7b26\nSELECT LEFT(&#039;hello&#039;,2),RIGHT(&#039;hello&#039;,2);\n-- LPAD()|RPAD():\u7528\u5b57\u7b26\u4e32\u586b\u5145\u5230\u6307\u5b9a\u957f\u5ea6\nSELECT LPAD(&#039;abc&#039;,10,&#039;?&#039;);--\u524d?\nSELECT RPAD(&#039;abc&#039;,10,&#039;!&#039;);--\u540e!\n-- \u53bb\u6389\u5b57\u7b26\u4e32\u4e24\u7aef\u7684\u7a7a\u683c TRIM()\u3010\u4e24\u7aef\u3011|LTRIM()\u3010\u5de6\u7aef\u3011|RTRIM():\u3010\u53f3\u7aef\u3011\nSELECT CONCAT(&#039;*&#039;,TRIM(&#039; abc &#039;),&#039;*&#039;),CONCAT(&#039;*&#039;,LTRIM(&#039; abc &#039;),&#039;*&#039;),CONCAT(&#039;*&#039;,RTRIM(&#039; abc &#039;),&#039;*&#039;);\n-- REPEAT():\u91cd\u590d\u6307\u5b9a\u7684\u6b21\u6570\nSELECT REPEAT(&#039;hello&#039;,3);\n-- REPLACE():\u5b57\u7b26\u4e32\nSELECT REPLACE(&#039;hello king&#039;,&#039;king&#039;,&#039;queen&#039;);--hello queen\n-- \u622a\u53d6\u5b57\u7b26\u4e32 SUBSTRING\nSELECT SUBSTRING(&#039;abcdef&#039;,1,3);--\u4ece\u7b2c\u4e00\u4e2a 1 \u5f00\u59cb\uff0c\u622a\u53d6 3 \u4e2a\n-- \u6bd4\u8f83\u5b57\u7b26\u4e32\nSELECT STRCMP(&#039;a&#039;,&#039;b&#039;);--a&lt;b -1 a=a 0 a&gt;b 1<\/code><\/pre>\n<h2>\u65e5\u671f\u65f6\u95f4\u5e38\u7528\u51fd\u6570\u7684\u4f7f\u7528<\/h2>\n<pre class=\"prettyprint linenums\" ><code>-- \u6d4b\u8bd5\u65e5\u671f\u65f6\u95f4\u51fd\u6570\n-- \u8fd4\u56de\u5f53\u524d\u65e5\u671f\nSELECT CURDATE(),CURRENT_DATE();\n-- \u8fd4\u56de\u5f53\u524d\u65f6\u95f4\nSELECT CURTIME(),CURRENT_TIME();\n-- \u8fd4\u56de\u5f53\u524d\u7684\u65e5\u671f\u65f6\u95f4\nSELECT NOW(),CURRENT_TIMESTAMP(),SYSDATE();\n-- \u8fd4\u56de\u65e5\u671f\u4e2d\u7684\u6708\u4efd\u548c\u6708\u4efd\u7684\u540d\u79f0\nSELECT MONTH(&#039;2017-02-19&#039;);\nSELECT MONTH(CURDATE()),MONTHNAME(CURDATE());\n-- \u8fd4\u56de\u661f\u671f\u51e0\nSELECT DAYNAME(NOW());\n-- \u8fd4\u56de\u4e00\u5468\u5185\u7684\u7b2c\u51e0\u5929,1 \u4ee3\u8868\u661f\u671f\u5929\u30012 \u4ee3\u8868\u661f\u671f\u4e00\nSELECT DAYOFWEEK(NOW());\n-- \u4e00\u5e74\u4e2d\u7b2c\u51e0\u4e2a\u661f\u671f\nSELECT WEEK(NOW());\n--\u5f53\u524d\u65e5\u671f\u65f6\u95f4\nSELECT YEAR(NOW()),MONTH(NOW()),DAY(NOW()),HOUR(NOW()),MINUTE(NOW()),SECOND(NOW());\n-- DATEDIFF()\u8ba1\u7b97\u4e24\u4e2a\u65e5\u671f\u76f8\u5dee\u7684\u5929\u6570\nSELECT DATEDIFF(&#039;2017-03-06&#039;,&#039;2017-03-02&#039;);<\/code><\/pre>\n<h2>\u5176\u5b83\u5e38\u7528\u51fd\u6570<\/h2>\n<pre class=\"prettyprint linenums\" ><code>-- \u6d4b\u8bd5\u5176\u5b83\u5e38\u7528\u51fd\u6570\nSELECT VERSION(),CONNECTION_ID();\n--\u5f97\u5230\u5f53\u524d\u767b\u5f55\u7684\u7528\u6237\nSELECT USER(),CURRENT_USER(),SYSTEM_USER(),SESSION_USER();\n-- \u5f97\u5230\u4e0a\u4e00\u6b65\u63d2\u5165\u64cd\u4f5c\u4ea7\u751f AUTO_INCREMENT \u7684\u503c\nSELECT LAST_INSERT_ID();\n--\u8fdb\u884c\u52a0\u5bc6\nSELECT MD5(&#039;king&#039;);\n-- PASSWORD():\u5bc6\u7801\u52a0\u5bc6\u7b97\u6cd5\nSELECT PASSWORD(&#039;root&#039;);<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6559\u5b66\u51fd\u6570\u7684\u4f7f\u7528 \u5b57\u7b26\u4e32\u5e38\u7528\u51fd\u6570 \u7528 MySQL \u8bed\u53e5\u5c06 10002554.333 \u8f6c\u6362\u4e3a\u4fdd\u7559\u4e00\u4f4d\u5c0f\u6570\u7684\u5343\u5206\u4f4d\u5212 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1455","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/posts\/1455","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1455"}],"version-history":[{"count":0,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=\/wp\/v2\/posts\/1455\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.odjbinail.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}