Oracle

oracle如何修改預設日期格式

  • June 14, 2019

這裡是 Oracle 的新手,我正在處理一些任務,但我注意到當我使用腳本創建表時,oracle 拋出以下錯誤:

ORA-01858: a non-numeric character was found where a numeric was expected
01858. 00000 -  "a non-numeric character was found where a numeric was expected"
*Cause:    The input data to be converted using a date format model was
      incorrect.  The input data did not contain a number where a number was
      required by the format model.
*Action:   Fix the input data or the date format model to make sure the
      elements match in number and type.  Then retry the operation.

知道我查詢中的日期格式類似於 ‘01-JUN-2012’ 我想知道如何更改我的 oracle 安裝中的預設格式以滿足我的系統格式?我正在使用帶有免費 Oracle 版本 11g 的 SQL Developer。

我也想知道這是否是因為我的電腦是 WIN 7 法語版本,而我查詢中的日期是英文美國格式?

UPDATE bb_product
  set salestart = '01-JUN-2012', saleend = '15-JUN-2012', SalePrice = 8.00
  WHERE idProduct = 6;

這個查詢來自我的教授分發的 Brewer Beans DB。我假設是在使用 EN-US 格式的系統中創建的……有什麼幫助嗎?

你可以試試 ALTER SESSION

ALTER SESSION SET NLS_DATE_FORMAT = '[date_format]';

日期格式

MM  Numeric month (e.g., 07)
MON     Abbreviated month name (e.g., JUL)
MONTH   Full month name (e.g., JULY)
DD  Day of month (e.g., 24)
DY  Abbreviated name of day (e.g., FRI)
YYYY    4-digit year (e.g., 1998)
YY  Last 2 digits of the year (e.g., 98)
RR  Like YY, but the two digits are ``rounded'' to a year in the range 1950 to 2049. Thus, 06 is considered 2006 instead of 1906
AM (or PM)  Meridian indicator
HH  Hour of day (1-12)
HH24    Hour of day (0-23)
MI  Minute (0-59)
SS  Second (0-59)

TO_CHAR(datum_column, date_format) 是避免頭疼的最佳方法檢查 Justin Cave 的答案

引用自:https://dba.stackexchange.com/questions/57816