cursor in query and generate hierarchical xml
================================================
CREATE TABLE table_1 (countryid VARCHAR2(10),country VARCHAR2(20));
INSERT INTO table_1
VALUES ('100', 'Bangladesh');
INSERT INTO table_1
VALUES ('200', 'India');
INSERT INTO table_1
VALUES ('300', 'Pakistan');
COMMIT ;
CREATE TABLE table_2 (cityid VARCHAR2(10),city VARCHAR2(20),countryid VARCHAR2(10));
INSERT INTO table_2
VALUES ('10', 'Dhaka', '100');
INSERT INTO table_2
VALUES ('20', 'Sylhet', '100');
INSERT INTO table_2
VALUES ('30', 'Rajshahi', '100');
INSERT INTO table_2
VALUES ('10', 'Kolkata', '200');
INSERT INTO table_2
VALUES ('20', 'Mumbai', '200');
INSERT INTO table_2
VALUES ('30', 'Rajastan', '200');
COMMIT ;
----Query
SELECT countryid, country,
CURSOR (SELECT cityid, city
FROM table_2 t1
WHERE t1.countryid = t2.countryid) AS cityname
FROM table_1 t2
-----generate an xml file with hierarchical
select DBMS_XMLquery.GetXML('SELECT COUNTRYID, COUNTRY,
CURSOR (SELECT CITYID, CITY
FROM TABLE_2 T1
WHERE T1.COUNTRYID = T2.COUNTRYID) AS CITYNAME
FROM TABLE_1 T2',2) dd from dual;
Halim, a Georgia Tech graduate Senior Database Engineer/Data Architect based in Atlanta, USA, is an Oracle OCP DBA and Developer, Certified Cloud Architect Professional, and OCI Autonomous Database Specialist. With extensive expertise in database design, configuration, tuning, capacity planning, RAC, DG, scripting, Python, APEX, and PL/SQL, he combines technical mastery with a passion for innovation. Notably, Halim secured 16th place worldwide in PL/SQL Challenge Cup Playoff on the year 2010.
Saturday, September 12, 2009
Subscribe to:
Post Comments (Atom)
My Blog List
-
-
-
ASSM states3 weeks ago
-
UKOUG Discover 20241 month ago
-
-
-
-
-
-
-
-
Moving Sideways8 years ago
-
-
Upcoming Events...11 years ago
-
No comments:
Post a Comment