BEGIN IF(DBMS_XDB.CREATEFOLDER('/public/employees')) THEN DBMS_OUTPUT.PUT_LINE('Folder is created'); ELSE DBMS_OUTPUT.PUT_LINE('Cannot create folder'); END IF; COMMIT; END; /DECLARE XMLdoc XMLType; BEGIN SELECT XMLQuery( 'for $j in 1 return ( { for $i in ora:view("HR", "employees")/ROW where $i/EMPLOYEE_ID <= 102 return ( {xs:string($i/EMPLOYEE_ID)} {xs:string($i/LAST_NAME)} {xs:integer($i/SALARY)} )} )' RETURNING CONTENT) INTO XMLdoc FROM DUAL; IF(DBMS_XDB.CREATERESOURCE('/public/employees/employees.xml', XMLdoc)) THEN DBMS_OUTPUT.PUT_LINE('Resource is created'); ELSE DBMS_OUTPUT.PUT_LINE('Cannot create resource'); END IF; COMMIT; END; / |
SELECT XMLQuery('for $i in fn:doc("/public/employees/employees.xml") return; $i' RETURNING CONTENT) AS RESULT FROM DUAL; |
SELECT ttab.COLUMN_VALUE AS OrderTotal FROM purchaseorder, XMLTable( 'for $i in /PurchaseOrder where $i/User = "EABEL" return; {$i/Reference} {fn:sum(for $j in $i/LineItems/LineItem/Part return ($j/@Quantity*$j/@UnitPRice))} PASSING OBJECT_VALUE ) ttab; |
ORDERTOTAL ------------------------------------------------------------- |
SELECT XMLQuery('for $i in /PurchaseOrder where $i/User eq "EABEL" return {$i/Reference} {fn:sum(for $j in $i/LineItems/LineItem/Part return ($j/@Quantity*$j/@UnitPrice))} PASSING OBJECT_VALUE RETURNING CONTENT) FROM purchaseorder; |
SELECT XMLQuery('for $i in /PurchaseOrder return {$i/Reference} {fn:sum(for $j in $i/LineItems/LineItem/Part return ($j/@Quantity*$j/@UnitPrice))} PASSING OBJECT_VALUE RETURNING CONTENT) AS ordertotal FROM purchaseorder WHERE existsNode(OBJECT_VALUE, '/PurchaseOrder[User = "EABEL"]') = 1; |
DECLARE XMLdoc XMLType; BEGIN SELECT XMLQuery( 'for $j in ora:view("SCOTT", "dept")/ROW where $j/DEPTNO = 10 return ( {$j/DEPTNO, $j/DNAME} for $i in ora:view("SCOTT", "emp")/ROW where $i/DEPTNO = $j/DEPTNO return ( {$i/EMPNO, $i/ENAME, $i/SAL} RETURNING CONTENT) INTO XMLdoc FROM DUAL; IF(DBMS_XDB.CREATERESOURCE('/public/employees/acc_dept.xml', XMLdoc)) THEN DBMS_OUTPUT.PUT_LINE('Resource is created'); ELSE DBMS_OUTPUT.PUT_LINE('Cannot create resource'); END IF; COMMIT; END; / |
SELECT XMLQuery( 'for $i in fn:collection("/public/employees")//EMPLOYEE where $i/SAL >= 5000 order by $i/ENAME return; $i' RETURNING CONTENT) FROM DUAL; |
SELECT emps.empno,emps.ename, emps.sal FROM XMLTable( 'for $i in fn:collection("/public/employees")//EMPLOYEE where $i/SAL >= 5000 return; $i' COLUMNS empno NUMBER PATH '/EMPLOYEE/EMPNO', ename VARCHAR2(30) PATH '/EMPLOYEE/ENAME', sal NUMBER PATH '/EMPLOYEE/SAL') emps; |
EMPNO ENAME SAL ----- -------------- ---------- 7839 KING 5000 100 King 24000 101 Kochhar 17000 102 De Haan 17000 |
SELECT XMLQuery( 'for $k in 1 return ( $j in $emps/EMPLOYEES/EMPLOYEE where $i/EMPLOYEE_ID = $j/EMPNO return ( PASSING xmlparse (document httpuritype ('http://localhost/employees/empsbonus.xml').getCLOB()) as "emps" RETURNING CONTENT).getStringVal() as RESULT FROM DUAL; |
SET AUTOTRACE ON EXPLAIN SELECT count(*) FROM oe.purchaseorder, XMLTable( 'for $i in /PurchaseOrder/User where $i = "CJOHNSON" return $i' PASSING OBJECT_VALUE) ptab; |
COUNT(*) ---------- 9Execution Plan ---------------------------------------------------- Plan hash value: 4046110317---------------------------------------------------------------------------------------- Id Operation Name Rows Bytes Cost (%CPU) Time ---------------------------------------------------------------------------------------- 0 SELECT STATEMENT 1 226 29 (0) 00:00:01 1 SORT AGGREGATE 1 226 2 NESTED LOOPS 10782 2379K 29 (0) 00:00:01 * 3 TABLE access FULL PURCHASEORDER 1 226 5 (0) 00:00:01 4 COLLECTION ITERATOR P XMLSEQUENCEFROMX Predicate Information (identified by operation id): ---------------------------------------------------3 - filter(SYS_CHECKACL("ACLOID","OWNERID",xmltype('... |
SELECT count(*) FROM oe.purchaseorder, XMLTable( 'for $i in /PurchaseOrder where $i/User = "CJOHNSON" return $i/User' PASSING OBJECT_VALUE) ptab;这次,输出应如下所示: COUNT(*) ---------- 9 Execution Plan --------------------------------------------------- Plan hash value: 3411896580---------------------------------------------------------------------------------------- Id Operation Name Rows Bytes Cost (%CPU) Time ---------------------------------------------------------------------------------------- 0 SELECT STATEMENT 1 29 7 (0) 00:00:01 1 SORT AGGREGATE 1 29 2 NESTED LOOPS 1 29 7 (0) 00:00:01 3 FAST DUAL 1 2 (0) 00:00:01 * 4 TABLE ACCESS FULL PURCHASEORDER 1 29 5 (0) 00:00:01 Predicate Information (identified by operation id): ---------------------------------------------------4 - filter("PURCHASEORDER"."SYS_NC00022$"='CJOHNSON' AND SYS_CHECKACL("ACLOID","OWNERID",xmltype('... |
//File:BindVars.php $user = 'hr'; $pswd = 'hr'; $db ='(DESCRipTION= (ADDRESS_LIST= (ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)) ) (CONNECT_DATA=(SID=orclR2)(SERVER=DEDICATED)) )'; $empno=100; $conn = oci_connect($user, $pswd, $db); $sql = 'SELECT XMLQuery('."'".'for $i in ora:view("employees")/ROW where $i/EMPLOYEE_ID = $empno return ( {$i/EMPLOYEE_ID, $i/EMAIL, $i/JOB_ID} RETURNING CONTENT).GetStringVal() AS RESULT FROM DUAL'; $query = oci_parse($conn, $sql); oci_bind_by_name($query, ":empno", $empno, 3); oci_execute($query); oci_fetch($query); $str = oci_result($query, 'RESULT'); print $str; ?> |
SELECT XMLTRANSFORM(OBJECT_VALUE, xdbUriType('/public/orderTotal.xsl').getXML()).GetStringVal() AS RESULT FROM purchaseorder WHERE existsNode(OBJECT_VALUE, '/PurchaseOrder[User = "EABEL"]') = 1; |
SELECT XMLQuery( 'for $i in $h//channel return; {$i/lastBuildDate} {for $j in $h//item where ora:contains($j, "PHP") return PASSING xmlparse (document httpuritype ('http://www.oracle.com/technology/syndication/rss_otn_news.xml').getCLOB()) as "h" RETURNING CONTENT).getStringVal() as RESULT FROM DUAL; |
http://www.oracle.com/technology/xe http://www.oracle.com/technology/pub/articles/oracle_php_cookbook http://www.oracle.com/technology/tech/php/zendcore/index.html |
新闻热点
疑难解答