{"id":26595,"date":"2024-11-24T14:30:54","date_gmt":"2024-11-24T06:30:54","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26595\/"},"modified":"2024-11-24T14:30:54","modified_gmt":"2024-11-24T06:30:54","slug":"mysql-%e4%b8%ad-str_to_date-%e5%87%bd%e6%95%b0%e8%bf%94%e5%9b%9e-null%ef%bc%9a%e4%b8%ba%e4%bd%95-plan_start_time-%e5%88%97%e4%b8%ba%e7%a9%ba%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26595\/","title":{"rendered":"MySQL \u4e2d STR_TO_DATE \u51fd\u6570\u8fd4\u56de NULL\uff1a\u4e3a\u4f55 &#8220;plan_start_time&#8221; \u5217\u4e3a\u7a7a\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173102527286644.jpg\" class=\"aligncenter\" title=\"MySQL \u4e2d STR_TO_DATE \u51fd\u6570\u8fd4\u56de NULL\uff1a\u4e3a\u4f55 &#8220;plan_start_time&#8221; \u5217\u4e3a\u7a7a\uff1f\u63d2\u56fe\" alt=\"MySQL \u4e2d STR_TO_DATE \u51fd\u6570\u8fd4\u56de NULL\uff1a\u4e3a\u4f55 &#8220;plan_start_time&#8221; \u5217\u4e3a\u7a7a\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4e2dstr_to_date\u51fd\u6570\u8fd4\u56denull\u7684\u95ee\u9898\u63a2\u7a76<\/strong><\/p>\n<p>\u5728\u4f7f\u7528mysql\u67e5\u8be2\u4e2d\uff0cstr_to_date\u51fd\u6570\u65e8\u5728\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u200b\u200b\u4e3a\u65e5\u671f\u6216\u65f6\u95f4\u7c7b\u578b\u3002\u7136\u800c\uff0c\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4e00\u51fd\u6570\u53ef\u80fd\u4f1a\u8fd4\u56denull\uff0c\u8ba9\u6211\u4eec\u6df1\u5165\u5206\u6790\u4e00\u4e2a\u76f8\u5173\u7684\u573a\u666f\u3002<\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><br \/>\u4e3a\u4ec0\u4e48\u4ee5\u4e0b\u67e5\u8be2\u8fd4\u56de&#8221;temp&#8221;\u5217\u4e3a\u7a7a\uff08null\uff09\uff1f<\/p>\n<pre>SELECT STR_TO_DATE(plan_start_time, '%h:%i:%s') as temp, plan_start_time from base_stop_calendar<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5206\u6790\u548c\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u4ece\u7ed9\u51fa\u7684\u9519\u8bef\u4fe1\u606f\u6765\u770b\uff0c\u95ee\u9898\u53ef\u80fd\u5728\u4e8estr_to_date\u51fd\u6570\u4e0e&#8221;plan_start_time&#8221;\u5217\u4e2d\u5b58\u50a8\u7684\u6570\u636e\u7c7b\u578b\u4e0d\u5339\u914d\u3002<\/p>\n<p>original \u63d0\u4f9b\u7684\u9644\u52a0\u4fe1\u606f\u8868\u660e &#8220;plan_start_time&#8221; \u662fvarchar\u7c7b\u578b\uff0c\u800c str_to_date \u51fd\u6570\u8f6c\u6362\u5b57\u7b26\u4e32\u683c\u5f0f\u4e3a hh:mm:ss \u65f6\u95f4\u683c\u5f0f\uff0c\u5176\u4e2d hh \u4e3a\u5c0f\u65f6\u6570\uff0cmm \u4e3a\u5206\u949f\u6570\uff0css \u4e3a\u79d2\u6570\u3002\u5728\u683c\u5f0f\u5316\u5b57\u7b26\u4e2d\uff0c\u5927\u5199 &#8220;h&#8221; \u8868\u793a 24 \u5c0f\u65f6\u5236\uff0c\u800c\u5c0f\u5199 &#8220;h&#8221; \u8868\u793a 12 \u5c0f\u65f6\u5236\u3002<\/p>\n<p>\u56e0\u6b64\uff0c\u8bf7\u786e\u4fdd &#8220;plan_start_time&#8221; \u5217\u4e2d\u7684\u503c\u9075\u5faa\u6307\u5b9a\u7684\u683c\u5f0f\uff0c\u5e76\u4e14\u683c\u5f0f\u5316\u5b57\u7b26\u4e0e\u503c\u7684\u683c\u5f0f\u76f8\u5339\u914d\u3002\u4f8b\u5982\uff0c\u5982\u679c &#8220;plan_start_time&#8221; \u5217\u4e2d\u5305\u542b &#8220;09:00:00&#8221; \u8fd9\u6837\u7684\u503c\uff0c\u90a3\u4e48\u683c\u5f0f\u5316\u5b57\u7b26\u5e94\u4e3a &#8220;%h:%i:%s&#8221;\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u8bf7\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<ul>\n<li>\u786e\u4fdd &#8220;plan_start_time&#8221; \u5217\u4e2d\u7684\u503c\u662f\u6709\u6548\u7684\u65e5\u671f\u6216\u65f6\u95f4\u5b57\u7b26\u4e32\u3002<\/li>\n<li>\u5927\u5199\u548c\u5c0f\u5199 &#8220;h&#8221; \u6709\u3002<\/li>\n<li>\u4f7f\u7528\u5176\u4ed6\u65e5\u671f\u548c\u65f6\u95f4\u51fd\u6570\uff0c\u4f8b\u5982 date_format() \u6216 timestamp()\uff0c\u53ef\u80fd\u4f1a\u66f4\u9002\u5408\u67d0\u4e9b\u573a\u666f\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL \u4e2d STR_TO_DATE \u51fd\u6570\u8fd4\u56de NULL\uff1a\u4e3a\u4f55 &#8220;plan_start_time&#8221; \u5217\u4e3a\u7a7a\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e2dstr_to_date\u51fd\u6570\u8fd4\u56denull\u7684\u95ee\u9898\u63a2\u7a76 \u5728\u4f7f\u7528mysql\u67e5\u8be2\u4e2d\uff0cstr_to_date\u51fd\u6570\u65e8\u5728\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u200b\u200b\u4e3a\u65e5\u671f\u6216\u65f6\u95f4\u7c7b\u578b\u3002\u7136\u800c\uff0c\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4e00\u51fd\u6570\u53ef\u80fd\u4f1a\u8fd4\u56denull\uff0c\u8ba9\u6211\u4eec\u6df1\u5165\u5206\u6790\u4e00\u4e2a\u76f8\u5173\u7684\u573a\u666f\u3002 \u95ee\u9898\uff1a\u4e3a\u4ec0\u4e48\u4ee5\u4e0b\u67e5\u8be2\u8fd4\u56de&#8221;temp&#8221;\u5217\u4e3a\u7a7a\uff08null\uff09\uff1f SELECT STR_TO_DATE(plan_start_time, &#8216;%h:%i:%s&#8217;) as temp, plan_start_time from base_stop_calendar \u767b\u5f55\u540e\u590d\u5236 \u5206\u6790\u548c\u89e3\u51b3\u65b9\u6848\uff1a \u4ece\u7ed9\u51fa\u7684\u9519\u8bef\u4fe1\u606f\u6765\u770b\uff0c\u95ee\u9898\u53ef\u80fd\u5728\u4e8estr_to_date\u51fd\u6570\u4e0e&#8221;plan_start_time&#8221;\u5217\u4e2d\u5b58\u50a8\u7684\u6570\u636e\u7c7b\u578b\u4e0d\u5339\u914d\u3002 original \u63d0\u4f9b\u7684\u9644\u52a0\u4fe1\u606f\u8868\u660e &#8220;plan_start_time&#8221; \u662fvarchar\u7c7b\u578b\uff0c\u800c str_to_date \u51fd\u6570\u8f6c\u6362\u5b57\u7b26\u4e32\u683c\u5f0f\u4e3a hh:mm:ss \u65f6\u95f4\u683c\u5f0f\uff0c\u5176\u4e2d hh \u4e3a\u5c0f\u65f6\u6570\uff0cmm \u4e3a\u5206\u949f\u6570\uff0css \u4e3a\u79d2\u6570\u3002\u5728\u683c\u5f0f\u5316\u5b57\u7b26\u4e2d\uff0c\u5927\u5199 &#8220;h&#8221; \u8868\u793a 24 \u5c0f\u65f6\u5236\uff0c\u800c\u5c0f\u5199 &#8220;h&#8221; \u8868\u793a 12 \u5c0f\u65f6\u5236\u3002 \u56e0\u6b64\uff0c\u8bf7\u786e\u4fdd &#8220;plan_start_time&#8221; \u5217\u4e2d\u7684\u503c\u9075\u5faa\u6307\u5b9a\u7684\u683c\u5f0f\uff0c\u5e76\u4e14\u683c\u5f0f\u5316\u5b57\u7b26\u4e0e\u503c\u7684\u683c\u5f0f\u76f8\u5339\u914d\u3002\u4f8b\u5982\uff0c\u5982\u679c &#8220;plan_start_time&#8221; \u5217\u4e2d\u5305\u542b &#8220;09:00:00&#8221; \u8fd9\u6837\u7684\u503c\uff0c\u90a3\u4e48\u683c\u5f0f\u5316\u5b57\u7b26\u5e94\u4e3a &#8220;%h:%i:%s&#8221;\u3002 \u6b64\u5916\uff0c\u8bf7\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a \u786e\u4fdd &#8220;plan_start_time&#8221; \u5217\u4e2d\u7684\u503c\u662f\u6709\u6548\u7684\u65e5\u671f\u6216\u65f6\u95f4\u5b57\u7b26\u4e32\u3002 \u5927\u5199\u548c\u5c0f\u5199 &#8220;h&#8221; \u6709\u3002 \u4f7f\u7528\u5176\u4ed6\u65e5\u671f\u548c\u65f6\u95f4\u51fd\u6570\uff0c\u4f8b\u5982 date_format() \u6216 timestamp()\uff0c\u53ef\u80fd\u4f1a\u66f4\u9002\u5408\u67d0\u4e9b\u573a\u666f\u3002 \u4ee5\u4e0a\u5c31\u662fMySQL \u4e2d [&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-26595","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26595","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=26595"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26595\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}