{"id":5877,"date":"2024-11-14T09:15:15","date_gmt":"2024-11-14T01:15:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5877\/"},"modified":"2024-11-14T09:15:15","modified_gmt":"2024-11-14T01:15:15","slug":"sql%e5%bd%93%e5%89%8d%e6%97%b6%e9%97%b4%e6%80%8e%e4%b9%88%e8%a1%a8%e7%a4%ba","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5877\/","title":{"rendered":"sql\u5f53\u524d\u65f6\u95f4\u600e\u4e48\u8868\u793a"},"content":{"rendered":"<blockquote><p>\n  sql \u4e2d\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u7684\u8bed\u6cd5\u56e0\u6570\u636e\u5e93\u7cfb\u7edf\u800c\u5f02\uff0c\u5e38\u89c1\u65b9\u6cd5\u5305\u62ec\uff1anow() \u51fd\u6570\uff08mysql\u3001mariadb\u3001postgresql\uff09current_timestamp() \u51fd\u6570\uff08oracle\u3001db2\u3001sql server\uff09getdate() \u51fd\u6570\uff08microsoft sql server\uff09sysdate() \u51fd\u6570\uff08oracle\uff09current_date() \u51fd\u6570\uff08mysql\u3001mariadb\uff09\u8fd4\u56de\u503c\u4e3a\u5f53\u524d\u7cfb\u7edf\u65f6\u95f4\u7684\u65e5\u671f\u65f6\u95f4\u503c\uff0c\u683c\u5f0f\u56e0\u6570\u636e\u5e93\u7cfb\u7edf\u800c\u5f02\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/03\/2024060321304257075.jpg\" class=\"aligncenter\" title=\"sql\u5f53\u524d\u65f6\u95f4\u600e\u4e48\u8868\u793a\u63d2\u56fe\" alt=\"sql\u5f53\u524d\u65f6\u95f4\u600e\u4e48\u8868\u793a\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 SQL \u8868\u793a\u5f53\u524d\u65f6\u95f4<\/strong><\/p>\n<p>SQL \u4e2d\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u7684\u8bed\u6cd5\u56e0\u6570\u636e\u5e93\u7cfb\u7edf\u800c\u5f02\u3002\u4ee5\u4e0b\u4ecb\u7ecd\u51e0\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. NOW() \u51fd\u6570<\/strong><\/p>\n<p><strong>MySQL\u3001MariaDB\u3001PostgreSQL:<\/strong><\/p>\n<pre>SELECT NOW();<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>2. CURRENT_TIMESTAMP() \u51fd\u6570<\/strong><\/p>\n<p><strong>Oracle\u3001DB2\u3001SQL Server:<\/strong><\/p>\n<pre>SELECT CURRENT_TIMESTAMP;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>3. GETDATE() \u51fd\u6570<\/strong><\/p>\n<p><strong>Microsoft SQL Server:<\/strong><\/p>\n<pre>SELECT GETDATE();<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>4. SYSDATE() \u51fd\u6570<\/strong><\/p>\n<p><strong>Oracle:<\/strong><\/p>\n<pre>SELECT SYSDATE;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>5. CURRENT_DATE() \u51fd\u6570<\/strong><\/p>\n<p><strong>MySQL\u3001MariaDB:<\/strong><\/p>\n<pre>SELECT CURRENT_DATE;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u8fd4\u56de\u503c:<\/strong><\/p>\n<p>\u8fd9\u4e9b\u51fd\u6570\u90fd\u8fd4\u56de\u4e00\u4e2a\u8868\u793a\u5f53\u524d\u7cfb\u7edf\u65f6\u95f4\u7684\u65e5\u671f\u65f6\u95f4\u503c\u3002\u8fd4\u56de\u503c\u7684\u683c\u5f0f\u56e0\u6570\u636e\u5e93\u7cfb\u7edf\u800c\u5f02\uff0c\u901a\u5e38\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u6216\u4e00\u4e2a\u65e5\u671f\u65f6\u95f4\u5bf9\u8c61\u3002<\/p>\n<p><strong>\u6ce8\u610f:<\/strong><\/p>\n<ul>\n<li>\u67d0\u4e9b\u6570\u636e\u5e93\u7cfb\u7edf\u53ef\u80fd\u8fd8\u63d0\u4f9b\u5176\u4ed6\u51fd\u6570\u6765\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\uff0c\u4f8b\u5982 LOCALTIME()\u3001LOCALTIMESTAMP() \u548c UTCNOW()\u3002<\/li>\n<li>\u5982\u679c\u9700\u8981\u5728 INSERT \u6216 UPDATE \u8bed\u53e5\u4e2d\u4f7f\u7528\u5f53\u524d\u65f6\u95f4\uff0c\u8bf7\u4f7f\u7528\u76f8\u5e94\u7684\u51fd\u6570\uff08\u4f8b\u5982 NOW() \u6216 CURRENT_TIMESTAMP)\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u4f7f\u7528\u6587\u5b57\u65f6\u95f4\u503c\u3002<\/li>\n<li>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6570\u636e\u5e93\u7cfb\u7edf\u53ef\u80fd\u5141\u8bb8\u4f7f\u7528 SYSTIMESTAMP \u6216 CURRENT \u522b\u540d\u6765\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\uff0c\u4f46\u8fd9\u4e9b\u7528\u6cd5\u4e0d\u5efa\u8bae\u4f7f\u7528\uff0c\u56e0\u4e3a\u5b83\u4eec\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6b67\u4e49\u6216\u4e0e\u5176\u4ed6\u5e94\u7528\u7a0b\u5e8f\u6216\u5de5\u5177\u4e0d\u517c\u5bb9\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fsql\u5f53\u524d\u65f6\u95f4\u600e\u4e48\u8868\u793a\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>sql \u4e2d\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u7684\u8bed\u6cd5\u56e0\u6570\u636e\u5e93\u7cfb\u7edf\u800c\u5f02\uff0c\u5e38\u89c1\u65b9\u6cd5\u5305\u62ec\uff1anow() \u51fd\u6570\uff08mysql\u3001mariadb\u3001postgresql\uff09current_timestamp() \u51fd\u6570\uff08oracle\u3001db2\u3001sql server\uff09getdate() \u51fd\u6570\uff08microsoft sql server\uff09sysdate() \u51fd\u6570\uff08oracle\uff09current_date() \u51fd\u6570\uff08mysql\u3001mariadb\uff09\u8fd4\u56de\u503c\u4e3a\u5f53\u524d\u7cfb\u7edf\u65f6\u95f4\u7684\u65e5\u671f\u65f6\u95f4\u503c\uff0c\u683c\u5f0f\u56e0\u6570\u636e\u5e93\u7cfb\u7edf\u800c\u5f02\u3002 \u5982\u4f55\u4f7f\u7528 SQL \u8868\u793a\u5f53\u524d\u65f6\u95f4 SQL \u4e2d\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u7684\u8bed\u6cd5\u56e0\u6570\u636e\u5e93\u7cfb\u7edf\u800c\u5f02\u3002\u4ee5\u4e0b\u4ecb\u7ecd\u51e0\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\uff1a 1. NOW() \u51fd\u6570 MySQL\u3001MariaDB\u3001PostgreSQL: SELECT NOW(); \u767b\u5f55\u540e\u590d\u5236 2. CURRENT_TIMESTAMP() \u51fd\u6570 Oracle\u3001DB2\u3001SQL Server: SELECT CURRENT_TIMESTAMP; \u767b\u5f55\u540e\u590d\u5236 3. GETDATE() \u51fd\u6570 Microsoft SQL Server: SELECT GETDATE(); \u767b\u5f55\u540e\u590d\u5236 4. SYSDATE() \u51fd\u6570 Oracle: SELECT SYSDATE; \u767b\u5f55\u540e\u590d\u5236 5. CURRENT_DATE() \u51fd\u6570 MySQL\u3001MariaDB: SELECT CURRENT_DATE; \u767b\u5f55\u540e\u590d\u5236 \u8fd4\u56de\u503c: \u8fd9\u4e9b\u51fd\u6570\u90fd\u8fd4\u56de\u4e00\u4e2a\u8868\u793a\u5f53\u524d\u7cfb\u7edf\u65f6\u95f4\u7684\u65e5\u671f\u65f6\u95f4\u503c\u3002\u8fd4\u56de\u503c\u7684\u683c\u5f0f\u56e0\u6570\u636e\u5e93\u7cfb\u7edf\u800c\u5f02\uff0c\u901a\u5e38\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u6216\u4e00\u4e2a\u65e5\u671f\u65f6\u95f4\u5bf9\u8c61\u3002 [&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-5877","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5877","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=5877"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5877\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5877"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5877"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5877"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}