熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

to

2022-06-13   來源: Oracle 

  如to_date函數中時間格式與當前時間格式相符可以不在函數中指定格式而完成隱式轉換

  select>BYS@bys>select sysdate from dual;

  SYSDATE

  

  // ::

  select>BYS@bys>select to_date(// ::) from dual;

  TO_DATE(//

  

  // ::

  當前日期格式下下面幾種格式都可以隱式轉換應該是日期間連接符使用特殊字符都沒問題但是月與日小時分鐘要能對上

  不能使用&&表示傳入變量不能使用數字或字母字符

  select>BYS@bys>select to_date( ::) from dual;

  TO_DATE(

  

  // ::

  select>BYS@bys>select to_date(# :+) from dual;

  TO_DATE(#

  

  // ::

  select>BYS@bys>select to_date(a :+) from dual;

  select to_date(a :+) from dual

  *

  ERROR at line :

  ORA: literal does not match format string

  select>BYS@bys>select to_date( :+) from dual;

  select to_date( :+) from dual

  *

  ERROR at line :

  ORA: literal does not match format string

  select>BYS@bys>select to_date(@ :+) from dual;

  TO_DATE(@

  

  // ::

  如果to_date函數中格式字段長度與系統的不符的幾種情況

  把最後的表示秒的字符省略可以正常顯示

  select>BYS@bys>select to_date(@ :) from dual;

  TO_DATE(@

  

  // ::

  把最後的表示秒的字符及表示具體幾號的字符省略報錯

  select>BYS@bys>select to_date(@ :) from dual;

  select to_date(@ :) from dual

  *

  ERROR at line :

  ORA: a nonnumeric character was found where a numeric was expected

  只給出分和秒未給出代替

  select>BYS@bys>select to_date(@ ) from dual;

  TO_DATE(@

  

  // ::

  只給出日期的字段秒用來代替

  select>BYS@bys>select to_date(@ ) from dual;

  TO_DATE(@

  

  // ::

  只給出年未給幾號報錯

  select>BYS@bys>select to_date( ) from dual;

  select to_date( ) from dual

  *

  ERROR at line :

  ORA: input value not long enough for date format

  select>BYS@bys>select to_date($ ) from dual;

  TO_DATE($

  

  // ::

  to_date函數中時間格式與當前時間格式不符需要在函數中顯式指定時間格式來完成轉換

  select>BYS@bys>select sysdate from dual;

  SYSDATE

  

  OCT

  注意列寬以免不能顯示全

  col>BYS@bys>col aa for a

  select>BYS@bys>select to_date( ::yyyymmdd hh:mi:ss) aa from dual;

  AA

  

  FEB

  不指定格式會報錯

  select>BYS@bys>select to_date( ::) from dual;

  select to_date( ::) from dual

  *

  ERROR at line :

  ORA: literal does not match format string


From:http://tw.wingwit.com/Article/program/Oracle/201311/17572.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.