{"id":6179,"date":"2024-11-14T12:31:32","date_gmt":"2024-11-14T04:31:32","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6179\/"},"modified":"2024-11-14T12:31:32","modified_gmt":"2024-11-14T04:31:32","slug":"mysql%e5%a6%82%e4%bd%95%e5%b0%86%e5%ad%97%e7%ac%a6%e4%b8%b2%e8%bd%ac%e6%8d%a2%e6%88%90%e6%95%b0%e5%ad%97","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6179\/","title":{"rendered":"mysql\u5982\u4f55\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6570\u5b57"},"content":{"rendered":"<blockquote><p>\n  \u8981\u5c06 mysql \u4e2d\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u5b57\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1aconvert() \u51fd\u6570\uff1aselect convert(my_string, unsigned integer);cast() \u51fd\u6570\uff1aselect cast(my_string as unsigned integer);str_to_int() \u51fd\u6570\uff1aselect str_to_int(my_string, 10);val() \u51fd\u6570\uff1aselect val(my_string);\u8fd0\u7b97\u7b26\uff1aselect +my_string;\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/14\/2024061404362343945.jpg\" class=\"aligncenter\" title=\"mysql\u5982\u4f55\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6570\u5b57\u63d2\u56fe\" alt=\"mysql\u5982\u4f55\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6570\u5b57\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06 MySQL \u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6570\u5b57<\/strong><\/p>\n<p>\u5728 MySQL \u4e2d\uff0c\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6570\u5b57\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. \u4f7f\u7528 CONVERT() \u51fd\u6570<\/strong><\/p>\n<pre>SELECT CONVERT(my_string, UNSIGNED INTEGER);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 CAST() \u51fd\u6570<\/strong><\/p>\n<pre>SELECT CAST(my_string AS UNSIGNED INTEGER);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u4f7f\u7528 STR_TO_INT() \u51fd\u6570<\/strong><\/p>\n<pre>SELECT STR_TO_INT(my_string, 10);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u4f7f\u7528 VAL() \u51fd\u6570<\/strong><\/p>\n<pre>SELECT VAL(my_string);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u4f7f\u7528 + \u8fd0\u7b97\u7b26<\/strong><\/p>\n<pre>SELECT +my_string;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u9002\u7528\u4e8e\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6574\u6570\u3002<\/li>\n<li>\u5bf9\u4e8e\u6d6e\u70b9\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528 CONVERT() \u6216 CAST() \u51fd\u6570\u3002<\/li>\n<li>\u5982\u679c\u5b57\u7b26\u4e32\u5305\u542b\u975e\u6570\u5b57\u5b57\u7b26\uff0c\u5219\u8f6c\u6362\u5c06\u5931\u8d25\u5e76\u8fd4\u56de NULL\u3002<\/li>\n<li>\u53ef\u4ee5\u4f7f\u7528 ISNUMERIC() \u51fd\u6570\u68c0\u67e5\u5b57\u7b26\u4e32\u662f\u5426\u53ef\u4ee5\u8f6c\u6362\u4e3a\u6570\u5b57\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6570\u5b57\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8981\u5c06 mysql \u4e2d\u7684\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u6570\u5b57\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1aconvert() \u51fd\u6570\uff1aselect convert(my_string, unsigned integer);cast() \u51fd\u6570\uff1aselect cast(my_string as unsigned integer);str_to_int() \u51fd\u6570\uff1aselect str_to_int(my_string, 10);val() \u51fd\u6570\uff1aselect val(my_string);\u8fd0\u7b97\u7b26\uff1aselect +my_string; \u5982\u4f55\u5c06 MySQL \u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6570\u5b57 \u5728 MySQL \u4e2d\uff0c\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6570\u5b57\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a 1. \u4f7f\u7528 CONVERT() \u51fd\u6570 SELECT CONVERT(my_string, UNSIGNED INTEGER); \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528 CAST() \u51fd\u6570 SELECT CAST(my_string AS UNSIGNED INTEGER); \u767b\u5f55\u540e\u590d\u5236 3. \u4f7f\u7528 STR_TO_INT() \u51fd\u6570 SELECT STR_TO_INT(my_string, 10); \u767b\u5f55\u540e\u590d\u5236 4. \u4f7f\u7528 VAL() \u51fd\u6570 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6179","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6179","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6179"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6179\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6179"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6179"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6179"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}