|
| Re: How to make input parameters as optional in the function definition |
 |
Mon, 28 Apr 2008 10:46:53 -070 |
You want to be a little bit careful here. Behavior between DSP 2.5 and 3.x is
different - and there is a bug in 3.x where it will silently not execute SQL
when a passed parameter is null - so you could get incorrect results unless you
are careful.
For DSP 3.x :
You will need to use code like this - notice that it uses an intermediate
variable ($ARG0), and that when the argument is empty, it assigns some dummy
value to it. (and of course if your arg is an integer, it will need to be a
dummy integer value, when it is a date, you'll need to use a dummy date value).
declare function f1:getCustomerByLastName($arg0 as xs:string?) as
element(f1:CUSTOMER)*{
let $ARG0:= if(empty($arg0)) then "dummy" else $arg0
for $CUSTOMER in f1:CUSTOMER()
where ($ARG0 eq $CUSTOMER/LAST_NAME or ($ARG0 eq "dummy") treat as
xs:boolean)
return
$CUSTOMER
};
Please check the query plan to ensure that both conditions are pushed to th |
| Post Reply
|
|
|
|
|
|
|
|
|
|