Updating database tables from xml

Rated 3.87/5 based on 954 customer reviews

Example 5-22 extracts the fragments of a document that are identified by an XPath expression. The example uses XQuery Full Text to perform full-text search. These purchase orders are grouped by customer and counted. Example 5-21 tabulates the purchase orders whose shipping address contains the string "" (double L).combine that power of expression and computation with the strengths of SQL. Abel Counter to Counter SELECT reference, lineno, upc, description, quantity FROM purchaseorder_lineitem; REFERENCE LINENO UPC DESCRIPTION QUANTITY -------------------------------- ---------- -------------- ---------------------------------- ---------- EABEL-20021009123336251PDT 1 37429125526 Samurai 2: Duel at Ichijoji Temple 3 EABEL-20021009123336251PDT 2 37429128220 The Red Shoes 4 EABEL-20021009123336251PDT 3 715515009058 A Night to Remember 1 CREATE OR REPLACE PROCEDURE insert Purchase Order(purchaseorder XMLType) AS reference VARCHAR2(28); BEGIN INSERT INTO purchaseorder_table (reference, requestor, actions, userid, costcenter, shiptoname, address, phone, rejectedby, daterejected, comments, specialinstructions) SELECT * FROM XMLTable('$p/Purchase Order' PASSING purchaseorder AS "p" COLUMNS reference VARCHAR2(28) PATH 'Reference', requestor VARCHAR2(48) PATH 'Requestor', actions XMLType PATH 'Actions', userid VARCHAR2(32) PATH 'User', costcenter VARCHAR2(3) PATH 'Cost Center', shiptoname VARCHAR2(48) PATH 'Shipping Instructions/name', address VARCHAR2(512) PATH 'Shipping Instructions/address', phone VARCHAR2(32) PATH 'Shipping Instructions/telephone', rejectedby VARCHAR2(32) PATH 'Reject/User', daterejected DATE PATH 'Reject/Date', comments VARCHAR2(2048) PATH 'Reject/Comments', specialinstructions VARCHAR2(2048) PATH 'Special Instructions'); INSERT INTO purchaseorder_lineitem (reference, lineno, upc, description, quantity, unitprice) SELECT t.reference, li.lineno, li.upc, li.description, li.quantity, li.unitprice FROM XMLTable('$p/Purchase Order' PASSING purchaseorder AS "p" COLUMNS reference VARCHAR2(28) PATH 'Reference', lineitem XMLType PATH 'Line Items/Line Item') t, XMLTable('Line Item' PASSING t.lineitem COLUMNS lineno NUMBER(10) PATH '@Item Number', upc VARCHAR2(14) PATH 'Part/@Id', description VARCHAR2(128) PATH 'Description', quantity NUMBER(10) PATH 'Part/@Quantity', unitprice NUMBER(12,2) PATH 'Part/@Unit Price') li; END; SELECT reference, userid, shiptoname, specialinstructions FROM purchaseorder_table; REFERENCE USERID SHIPTONAME SPECIALINSTRUCTIONS -------------------------------- -------- ------------------------------------------------ ------------------- SBELL-2002100912333601PDT SBELL Sarah J. Smith 7 SELECT XMLCast(XMLQuery('$p/Purchase Order/Reference' PASSING po.You typically use XQuery with Oracle XML DB in the following ways. Bell Air Mail SELECT reference, lineno, upc, description, quantity FROM purchaseorder_lineitem; REFERENCE LINENO UPC DESCRIPTION QUANTITY ------------------------- ------ ------------ ---------------------------------- -------- SBELL-2002100912333601PDT 1 715515009058 A Night to Remember 2 SBELL-2002100912333601PDT 2 37429140222 The Unbearable Lightness Of Being 2 SBELL-2002100912333601PDT 3 715515011020 Sisters 4 ('$p/Purchase Order/Requestor' PASSING po. OBJECT_VALUE AS "p" RETURNING CONTENT) AS VARCHAR2(30)) reference, count(*) FROM purchaseorder po, XMLTable('$p//Line Item[Part/@Id="37429148327"]' PASSING OBJECT_VALUE AS "p") WHERE () = 1 GROUP BY XMLCast(XMLQuery('$p/Purchase Order/Reference' PASSING po.

', item VARCHAR2(4) PATH '@Item Number', description VARCHAR2(45) PATH 'Description') t WHERE item = 5; REFERENCE ITEM DESCRIPTION ------------------------------ ---- ------------------------------------ AMCEWEN-20021009123336171PDT 5 Coup De Torchon (Clean Slate) AMCEWEN-20021009123336271PDT 5 The Unbearable Lightness Of Being PTUCKER-20021009123336191PDT 5 The Scarlet Empress PTUCKER-20021009123336291PDT 5 The Unbearable Lightness Of Being SBELL-20021009123336231PDT 5 Black Narcissus SBELL-20021009123336331PDT 5 Fishing With John 1 -3 SKING-20021009123336321PDT 5 The Red Shoes SMCCAIN-20021009123336151PDT 5 Wages of Fear SMCCAIN-20021009123336341PDT 5 The Most Dangerous Game VJONES-20021009123336301PDT 5 Le Trou 10 rows selected.

DECLARE x Node XMLType; v Text VARCHAR2(256); v Reference VARCHAR2(32); CURSOR get Purchase Order(reference IN VARCHAR2) IS SELECT OBJECT_VALUE XML FROM purchaseorder WHERE XMLExists('$p/Purchase Order[Reference=$r]' PASSING OBJECT_VALUE AS "p", reference AS "r"); BEGIN v Reference := 'EABEL-20021009123335791PDT'; FOR c IN get Purchase Order(v Reference) LOOP x Node := c.

OBJECT_VALUE AS "p" RETURNING CONTENT) AS VARCHAR2(12)); REFERENCE USERID STATUS STATUS_DATE -------------------------------- -------- -------- ------------ VJONES-20020916140000000PDT SVOLLMAN Accepted 2002-10-11 SMCCAIN-2002091213000000PDT SKING Rejected 2002-10-12 2 rows selected.

CREATE TABLE purchaseorder_table (reference VARCHAR2(28) PRIMARY KEY, requestor VARCHAR2(48), actions XMLType, userid VARCHAR2(32), costcenter VARCHAR2(3), shiptoname VARCHAR2(48), address VARCHAR2(512), phone VARCHAR2(32), rejectedby VARCHAR2(32), daterejected DATE, comments VARCHAR2(2048), specialinstructions VARCHAR2(2048)); CREATE TABLE purchaseorder_lineitem (reference, FOREIGN KEY ("REFERENCE") REFERENCES "PURCHASEORDER_TABLE" ("REFERENCE") ON DELETE CASCADE, lineno NUMBER(10), PRIMARY KEY ("REFERENCE", "LINENO"), upc VARCHAR2(14), description VARCHAR2(128), quantity NUMBER(10), unitprice NUMBER(12,2)); INSERT INTO purchaseorder_table (reference, requestor, actions, userid, costcenter, shiptoname, address, phone, rejectedby, daterejected, comments, specialinstructions) SELECT t.reference, t.requestor, t.actions, t.userid, t.costcenter, t.shiptoname, t.address, t.phone, t.rejectedby, t.daterejected, t.comments, t.specialinstructions FROM purchaseorder p, XMLTable('/Purchase Order' PASSING p.

Abel The Description of Line Item[1] for Reference PTUCKER-20021009123335430PDT is Picnic at Hanging Rock PL/SQL procedure successfully completed.

Leave a Reply