2015-02-23 17 views
0

我有一個日期格式爲'12 -FEB-2014'我需要將其轉換爲'yyyy-mm-dd'格式。我嘗試這樣做:解析日期字符串

xdmp:parse-dateTime("[D01]-[MN,*-3]-[Y0001]","12-FEB-2014") 

但它拋出一個異常:

XDMP-PATTERNVALUEMISMATCH: Given value doesn't match with the specified pattern 
for parsing dateTime string 

回答

3

它看起來像你有你將不得不作出自己的轉換函數的月份。下面的代碼應該給你一個開始。它會消除你給我們的例子。

declare function local:month-name-to-int 
    ($stringIN as xs:string?) as xs:string? { 
    switch (fn:lower-case($stringIN)) 
    case "jan" return "01" 
    case "feb" return "02" 
    case "mar" return "03" 
    case "apr" return "04" 
    case "may" return "05" 
    case "jun" return "06" 
    case "jul" return "07" 
    case "aug" return "08" 
    case "sep" return "09" 
    case "oct" return "10" 
    case "nov" return "11" 
    case "dec" return "12" 
    default return fn:error(xs:QName("ERROR"), "unknown month") 
} ; 

let $string := "12-FEb-2014" 
let $stringTokened := fn:tokenize($string, "-") 
return xs:date($stringTokened[3] || "-"||local:month-name-to-int($stringTokened[2]) || "-" || $stringTokened[1]) 
+1

現在函數xdmp:解析-日期時間( 「[D01] - [MN,* - 3] - [Y0001]」, 「12-FEB-2014」)似乎GUD一起工作 – LSB 2016-06-28 10:22:01