bpel
It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs.
在Oracle BPEL中使用日期函数有时会有些棘手。 我将快速解释如何将N天添加到当前日期。 在BPEL流程中,这可能很有用,您可以对其进行调整以适合您的需求。
First of all, let's see how to add 1 day to the current date, in a XSL expression:
首先,让我们看看如何在XSL表达式中将1天添加到当前日期:
xp20:add-dayTimeDuration-to-dateTime(xp20:current-date(), 'P1D')
There are 2 functions used here. The most important part in this article is the special format 'P1D' which means "one day". So the current date is obtained with the "xp20:current-date()" and the number of days to add is defined with the '1' between the 'P' and the 'D' in the format 'P1D'.
这里使用2个功能。 本文中最重要的部分是特殊格式“ P1D”,表示“一天”。 因此,当前日期是通过“ xp20:current-date()”获得的,要添加的天数由“ P”和“ D”之间的“ 1”定义,格式为“ P1D”。
So to add N days, the format must be in the following form : 'P' + number of days + 'D'. For example, to add 40 days to the current date and to get back the new calculated date, the following command must be used :
因此,要添加N天,格式必须采用以下格式:“ P” +天数+“ D”。 例如,要将40天添加到当前日期并取回新的计算日期,必须使用以下命令:
xp20:add-dayTimeDuration-to-dateTime(xp20:current-date(), 'P40D')
Now, in an XSL expression referencing a XSL variable in which the number of days is, that would be done with something that looks like that :
现在,在一个XSL表达式中引用一个XSL变量(天数在其中),这可以通过如下方式完成:
<from expression="xp20:add-dayTimeDuration-to-dateTime(xp20:current-date(),concat('P',String(bpws:getVariableData('OnMessage_1_InputVariable','parameters','/ns1:MyParam/ns1:NumberOfDays')),'D'))"/>
Let's take the expression only :
让我们仅使用表达式:
xp20:add-dayTimeDuration-to-dateTime(xp20:current-date(),concat('P',String(bpws:getVariableData('OnMessage_1_InputVariable','parameters','/ns1:MyParam/ns1:NumberOfDays')),'D'))
This can be split visually to understand more clearly :
可以在视觉上进行拆分以更清楚地了解:
xp20:add-dayTimeDuration-to-dateTime
(
xp20:current-date(),
concat(
'P',
String(bpws:getVariableData
(
'OnMessage_1_InputVariable','parameters','/ns1:MyParam/ns1:NumberOfDays')
),
'D'
)
The BPEL concatenation function is used and enables to concatenate the 3 parts : the 'P', the number of days and the 'D'.
使用BPEL串联功能,它可以串联3个部分:“ P”,天数和“ D”。
The String function is used to convert the number of days in character format.
字符串函数用于转换字符格式的天数。
All that can be done with the BPEL Expression Builder when working on a BPEL process. A useful trick is to use CTRL+SPACE to ease the creation of an expression.
在进行BPEL流程时,可以使用BPEL Expression Builder完成所有这些操作。 一个有用的技巧是使用CTRL + SPACE简化表达式的创建。
Last evolution : Format the result date according to "dd/mm/aaaa" (european countries) :
最后演变:根据“ dd / mm / aaaa”(欧洲国家/地区)格式化结果日期:
xp20:format-dateTime(xp20:add-dayTimeDuration-to-dateTime(xp20:current-date(), concat('P',string(bpws:getVariableData('OnMessage_1_InputVariable','parameters','/ns1:MyParam/ns1:NumberOfDays')),'D')),'[D01]/[M01]/[YYYY]')
Here, the format-dateTime function is used, with the specific format '[D01]/[M01]/[YYYY]' that means days with 2 digits, months with 2 digits and year with 4 digits. :)
此处,使用格式为dateTime的函数,其特定格式为[[D01] / [M01] / [YYYY]”,表示2位数字的天,2位数字的月和4位数字的年。 :)
That's it!
而已!
bpel