How to do Decode in Xquery
543512Nov 24 2006 — edited Dec 1 2006I’m trying to implement the PL/SQL query using XQuery, both of which are given below.
However, I need help for the following two cases:
1) How to implement the decode step?
2) How to compare for the date values?
PL/SQL
select a.id, a.year, a.crop, b.trans_date,
decode (b.name, 'Account_ID', 'A', 'Company_ID','C') as entity
from crops a, crops_audit b
where a.id = b.id and
a.year = b.year and
a.crop = b.crop and
b.trans_date >= date_variable
XQuery
SELECT XMLQuery('<Insert>
{for $a in ora:view("CROPS"),
$b in ora:view("CROPS_AUDIT")
let $a_id := $a/ROW/ID/text(),
$a_year := $a/ROW/YEAR/text(),
$a_crop := $a/ROW/CROP/text(),
$b_id := $b/ROW/ID/text(),
$b_year := $b/ROW/YEAR/text(),
$b_crop := $b/ROW/CROP/text(),
$b_trans_date := $b/ROW/TRANS_DATE/text(),
$b_type := $b/ROW/TYPE/text()
where $a_id = $b_id and
$a_year = $b_year and
$a_crop = $b_crop and
$b_trans_date >= xs:date(date_variable)
return
whatever xml needs to be generated
}</Insert>' RETURNING CONTENT)
FROM dual;