OpenQuery将yyyymmdd转换为MM / DD / YYYY

时间:2019-03-07 15:43:25

标签: oracle ssms openquery

我尝试过

FROM OPENQUERY(TESTsvr, 
Select to_date(CREATE_DT, "MM/DD/YYYY") as Testing
From Test.ViewTest

FROM OPENQUERY(TESTsvr, 
to_char(CREATE_DT, "mm/dd/yyyy hh24:mi:ss") as Testing
From Test.ViewTest

但是当我执行它时,它说出无效的标识符。

1 个答案:

答案 0 :(得分:1)

尝试使用引号: 如果要将日期转换为char:

  FROM OPENQUERY(TESTsvr, 
'select to_char(CREATE_DT, ''mm/dd/yyyy hh24:mi:ss'') as Testing From Test.ViewTest')

如果要将char转换为日期:

  FROM OPENQUERY(TESTsvr, 
'select to_date(CREATE_DT, ''mm/dd/yyyy'') as Testing From Test.ViewTest')

如果要将NUMBER(8)转换为日期(如yyyymmdd):

  FROM OPENQUERY(TESTsvr, 
'select to_date(CREATE_DT, ''yyyymmdd'') as Testing From Test.ViewTest')