文章詳情頁
Oracle如何獲取數(shù)據(jù)庫系統(tǒng)的當前時間
瀏覽:36日期:2023-03-12 15:25:36
目錄
- Oracle獲取數(shù)據(jù)庫系統(tǒng)的當前時間
- 更新當前時間
- 查詢當前時間
- Oracle數(shù)據(jù)庫 獲取當前年月份
- 總結
Oracle獲取數(shù)據(jù)庫系統(tǒng)的當前時間
MySQL 中我們可以通過 NOW() 函數(shù)來獲取系統(tǒng)的當前時間。
但在 Oracle 中并沒有 NOW() 函數(shù),相應的,我們需要使用 SYSDATE 函數(shù)來獲取 Oracle 數(shù)據(jù)庫所在系統(tǒng)的當前時間。
更新當前時間
利用 SYSDATE 內置函數(shù),我們可以很方便地更新當前時間的字段值:
UPDATE MY_TABLE ?SET MODIFY_TIME = SYSDATE ?WHERE DELETED = 0 ? ?AND ID = "XXX"
查詢當前時間
在 MySQL 中,我們可以通過以下語句直接獲取當前時間:
SELECT NOW()
但在 Oracle 中,F(xiàn)ROM 關鍵字是必不可少的:
SELECT SYSDATE FROM DUAL
Oracle數(shù)據(jù)庫 獲取當前年月份
1、oracle中extract()函數(shù)從oracle 9i中引入,用于從一個date或者interval類型中截取到特定的部分
select extract(year from sysdate) from dual; --當前年? select extract(month from sysdate) from dual; --本年到當月的月數(shù)? select extract(day from sysdate) from dual; --本月到當日的天數(shù)? select extract(year from date"2011-05-17") year from dual;? select extract(month from date"2011-05-17") month from dual;? select extract(day from date"2011-05-17") day from dual;?
2、ORACLE里獲取一個時間的年、季、月、周、日的函數(shù)
select ?to_char(sysdate, "yyyy" ) ?from dual; --年? ? ? select ?to_char(sysdate, "MM" ) ?from dual; --月? select ?to_char(sysdate, "dd" ) ?from dual; --日? select ?to_char(sysdate,"Q") ?from dual; --季? select ?to_char(sysdate,"iw") ?from dual; --周--按日歷上的那種,每年有52或者53周?
- 當前時間減去7分鐘的時間
select sysdate,sysdate - interval "7" MINUTE from dual;
- 當前時間減去7小時的時間
select sysdate - interval "7" hour from dual;
- 當前時間減去7天的時間
select sysdate - interval "7" day from dual;
- 當前時間減去7月的時間
select sysdate,sysdate - interval "7" month from dual;
- 當前時間減去7年的時間
select sysdate,sysdate - interval "7" year from dual;
- 時間間隔乘以一個數(shù)字
select sysdate,sysdate - 8*interval "7" hour from dual;
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持。
標簽:
Oracle
相關文章:
1. Oracle數(shù)據(jù)庫與用戶角色權限相關的視圖2. Oracle數(shù)據(jù)庫中分區(qū)表的操作方法詳解3. 史上最簡單的方法復制或遷移Oracle數(shù)據(jù)庫4. Oracle數(shù)據(jù)庫19C的安裝與配置指南(2022年最新版)5. 保“庫”之路:Oracle數(shù)據(jù)庫性能保護6. 在Oracle數(shù)據(jù)庫中處理數(shù)據(jù)的高并發(fā)響應7. Oracle數(shù)據(jù)庫在網格計算中的應用8. Oracle數(shù)據(jù)庫軟件包遠程溢出漏洞9. 提綱挈領Oracle數(shù)據(jù)庫災難防護技術10. 關于Oracle數(shù)據(jù)庫的性能優(yōu)化心得
排行榜

網公網安備