{"id":5322,"date":"2024-11-14T12:26:14","date_gmt":"2024-11-14T04:26:14","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5322\/"},"modified":"2024-11-14T12:26:14","modified_gmt":"2024-11-14T04:26:14","slug":"oracle%e6%97%a5%e6%9c%9f%e5%87%bd%e6%95%b0%e6%80%8e%e4%b9%88%e5%86%99","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5322\/","title":{"rendered":"oracle\u65e5\u671f\u51fd\u6570\u600e\u4e48\u5199"},"content":{"rendered":"<p><strong> \u65e5\u671f\u51fd\u6570<\/strong><\/p>\n<p>Oracle \u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u5f3a\u5927\u7684\u65e5\u671f\u51fd\u6570\uff0c\u7528\u4e8e\u5bf9\u65e5\u671f\u6570\u636e\u8fdb\u884c\u64cd\u4f5c\u548c\u8f6c\u6362\u3002\u8fd9\u4e9b\u51fd\u6570\u5728\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u4e2d\u975e\u5e38\u6709\u7528\u3002<\/p>\n<p><strong>\u57fa\u672c\u65e5\u671f\u51fd\u6570<\/strong><\/p>\n<ul>\n<li> <strong>SYSDATE<\/strong>\uff1a\u8fd4\u56de\u5f53\u524d\u7cfb\u7edf\u65e5\u671f\u548c\u65f6\u95f4\u3002<\/li>\n<li> <strong>NOW<\/strong>\uff1a\u4e0e SYSDATE \u76f8\u540c\uff0c\u8fd4\u56de\u5f53\u524d\u7cfb\u7edf\u65e5\u671f\u548c\u65f6\u95f4\u3002<\/li>\n<li> <strong>TRUNC<\/strong>\uff1a\u5c06\u65e5\u671f\u622a\u65ad\u5230\u6307\u5b9a\u7684\u7cbe\u5ea6\uff08\u4f8b\u5982\uff0cTRUNC(sysdate, &#8216;MONTH&#8217;) \u8fd4\u56de\u5f53\u524d\u6708\u4efd\u7684\u7b2c\u4e00\u5929\uff09\u3002<\/li>\n<li> <strong>ADD_MONTHS<\/strong>\uff1a\u5c06\u6307\u5b9a\u7684\u6708\u6570\u6dfb\u52a0\u5230\u65e5\u671f\u4e2d\u3002<\/li>\n<li> <strong>SUBTRACT_MONTHS<\/strong>\uff1a\u4ece\u65e5\u671f\u4e2d\u51cf\u53bb\u6307\u5b9a\u7684\u6708\u6570\u3002<\/li>\n<\/ul>\n<p><strong>\u65e5\u671f\u6bd4\u8f83\u51fd\u6570<\/strong><\/p>\n<ul>\n<li> <strong>DATE_EQUAL<\/strong>\uff1a\u6bd4\u8f83\u4e24\u4e2a\u65e5\u671f\u662f\u5426\u76f8\u7b49\u3002<\/li>\n<li> <strong>DATE_GREATER<\/strong>\uff1a\u6bd4\u8f83\u4e00\u4e2a\u65e5\u671f\u662f\u5426\u5927\u4e8e\u53e6\u4e00\u4e2a\u65e5\u671f\u3002<\/li>\n<li> <strong>DATE_LESSER<\/strong>\uff1a\u6bd4\u8f83\u4e00\u4e2a\u65e5\u671f\u662f\u5426\u5c0f\u4e8e\u53e6\u4e00\u4e2a\u65e5\u671f\u3002<\/li>\n<\/ul>\n<p><strong>\u65e5\u671f\u683c\u5f0f\u5316\u51fd\u6570<\/strong><\/p>\n<ul>\n<li> <strong>TO_CHAR<\/strong>\uff1a\u5c06\u65e5\u671f\u8f6c\u6362\u4e3a\u6307\u5b9a\u7684\u5b57\u7b26\u683c\u5f0f\u3002<\/li>\n<li> <strong>TO_DATE<\/strong>\uff1a\u5c06\u5b57\u7b26\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u65e5\u671f\u3002<\/li>\n<\/ul>\n<p><strong>\u5176\u4ed6\u9ad8\u7ea7\u51fd\u6570<\/strong><\/p>\n<ul>\n<li> <strong>DAYS_BETWEEN<\/strong>\uff1a\u8ba1\u7b97\u4e24\u4e2a\u65e5\u671f\u4e4b\u95f4\u7684\u5929\u6570\u5dee\u3002<\/li>\n<li> <strong>EXTRACT<\/strong>\uff1a\u4ece\u65e5\u671f\u4e2d\u63d0\u53d6\u7279\u5b9a\u7684\u65e5\u671f\u90e8\u5206\uff08\u4f8b\u5982\uff0cEXTRACT(HOUR FROM sysdate)\uff09\u3002<\/li>\n<li> <strong>NEXT_DAY<\/strong>\uff1a\u8fd4\u56de\u4e0b\u4e00\u4e2a\u6ee1\u8db3\u6307\u5b9a\u6761\u4ef6\u7684\u65e5\u671f\u3002<\/li>\n<li> <strong>LAST_DAY<\/strong>\uff1a\u8fd4\u56de\u6307\u5b9a\u6708\u4efd\u7684\u6700\u540e\u4e00\u5929\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f7f\u7528 Oracle \u65e5\u671f\u51fd\u6570\u7684\u793a\u4f8b\uff1a<\/p>\n<ul>\n<li>\u83b7\u53d6\u5f53\u524d\u65e5\u671f\uff1aSELECT SYSDATE FROM DUAL;<\/li>\n<li>\u5c06\u65e5\u671f\u622a\u65ad\u5230\u6708\u4efd\uff1aSELECT TRUNC(sysdate, &#8216;MONTH&#8217;) FROM DUAL;<\/li>\n<li>\u8ba1\u7b97\u4e24\u4e2a\u65e5\u671f\u4e4b\u95f4\u7684\u5929\u6570\u5dee\uff1aSELECT DAYS_BETWEEN(&#8216;2023-01-01&#8217;, &#8216;2023-03-01&#8217;) FROM DUAL;<\/li>\n<li>\u5c06\u65e5\u671f\u8f6c\u6362\u4e3a\u7279\u5b9a\u683c\u5f0f\uff1aSELECT TO_CHAR(sysdate, &#8216;YYYY-MM-DD&#8217;) FROM DUAL;<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u64cd\u7eb5\u548c\u5206\u6790\u65e5\u671f\u6570\u636e\uff0c\u4ee5\u6ee1\u8db3\u60a8\u7684\u7279\u5b9a\u9700\u6c42\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u65e5\u671f\u51fd\u6570\u600e\u4e48\u5199\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>\u65e5\u671f\u51fd\u6570 Oracle \u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u5f3a\u5927\u7684\u65e5\u671f\u51fd\u6570\uff0c\u7528\u4e8e\u5bf9\u65e5\u671f\u6570\u636e\u8fdb\u884c\u64cd\u4f5c\u548c\u8f6c\u6362\u3002\u8fd9\u4e9b\u51fd\u6570\u5728\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u4e2d\u975e\u5e38\u6709\u7528\u3002 \u57fa\u672c\u65e5\u671f\u51fd\u6570 SYSDATE\uff1a\u8fd4\u56de\u5f53\u524d\u7cfb\u7edf\u65e5\u671f\u548c\u65f6\u95f4\u3002 NOW\uff1a\u4e0e SYSDATE \u76f8\u540c\uff0c\u8fd4\u56de\u5f53\u524d\u7cfb\u7edf\u65e5\u671f\u548c\u65f6\u95f4\u3002 TRUNC\uff1a\u5c06\u65e5\u671f\u622a\u65ad\u5230\u6307\u5b9a\u7684\u7cbe\u5ea6\uff08\u4f8b\u5982\uff0cTRUNC(sysdate, &#8216;MONTH&#8217;) \u8fd4\u56de\u5f53\u524d\u6708\u4efd\u7684\u7b2c\u4e00\u5929\uff09\u3002 ADD_MONTHS\uff1a\u5c06\u6307\u5b9a\u7684\u6708\u6570\u6dfb\u52a0\u5230\u65e5\u671f\u4e2d\u3002 SUBTRACT_MONTHS\uff1a\u4ece\u65e5\u671f\u4e2d\u51cf\u53bb\u6307\u5b9a\u7684\u6708\u6570\u3002 \u65e5\u671f\u6bd4\u8f83\u51fd\u6570 DATE_EQUAL\uff1a\u6bd4\u8f83\u4e24\u4e2a\u65e5\u671f\u662f\u5426\u76f8\u7b49\u3002 DATE_GREATER\uff1a\u6bd4\u8f83\u4e00\u4e2a\u65e5\u671f\u662f\u5426\u5927\u4e8e\u53e6\u4e00\u4e2a\u65e5\u671f\u3002 DATE_LESSER\uff1a\u6bd4\u8f83\u4e00\u4e2a\u65e5\u671f\u662f\u5426\u5c0f\u4e8e\u53e6\u4e00\u4e2a\u65e5\u671f\u3002 \u65e5\u671f\u683c\u5f0f\u5316\u51fd\u6570 TO_CHAR\uff1a\u5c06\u65e5\u671f\u8f6c\u6362\u4e3a\u6307\u5b9a\u7684\u5b57\u7b26\u683c\u5f0f\u3002 TO_DATE\uff1a\u5c06\u5b57\u7b26\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u65e5\u671f\u3002 \u5176\u4ed6\u9ad8\u7ea7\u51fd\u6570 DAYS_BETWEEN\uff1a\u8ba1\u7b97\u4e24\u4e2a\u65e5\u671f\u4e4b\u95f4\u7684\u5929\u6570\u5dee\u3002 EXTRACT\uff1a\u4ece\u65e5\u671f\u4e2d\u63d0\u53d6\u7279\u5b9a\u7684\u65e5\u671f\u90e8\u5206\uff08\u4f8b\u5982\uff0cEXTRACT(HOUR FROM sysdate)\uff09\u3002 NEXT_DAY\uff1a\u8fd4\u56de\u4e0b\u4e00\u4e2a\u6ee1\u8db3\u6307\u5b9a\u6761\u4ef6\u7684\u65e5\u671f\u3002 LAST_DAY\uff1a\u8fd4\u56de\u6307\u5b9a\u6708\u4efd\u7684\u6700\u540e\u4e00\u5929\u3002 \u793a\u4f8b \u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f7f\u7528 Oracle \u65e5\u671f\u51fd\u6570\u7684\u793a\u4f8b\uff1a \u83b7\u53d6\u5f53\u524d\u65e5\u671f\uff1aSELECT SYSDATE FROM DUAL; \u5c06\u65e5\u671f\u622a\u65ad\u5230\u6708\u4efd\uff1aSELECT TRUNC(sysdate, &#8216;MONTH&#8217;) FROM DUAL; \u8ba1\u7b97\u4e24\u4e2a\u65e5\u671f\u4e4b\u95f4\u7684\u5929\u6570\u5dee\uff1aSELECT DAYS_BETWEEN(&#8216;2023-01-01&#8217;, &#8216;2023-03-01&#8217;) FROM DUAL; \u5c06\u65e5\u671f\u8f6c\u6362\u4e3a\u7279\u5b9a\u683c\u5f0f\uff1aSELECT TO_CHAR(sysdate, &#8216;YYYY-MM-DD&#8217;) FROM DUAL; \u901a\u8fc7\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u64cd\u7eb5\u548c\u5206\u6790\u65e5\u671f\u6570\u636e\uff0c\u4ee5\u6ee1\u8db3\u60a8\u7684\u7279\u5b9a\u9700\u6c42\u3002 \u4ee5\u4e0a\u5c31\u662f\u65e5\u671f\u51fd\u6570\u600e\u4e48\u5199\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-5322","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5322","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=5322"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5322\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}