oracle - PL SQL xmlelement: How to get data in xml from mutually exclusive condition on same tables -
i fetching data database using xml . here tables:
settings table:
class code name 'm1' 1 food1 'm1' 2 food2 'p1' 1 payincash 'p2' 2 payonline customer table: customer_id food_name payment_method cus123 1 1 cus123 2 2
as can see, have used internal codes map detail
i want write query give following output:
query output: customer_id food_name payment_method cus123 food1 payincash cus123 food2 payonline
i want retrieve data in xml format,that's why using xmlelement.
select xmlelement("customer_records", xmlagg( xmlelement("record", xmlelement("cus_id", customer_id), xmlelement("food", food_name), xmlelement("payment", payment_method) ) ) ) customer customer_id = 'cus123';
you can see can't join because of because conditions. please help.
try dependent subqueries, in way:
select customer_id, ( select name settings s class 'm%' , s.code = c.food_name ) food_name, ( select name settings s class 'p%' , s.code = c.payment_method ) payment_method customer c;
example using xmlagg:
select xmlelement("customer_records", xmlagg( xmlelement("record", xmlelement("cus_id", customer_id), xmlelement("food", food_name), xmlelement("payment", payment_method) ) ) ) ( select customer_id, ( select name settings s class 'm%' , s.code = c.food_name ) food_name, ( select name settings s class 'p%' , s.code = c.payment_method ) payment_method customer c );
result:
<customer_records> <record> <cus_id>cus123</cus_id> <food>food1</food> <payment>payincash</payment> </record> <record> <cus_id>cus123</cus_id> <food>food2</food> <payment>payonline</payment> </record> </customer_records>
Comments
Post a Comment