文章詳情頁
Oracle如何獲取數(shù)據(jù)庫系統(tǒng)的當(dāng)前時(shí)間
瀏覽:29日期:2023-03-12 15:25:36
目錄
- Oracle獲取數(shù)據(jù)庫系統(tǒng)的當(dāng)前時(shí)間
- 更新當(dāng)前時(shí)間
- 查詢當(dāng)前時(shí)間
- Oracle數(shù)據(jù)庫 獲取當(dāng)前年月份
- 總結(jié)
Oracle獲取數(shù)據(jù)庫系統(tǒng)的當(dāng)前時(shí)間
MySQL 中我們可以通過 NOW() 函數(shù)來獲取系統(tǒng)的當(dāng)前時(shí)間。
但在 Oracle 中并沒有 NOW() 函數(shù),相應(yīng)的,我們需要使用 SYSDATE 函數(shù)來獲取 Oracle 數(shù)據(jù)庫所在系統(tǒng)的當(dāng)前時(shí)間。
更新當(dāng)前時(shí)間
利用 SYSDATE 內(nèi)置函數(shù),我們可以很方便地更新當(dāng)前時(shí)間的字段值:
UPDATE MY_TABLE ?SET MODIFY_TIME = SYSDATE ?WHERE DELETED = 0 ? ?AND ID = "XXX"
查詢當(dāng)前時(shí)間
在 MySQL 中,我們可以通過以下語句直接獲取當(dāng)前時(shí)間:
SELECT NOW()
但在 Oracle 中,F(xiàn)ROM 關(guān)鍵字是必不可少的:
SELECT SYSDATE FROM DUAL
Oracle數(shù)據(jù)庫 獲取當(dāng)前年月份
1、oracle中extract()函數(shù)從oracle 9i中引入,用于從一個(gè)date或者interval類型中截取到特定的部分
select extract(year from sysdate) from dual; --當(dāng)前年? select extract(month from sysdate) from dual; --本年到當(dāng)月的月數(shù)? select extract(day from sysdate) from dual; --本月到當(dāng)日的天數(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里獲取一個(gè)時(shí)間的年、季、月、周、日的函數(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周?
- 當(dāng)前時(shí)間減去7分鐘的時(shí)間
select sysdate,sysdate - interval "7" MINUTE from dual;
- 當(dāng)前時(shí)間減去7小時(shí)的時(shí)間
select sysdate - interval "7" hour from dual;
- 當(dāng)前時(shí)間減去7天的時(shí)間
select sysdate - interval "7" day from dual;
- 當(dāng)前時(shí)間減去7月的時(shí)間
select sysdate,sysdate - interval "7" month from dual;
- 當(dāng)前時(shí)間減去7年的時(shí)間
select sysdate,sysdate - interval "7" year from dual;
- 時(shí)間間隔乘以一個(gè)數(shù)字
select sysdate,sysdate - 8*interval "7" hour from dual;
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持。
標(biāo)簽:
Oracle
相關(guān)文章:
1. 教你快速掌握Oracle數(shù)據(jù)庫結(jié)構(gòu)的16個(gè)要點(diǎn)2. Oracle數(shù)據(jù)庫備份與恢復(fù)之完全攻略3. 淺談創(chuàng)建Oracle數(shù)據(jù)庫連接的兩種方法4. Oracle數(shù)據(jù)庫對(duì)象的使用詳解5. 關(guān)于Oracle數(shù)據(jù)庫中的鎖機(jī)制深入研究6. 快速掌握Oracle數(shù)據(jù)庫游標(biāo)的使用方法7. 講解Oracle數(shù)據(jù)庫逐漸增大時(shí)的歸檔處理8. 初學(xué)者必讀:Oracle數(shù)據(jù)庫安裝錯(cuò)誤集錦9. ORACLE數(shù)據(jù)庫對(duì)象與用戶管理10. Oracle數(shù)據(jù)庫編寫有效事務(wù)指導(dǎo)方針
排行榜
