{"id":251354,"date":"2022-09-08T08:04:31","date_gmt":"2022-09-08T00:04:31","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=251354"},"modified":"2022-08-29T09:05:21","modified_gmt":"2022-08-29T01:05:21","slug":"oracle-five-linux","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/oracle-five-linux.html","title":{"rendered":"\u603b\u7ed3Oracle\u6839\u636e\u65f6\u95f4\u67e5\u8be2\u7684\u4e00\u4e9b\u5e38\u89c1\u60c5\u51b5"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u6839\u636e\u65f6\u95f4\u67e5\u8be2\u662f\u6211\u4eec\u65e5\u5e38\u5f00\u53d1\u4e2d\u7ecf\u5e38\u4f1a\u9047\u5230\u7684\u4e00\u4e2a\u529f\u80fd,\u4e0b\u9762\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u4e86\u5173\u4e8eOracle\u6839\u636e\u65f6\u95f4\u67e5\u8be2\u7684\u4e00\u4e9b\u5e38\u89c1\u60c5\u51b5,\u6587\u4e2d\u901a\u8fc7\u5b9e\u4f8b\u4ee3\u7801\u4ecb\u7ecd\u7684\u975e\u5e38\u8be6\u7ec6,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
1. \u67e5\u8be2\u65f6\u95f4\u6bb5\u4e4b\u5185\u7684\u6570\u636e<\/strong><\/div>\n
\u67e5\u8be22021-01-01  \u81f3  2021-01- 02 \u7684\u6570\u636e\r\nSELECT *\r\nFROM t_table1 t\r\nWHERE t.d_time >= to_date('2021-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')\r\n    AND t.d_time <= to_date('2021-01-02 23:59:59', 'yyyy-mm-dd hh24:mi:ss');<\/pre>\n

\u4ee5\u4e0bSQL\uff0c\u53ea\u4f1a\u67e5\u8be22021-01-01\u81f32021-1-2 00:00:00\u7684\u6570\u636e<\/p>\n

SELECT *\r\nFROM T_EVENT_MANAGEMENT t\r\nWHERE t.s_ra_time >= to_date('2021-01-01', 'yyyy-mm-dd')\r\n    AND t.s_ra_time <= to_date('2021-01-02', 'yyyy-mm-dd');\r\n--to_date('2021-01-02', 'yyyy-mm-dd') = 2021-01-02 00:00:00 \u8d85\u8fc72\u53f70\u70b9\u5c5e\u4e8e2\u53f7\u7684\u6570\u636e\u4e0d\u4f1a\u663e\u793a<\/pre>\n
2. \u65e5\u671f\u548c\u5b57\u7b26\u8f6c\u6362\u51fd\u6570\u7528\u6cd5\uff08to_date,to_char\uff09<\/strong><\/div>\n
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') as nowTime from dual;  --\u7ed3\u679c\uff1a2022-01-26 13:04:53\r\nselect to_char(sysdate,'yyyy') as nowYear   from dual; --\u7ed3\u679c\uff1a2022\r\nselect to_char(sysdate,'mm')   as nowMonth  from dual; --\u7ed3\u679c\uff1a01\r\nselect to_char(sysdate,'dd')   as nowDay    from dual; --\u7ed3\u679c\uff1a26\r\nselect to_char(sysdate,'hh24') as nowHour   from dual; --\u7ed3\u679c\uff1a13\r\nselect to_char(sysdate,'mi')   as nowMinute from dual; --\u7ed3\u679c\uff1a04\r\nselect to_char(sysdate,'ss')   as nowSecond from dual; --\u7ed3\u679c\uff1a53\r\n \r\n \r\nselect to_date('2022-01-26 13:04:53','yyyy-mm-dd hh24:mi:ss')  from dual<\/pre>\n
3. \u67e5\u8be2\u67d0\u5929\u661f\u671f\u51e0<\/strong><\/div>\n
select to_char(to_date('2022-01-26','yyyy-mm-dd'),'day') from dual;   --\u7ed3\u679c\uff1a\u661f\u671f\u4e09<\/pre>\n
4. \u4e24\u4e2a\u65e5\u671f\u76f4\u63a5\u76f8\u5dee\u5929\u6570<\/strong><\/div>\n
select floor(sysdate - to_date('20220101','yyyymmdd')) from dual;<\/pre>\n
5. \u67e5\u8be2\u51fa\u4e00\u4e2a\u7a7a\u7684\u65f6\u95f4\u7c7b\u578b<\/strong><\/div>\n
select 1, TO_DATE(null) from dual;<\/pre>\n

\"\"<\/a><\/p>\n

6. \u7528\u4e8e\u8ba1\u7b97date1\u548cdate2\u4e4b\u95f4\u6709\u51e0\u4e2a\u6708<\/strong><\/div>\n
select months_between(to_date('12-31-2021','MM-DD-YYYY'),to_date('01-31-2021','MM-DD-YYYY')) \"MONTHS\" FROM DUAL; --\u7ed3\u679c\uff1a11<\/pre>\n
7. \u6307\u5b9a\u65f6\u95f4\u7684\u4e0b\u4e00\u4e2a\u661f\u671f\u51e0\uff08\u7531char\u6307\u5b9a\uff09\u6240\u5728\u7684\u65e5\u671f\uff0c<\/strong><\/div>\n
NEXT_DAY(date,char) \r\n \r\nselect   next_day(sysdate,2) from dual;  --\u5f53\u524d\u65f6\u95f4\u7684\u4e0b\u4e00\u4e2a\u5468\u4e00\r\n--1\u8868\u793a\u661f\u671f\u65e5\uff0c2\u4ee3\u8868\u661f\u671f\u4e00<\/pre>\n
8. \u83b7\u53d6\u4eca\u5e74\u7684\u5929\u6570<\/strong><\/div>\n
select add_months(trunc(sysdate,'year'), 12) - trunc(sysdate,'year') from dual;\r\n --\u95f0\u5e74\u7684\u5904\u7406\u65b9\u6cd5     \r\nto_char( last_day( to_date('02'|| :year,'mmyyyy') ), 'dd')     \r\n --\u5982\u679c\u662f28\u5c31\u4e0d\u662f\u95f0\u5e74<\/pre>\n
9. \u83b7\u53d6\u5f53\u524d\u65f6\u95f4\u662f\u4eca\u5e74\u7684\u7b2c\u591a\u5c11\u5929<\/strong><\/div>\n
select TO_CHAR(SYSDATE,'DDD'),sysdate from dual;<\/pre>\n

trunc[\u622a\u65ad\u5230\u6700\u63a5\u8fd1\u7684\u65e5\u671f,\u5355\u4f4d\u4e3a\u5929] ,\u8fd4\u56de\u7684\u662f\u65e5\u671f\u7c7b\u578b<\/p>\n

select sysdate S1,                    \r\n    trunc(sysdate) S2,                 \/\/\u8fd4\u56de\u5f53\u524d\u65e5\u671f,\u65e0\u65f6\u5206\u79d2\r\n    trunc(sysdate,'year') YEAR,        \/\/\u8fd4\u56de\u5f53\u524d\u5e74\u76841\u67081\u65e5,\u65e0\u65f6\u5206\u79d2\r\n    trunc(sysdate,'month') MONTH ,     \/\/\u8fd4\u56de\u5f53\u524d\u6708\u76841\u65e5,\u65e0\u65f6\u5206\u79d2\r\n    trunc(sysdate,'day') DAY           \/\/\u8fd4\u56de\u5f53\u524d\u661f\u671f\u7684\u661f\u671f\u5929,\u65e0\u65f6\u5206\u79d2\r\n  from dual<\/pre>\n
10. \u8fd4\u56de\u65e5\u671f\u5217\u8868\u4e2d\u6700\u665a\u65e5\u671f<\/strong><\/div>\n
select greatest('2021-01-04','2022-01-04','2019-02-04') from dual;  --\u7ed3\u679c\uff1a2022-01-04<\/pre>\n
11. \u8ba1\u7b97\u65f6\u95f4\u5dee<\/strong><\/div>\n
select floor(to_number(sysdate-to_date('2020-11-02 15:55:03','yyyy-mm-dd hh24:mi:ss'))\/365) as spanYears from dual        \/\/\u65f6\u95f4\u5dee-\u5e74\r\nselect ceil(months_between(sysdate,to_date('2020-11-02 15:55:03','yyyy-mm-dd hh24:mi:ss'))) as spanMonths from dual        \/\/\u65f6\u95f4\u5dee-\u6708\r\nselect floor(to_number(sysdate-to_date('2020-11-02 15:55:03','yyyy-mm-dd hh24:mi:ss'))) as spanDays from dual             \/\/\u65f6\u95f4\u5dee-\u5929\r\nselect floor(to_number(sysdate-to_date('2020-11-02 15:55:03','yyyy-mm-dd hh24:mi:ss'))*24) as spanHours from dual         \/\/\u65f6\u95f4\u5dee-\u65f6\r\nselect floor(to_number(sysdate-to_date('2020-11-02 15:55:03','yyyy-mm-dd hh24:mi:ss'))*24*60) as spanMinutes from dual    \/\/\u65f6\u95f4\u5dee-\u5206\r\nselect floor(to_number(sysdate-to_date('2020-11-02 15:55:03','yyyy-mm-dd hh24:mi:ss'))*24*60*60) as spanSeconds from dual \/\/\u65f6\u95f4\u5dee-\u79d2<\/pre>\n
12. \u67e5\u627e\u6708\u7684\u7b2c\u4e00\u5929,\u6700\u540e\u4e00\u5929<\/strong><\/div>\n
SELECT Trunc(Trunc(SYSDATE, 'MONTH') - 1, 'MONTH') First_Day_Last_Month,  --\u6700\u540e\u4e00\u6708\u6700\u540e\u4e00\u5929\r\n      Trunc(SYSDATE, 'MONTH') - 1 \/ 86400 Last_Day_Last_Month,            --\u6700\u540e\u4e00\u6708\u6700\u540e\u4e00\u5929\r\n      Trunc(SYSDATE, 'MONTH') First_Day_Cur_Month,                        --\u5f53\u524d\u6708\u7b2c\u4e00\u5929\r\n      LAST_DAY(Trunc(SYSDATE, 'MONTH')) + 1 - 1 \/ 86400 Last_Day_Cur_Month --\u5f53\u524d\u6708\u6700\u540e\u4e00\u5929\r\n  FROM dual;<\/pre>\n
13. \u67e5\u8be2\u65f6\u95f4\u4e4b\u524d\u7684\u65f6\u95f4\uff08\u67e5\u4e4b\u540e\u628a\u51cf\u53f7\u6362\u6210\u52a0\u53f7\uff09<\/strong><\/div>\n
\u5f53\u524d\u65f6\u95f4\u51cf\u53bb7\u5206\u949f\u7684\u65f6\u95f4\r\nselect sysdate,sysdate - interval '7' MINUTE from dual\r\n \r\n\u5f53\u524d\u65f6\u95f4\u51cf\u53bb7\u5c0f\u65f6\u7684\u65f6\u95f4\r\nselect sysdate - interval '7' hour from dual\r\n \r\n\u5f53\u524d\u65f6\u95f4\u51cf\u53bb7\u5929\u7684\u65f6\u95f4\r\nselect sysdate - interval '7' day from dual\r\n \r\n\u5f53\u524d\u65f6\u95f4\u51cf\u53bb7\u6708\u7684\u65f6\u95f4\r\nselect sysdate,sysdate - interval '7' month from dual\r\n \r\n\u5f53\u524d\u65f6\u95f4\u51cf\u53bb7\u5e74\u7684\u65f6\u95f4\r\nselect sysdate,sysdate - interval '7' year from dual\r\n \r\n\u65f6\u95f4\u95f4\u9694\u4e58\u4ee5\u4e00\u4e2a\u6570\u5b57\uff08\u4e5f\u5c31\u662f8\u4e2a\u5c0f\u65f6*2\u500d\uff0c16\u4e2a\u5c0f\u65f6\u4e4b\u524d\u7684\u6570\u636e\uff09\r\nselect sysdate,sysdate - 8 *interval '2' hour from dual\r\n \r\n  \r\n\u83b7\u53d6\u4e03\u5929\u4e4b\u540e\u7684\u65f6\u95f4\r\nselect (sysdate + 7) from dual;\r\n \r\n\u83b7\u53d6\u524d\u4e00\u4e2a\u6708\u7684\u65f6\u95f4\uff08\u6b63\u6570\u65f6\u662f\u52a0\u6708\uff0c\u8d1f\u6570\u65f6\u4e3a\u51cf\u6708\uff09\r\nselect add_months(sysdate,-1) from dual;\r\n \r\nselect sysdate+1 from dual \u52a0\u4e00\u5929\r\nselect sysdate+1\/24 from dual \u52a01\u5c0f\u65f6\r\nselect sysdate+1\/(24*60) from dual \u52a01\u5206\u949f\r\nselect sysdate+1\/(24*60*60) from dual \u52a01\u79d2\u949f<\/pre>\n

\u5230\u6b64\u8fd9\u7bc7\u5173\u4e8eOracle\u6839\u636e\u65f6\u95f4\u67e5\u8be2\u7684\u6587\u7ae0\u5c31\u4ecb\u7ecd\u5230\u8fd9\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"

\u67e5\u8be22021-01-01 \u81f3 2021-01- 02 \u7684\u6570\u636e SELECT * FROM t_table1 t […]<\/p>\n","protected":false},"author":1482,"featured_media":49103,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-251354","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/251354","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1482"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=251354"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/251354\/revisions"}],"predecessor-version":[{"id":251360,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/251354\/revisions\/251360"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/49103"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=251354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=251354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=251354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}