Oracle8i Application Developer's Guide - XML Release 3 (8.1.7) Part Number A86030-01 |
|
Using XML-SQL Utility (XSU), 20 of 26
The PL/SQL API provides the ability to bind values to the SQL statement. The SQL statement can contain named bind variables. The variables have to start with a ':' in front of them to signal that they are bind variables. The steps involved in using the bind variable is as follows,
queryCtx = DBMS_XMLQuery.getCtx('select * from emp where empno = :EMPNO and ename = :ENAME');
clearBindValues
() clears all the bind variables set. The setBindValue
() sets a single bind variable with a string value. For example, we will set the empno and ename values as shown below:-
DBMS_XMLQuery.clearBindValues(queryCtx); DBMS_XMLQuery.setBindValue(queryCtx,'EMPNO',20); DBMS_XMLQuery.setBindValue(queryCtx,'ENAME','John');
DBMS_XMLQuery.getXMLClob(queryCtx);
DBMS_XMLQuery.setBindValue(queryCtx,'ENAME','Scott');
The rebinding of ENAME will now use Scott instead of John.
The following example illustrates the use of bind variables in the SQL statement:
declare queryCtx DBMS_XMLquery.ctxType; result CLOB; begin queryCtx := DBMS_XMLQuery.newContext( 'select * from emp where empno = :EMPNO and ename = :ENAME'); DBMS_XMLQuery.clearBindValues(queryCtx); DBMS_XMLQuery.setBindValue(queryCtx,'EMPNO',7566); DBMS_XMLQuery.setBindValue(queryCtx,'ENAME','JONES'); result := DBMS_XMLQuery.getXML(queryCtx); --printClobOut(result); DBMS_XMLQuery.setBindValue(queryCtx,'ENAME','Scott'); result := DBMS_XMLQuery.getXML(queryCtx); --printClobOut(result); end; /
|
Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|