Oracle、Db2、SqlServer、MySQL 資料庫插入當前系統時間

來源:互聯網
上載者:User

標籤:

做易買網項目,由於對資料庫插入系統時間不瞭解,常常遇到的問題:

1、java.sql.SQLException: ORA-01861: 文字與格式字串不匹配、
原因:由於擷取系統時間類型不對,應為systdate

下面介紹Oracle、Db2、SqlServer、MySQL 資料庫插入當前系統時間

例如有表table,table 中有兩個欄位:name 、makedate
1.oracle:
插入系統時間應為sysdate:
insert into table (name,makedate) values(‘測試‘,sysdate);
2.Db2:
插入系統時間應為current timestamp並且makedate資料類型為timestamp
insert into table (name,makedate) values(‘測試‘,current timestamp);
3.SqlServer:
插入系統時間應為GETDATE()
insert into table (name,makedate) values(‘測試‘,GETDATE());
4.MySQL:
插入系統時間應:
now():以‘yyyy-mm-dd hh:mm:ss‘返回當前的日期時間,可以直接存到datetime欄位中。
curdate():’yyyy-mm-dd’的格式返回今天的日期,可以直接存到date欄位中。
insert into table (name,makedate) values(‘測試‘,now());

Oracle、Db2、SqlServer、MySQL 資料庫插入當前系統時間

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.