Search a CLOB column(contains XML) in Oracle table
Hi,
I need help on how will i be able to search the data in a clob column that contains XML in an ORACLE table.
Thanks,
PSS
We are using 10g.. and database in which the table is located.. i just have a read only access .. so i am pulling all the data into a flat file (im using a shell script) and from there on i need to process the data... and my problem is how to pull the data in the CLOB using sql or whichever way.. if you can explain me with an example i would really appreciate it...
Thanks,
PSS
Similar Messages
-
Searching CLOB column of XML documents with leading wildcard - Performance
Hi, our table has a text indexed CLOB column of XML documents and when performing a search with a leading wild card, we never retrieve any results.
The query looks like this:
select id from <table> where contains(columnname, '(%12345)') > 0;
I cant even generate an explain plan from this query. I killed it after 39 minutes.
If the query changes to:
select id from <table> where contains(columnname, '(12345%)') > 0;
I get an explain plan immediately with a cost=2 and when I execute the query, I get results in less than a second.
I'd appreciate any thoughts of what I should check or what the problem might be.
Thanks! DougCan you provide a script that reproduces the case. I am unable to reproduce the problem with just some small sample data, as shown below. That means that there is nothing wrong with the syntax, but you may be having problems due to the size of your data or other parameters that have not been mentioned.
SCOTT@10gXE> CREATE TABLE your_table (id NUMBER, columnname CLOB)
2 /
Table created.
SCOTT@10gXE> insert into your_table
2 select 1, dbms_xmlgen.getxml
3 ('select deptno, dname,
4 cursor (select empno, ename
5 from emp
6 where emp.deptno = dept.deptno ) employee
7 from dept
8 where deptno = 10')
9 from dual
10 /
1 row created.
SCOTT@10gXE> SELECT * FROM your_table
2 /
ID COLUMNNAME
1 <?xml version="1.0"?>
<ROWSET>
<ROW>
<DEPTNO>10</DEPTNO>
<DNAME>ACCOUNTING</DNAME>
<EMPLOYEE>
<EMPLOYEE_ROW>
<EMPNO>7782</EMPNO>
<ENAME>CLARK</ENAME>
</EMPLOYEE_ROW>
<EMPLOYEE_ROW>
<EMPNO>7839</EMPNO>
<ENAME>KING</ENAME>
</EMPLOYEE_ROW>
<EMPLOYEE_ROW>
<EMPNO>7934</EMPNO>
<ENAME>MILLER</ENAME>
</EMPLOYEE_ROW>
</EMPLOYEE>
</ROW>
</ROWSET>
SCOTT@10gXE> CREATE INDEX your_idx ON your_table (columnname)
2 INDEXTYPE IS CTXSYS.CONTEXT
3 /
Index created.
SCOTT@10gXE> EXEC DBMS_STATS.GATHER_TABLE_STATS ('SCOTT', 'YOUR_TABLE')
PL/SQL procedure successfully completed.
SCOTT@10gXE> SET AUTOTRACE ON EXPLAIN
SCOTT@10gXE> select id from your_table where contains (columnname, '(%839)') > 0
2 /
ID
1
Execution Plan
Plan hash value: 2832585188
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 1 | 888 | 0 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| YOUR_TABLE | 1 | 888 | 0 (0)| 00:00:01 |
|* 2 | DOMAIN INDEX | YOUR_IDX | | | 0 (0)| 00:00:01 |
Predicate Information (identified by operation id):
2 - access("CTXSYS"."CONTAINS"("COLUMNNAME",'(%839)')>0)
SCOTT@10gXE> SET AUTOTRACE OFF -
Creating interMedia substring index on a CLOB that contains XML
I have a CLOB column that has an existing XML_SECTION_GROUP index on certain tags within the XML content of the CLOB. (see script below)
begin
ctx_ddl.create_section_group('XMLDOC','XML_SECTION_GROUP');
end;
begin
ctx_ddl.add_zone_section ('XMLDOC','title','title');
ctx_ddl.add_zone_section('XMLDOC','keywords','keywords');
ctx_ddl.add_zone_section('XMLDOC','author','author');
end;
create index xmldoc_idx on xml_documents(xmldoc)
indextype is ctxsys.context
parameters ('section group xmldoc') ;
I have a requirement to search on the 'author' zone section by the first letter only. I figure a substring index is the way to go but I'm not sure of the syntax to create a substring index. Especially when I have already declared a SECTION_GROUP preference on this column and I would need to create a WORDLIST preference as well I think. Can someone help me out here?
nullHere is the answer from Oracle Text Help:
"the main problem here is that you cannot apply that fancy substring
processing just to the author section -- it will apply to everything,
which will probably blow up the index size.
Anything you do will require reindexing the documents, so you cannot
really get around having to rebuild the index entirely.
Here are various ways to tackle the problem:
1. do nothing. Query just like: Z% WITHIN AUTHOR
PRO: don't have to rebuild index
CON: query is slow. some queries cannot be executed due to
wildcard maxterms limits.
2. create a wordlist preference with PREFIX_INDEX set to TRUE,
PREFIX_MIN_LENGTH set to 1 and PREFIX_MAX_LENGTH set to 1.
Query looks like: Z% WITHIN AUTHOR
PRO: moderately fast query
CON: must be on 8.1.7 or above
get a lot of junk from words from other sections
3. 2) as above, plus make AUTHOR, KEYWORDS, TITLE field sections
PRO: faster query than 2)
CON: field sections are less flexible w.r.t. nesting and
repeating occurrences
4. use a user_datastore or procedure_filter to transform the data
so that <AUTHOR>Steven King</AUTHOR> becomes
<AUTHORINIT>AIK</AUTHORINIT><AUTHOR>Steven King<AUTHOR>
Use field section for AUTHORINIT and query becomes:
AIK within AUTHORINIT (I used AIK instead of just K so that you
don't have to make I and A non-stopwords)
PRO: fastest query, smallest index
CON: most work
have to massage data so slows down indexing" -
Clob Columns gettting swapped in a table in Oracle 10G
Hi Experts,
When we try to insert a data into a table having two clob columns, if the data size increases more than 1000 characters, the contents of these two clob columns getting swapped. If it is less than 1000 characters, it works fine.
We are using bea Jrockit 27.6 JDK, Oracle 10G, Hibernate2, ibatis. Oracle jdbc driver is 10.2.0.4.
Any pointers on the above would be appreciated.
Thanks in advance.
-OKcheck if it is something related to inline and outline storage.
for LOB, if the data is less than 32k they are stored inline with table data. If they are more than 32k they are stored seperately. Perhaps...
one thing you can do is to use 2 tablespaces and assign one tablespace each for CLOB column then definitely you are apart. -
I have two tables
client_captions (which contains a varchar2 column called captions)
clients (which contains a clob column called client)
I'd like to know how many clients have any of the client captions within their clients data (which is a clob column).
Could you provide the code to figure this out.
E.g,
select * from clients where instr(client,:caption) > 0
where :caption would come from
select caption from client_captions
Could you help me by providing me with the code?
ThanksSince 9i LIKE works too:
SQL> create table t1 (clob_data clob);
Table created.
SQL> insert into t1 values('shdgshdgsjadgsahdkjahsdjkhjksadhjksadhakjhSMITHhagjhsgajs');
1 row created.
SQL> insert into t1 values('843984365984365437896543789564389756439875643985ALLAN8798435 45439857439
8574');
1 row created.
SQL> insert into t1 values('84398436598436543789654378956438975643987564398WARD475984375');
1 row created.
SQL> select substr(clob_data,1,10) from
2 t1 where exists (select 1 from emp where t1.clob_data like '%'||emp.ename||'%');
SUBSTR(CLOB_DATA,1,10)
shdgshdgsj
8439843659Rgds. -
Generating xml from oracle table
Hi,
I want to generate xml form an oracle table and using sql developer, oracle express 10g, xdk forler is also unzipped under oracle express folder, still getting following error: code used
var g_clob clob;
declare
l_ctx dbms_xmlquery.ctxHandle;
l_clob clob;
begin
l_ctx := dbms_xmlquery.newContext('select * from scott.emp');
dbms_lob.createtemporary(:g_clob,true,dbms_lob.session);
:g_clob := dbms_xmlquery.getXml(l_ctx);
end;
/ORA-06550: line 2, column 14:
PLS-00201: identifier 'DBMS_XMLQUERY.CTXHANDLE' must be declared
Thanks in advanceHi,
DBMS_XMLQUERY is a wrapper for methods from the Java class "oracle.xml.sql.query.OracleXMLStaticQuery".
The problem is that Oracle 10g XE doesn't have a JVM, so you can't use this package.
Use DBMS_XMLGEN instead, it provides similar functionalities and is more efficient (C-based) :
SQL> var g_clob clob
SQL> DECLARE
2 l_ctx dbms_xmlgen.ctxHandle;
3 BEGIN
4 l_ctx := dbms_xmlgen.newContext('select * from scott.emp');
5 :g_clob := dbms_xmlgen.getXML(l_ctx);
6 dbms_xmlgen.closeContext(l_ctx);
7 END;
8 /
PL/SQL procedure successfully completed.
SQL> set long 5000
SQL> set pages 1000
SQL> print g_clob
G_CLOB
<?xml version="1.0"?>
<ROWSET>
<ROW>
<EMPNO>7369</EMPNO>
<ENAME>SMITH</ENAME>
<JOB>CLERK</JOB>
<MGR>7902</MGR>
<HIREDATE>17/12/80</HIREDATE>
<SAL>800</SAL>
<DEPTNO>20</DEPTNO>
</ROW>
<ROW>
<EMPNO>7499</EMPNO>
<ENAME>ALLEN</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>20/02/81</HIREDATE>
<SAL>1600</SAL>
<COMM>300</COMM>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7521</EMPNO>
<ENAME>WARD</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>22/02/81</HIREDATE>
<SAL>1250</SAL>
<COMM>500</COMM>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7566</EMPNO>
<ENAME>JONES</ENAME>
<JOB>MANAGER</JOB>
<MGR>7839</MGR>
<HIREDATE>02/04/81</HIREDATE>
<SAL>2975</SAL>
<DEPTNO>20</DEPTNO>
</ROW>
<ROW>
<EMPNO>7654</EMPNO>
<ENAME>MARTIN</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>28/09/81</HIREDATE>
<SAL>1250</SAL>
<COMM>1400</COMM>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7698</EMPNO>
<ENAME>BLAKE</ENAME>
<JOB>MANAGER</JOB>
<MGR>7839</MGR>
<HIREDATE>01/05/81</HIREDATE>
<SAL>2850</SAL>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7782</EMPNO>
<ENAME>CLARK</ENAME>
<JOB>MANAGER</JOB>
<MGR>7839</MGR>
<HIREDATE>09/06/81</HIREDATE>
<SAL>2450</SAL>
<DEPTNO>10</DEPTNO>
</ROW>
<ROW>
<EMPNO>7839</EMPNO>
<ENAME>KING</ENAME>
<JOB>PRESIDENT</JOB>
<HIREDATE>17/11/81</HIREDATE>
<SAL>5000</SAL>
<DEPTNO>10</DEPTNO>
</ROW>
<ROW>
<EMPNO>7844</EMPNO>
<ENAME>TURNER</ENAME>
<JOB>SALESMAN</JOB>
<MGR>7698</MGR>
<HIREDATE>08/09/81</HIREDATE>
<SAL>1500</SAL>
<COMM>0</COMM>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7900</EMPNO>
<ENAME>JAMES</ENAME>
<JOB>CLERK</JOB>
<MGR>7698</MGR>
<HIREDATE>03/12/81</HIREDATE>
<SAL>950</SAL>
<DEPTNO>30</DEPTNO>
</ROW>
<ROW>
<EMPNO>7902</EMPNO>
<ENAME>FORD</ENAME>
<JOB>ANALYST</JOB>
<MGR>7566</MGR>
<HIREDATE>03/12/81</HIREDATE>
<SAL>3000</SAL>
<DEPTNO>20</DEPTNO>
</ROW>
<ROW>
<EMPNO>7934</EMPNO>
<ENAME>MILLER</ENAME>
<JOB>CLERK</JOB>
<MGR>7782</MGR>
<HIREDATE>23/01/82</HIREDATE>
<SAL>1300</SAL>
<DEPTNO>10</DEPTNO>
</ROW>
</ROWSET>Or, using SQL/XML functions :
SELECT XMLElement("ROWSET",
XMLAgg(
XMLElement("ROW",
XMLForest(empno, ename, job, mgr, hiredate, sal, comm, deptno)
).getClobVal()
FROM scott.emp
; -
Data from xml to oracle tables
Hi All,
I need to store data from the XML documents into appropriate tables in ORACLE. Note: I dont need to store the document itself, but the data in the document needs to be stored in the tables. What is the right way of doing this?
I previoulsy used SQLXML3.0 to load data from the XML documents to SQL server database ( .xsd will take care of the mapping), but we now need to store data into Oracle tables.
Thanks,There is a XMLDB demo authored by Mark Drake. This will explain a lot about Oracle XMLDB.
AFter reading, if you still have questions post back to the list
http://www.oracle.com/ultrasearch/wwws_otn/searchotn.jsp?p_Action=Search&p_Query=demo+xml -
Hi,
How can I read an xml.file read in an oracle table (invoice varchar2(20), invoice_line number, ship_date date, country varchar2(100))?
The xml looks like this:
<?xml version="1.0" encoding="utf-8" ?>
- <dataset xmlns="http://developer.cognos.com/schemas/xmldata/1/" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
- <!--
<dataset
xmlns="http://developer.cognos.com/schemas/xmldata/1/"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://developer.cognos.com/schemas/xmldata/1/ xmldata.xsd"
>
-->
- <metadata>
<item name="Invoice #" type="xs:string" length="42" />
<item name="Invoice Line" type="xs:string" length="10" />
<item name="Ship Date" type="xs:date" />
<item name="COUNTRY" type="xs:string" length="8" />
</metadata>
- <data>
- <row>
<value>26623</value>
<value>0001</value>
<value>2010-05-03</value>
<value>USA</value>
</row>
- <row>
<value>26624</value>
<value>0001</value>
<value>2010-05-03</value>
<value>USA</value>
</row>
- <row>
<value>26624</value>
<value>0003</value>
<value>2010-05-03</value>
<value>USA</value>
</row>
- <row>
<value>26625</value>
<value>0001</value>
<value>2010-05-03</value>
<value>USA</value>
</row>
</data>
</dataset>
Thnx, RobbertHi,
Possible solutions will depend on your db version, which you didn't give.
The following example assumes you're using 10gR2 :
CREATE TABLE invoices (
invoice varchar2(20),
invoice_line number,
ship_date date,
country varchar2(100)
DECLARE
xmldoc xmltype := xmltype(
'<?xml version="1.0" encoding="utf-8" ?>
<dataset xmlns="http://developer.cognos.com/schemas/xmldata/1/" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance">
<metadata>
<item name="Invoice #" type="xs:string" length="42" />
<item name="Invoice Line" type="xs:string" length="10" />
<item name="Ship Date" type="xs:date" />
<item name="COUNTRY" type="xs:string" length="8" />
</metadata>
<data>
<row>
<value>26623</value>
<value>0001</value>
<value>2010-05-03</value>
<value>USA</value>
</row>
<row>
<value>26624</value>
<value>0001</value>
<value>2010-05-03</value>
<value>USA</value>
</row>
<row>
<value>26624</value>
<value>0003</value>
<value>2010-05-03</value>
<value>USA</value>
</row>
<row>
<value>26625</value>
<value>0001</value>
<value>2010-05-03</value>
<value>USA</value>
</row>
</data>
</dataset>'
BEGIN
INSERT INTO invoices (invoice, invoice_line, ship_date, country)
SELECT invoice, invoice_line, to_date(ship_date, 'YYYY-MM-DD'), country
FROM XMLTable(
XMLNamespaces(default 'http://developer.cognos.com/schemas/xmldata/1/'),
'/dataset/data/row'
passing xmldoc
columns
invoice varchar2(20) path 'value[1]',
invoice_line number path 'value[2]',
ship_date varchar2(10) path 'value[3]',
country varchar2(100) path 'value[4]'
END;
/If your XML document resides outside the database, you may also access it directly through a DIRECTORY object :
CREATE OR REPLACE DIRECTORY xmldir AS 'C:\oracle\invoices\xml';
INSERT INTO invoices (invoice, invoice_line, ship_date, country)
SELECT invoice, invoice_line, to_date(ship_date, 'YYYY-MM-DD'), country
FROM XMLTable(
XMLNamespaces(default 'http://developer.cognos.com/schemas/xmldata/1/'),
'/dataset/data/row'
passing xmltype( bfilename('XMLDIR', 'invoices.xml'), nls_charset_id('AL32UTF8') )
columns
invoice varchar2(20) path 'value[1]',
invoice_line number path 'value[2]',
ship_date varchar2(10) path 'value[3]',
country varchar2(100) path 'value[4]'
);Some docs about XMLTable and XML querying with Oracle :
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions228.htm#CIHGGHFB
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14259/xdb_xquery.htm#ADXDB1700
Edited by: odie_63 on 24 juin 2010 20:07 -
HI All,
I have table like-
CREATE TABLE C2X_TEST(NAME VARCHAR2(100),XML_CLOB CLOB,XML_XML XMLType);
here in XML_CLOB column xml files are stored.
Now i want to update XML_XML column with corresponding XML_CLOB value .
How to update or insert?Thanks Odie. Will be trying it this week. We have many documents (Excel, Word) stored as BLOB columns in the Oracle EBS - R12 Procurement suite. Our general plan is to convert them using the following steps:
STEP 1: Convert BLOB to XMLtype (using the technique you have suggested )
STEP 2: Use XQuery to search data ..
I have been reading on the XML docs as well as your blog and I think the number of options here can get very confusing .....when to use what (CLOB, BLOB, XMLType, etc) ....
I am going to try and stick with the following policy:
(a) Use SQL for querying and updating Structured data
(b) Use XQuery for querying and updating XML data
The other options such as the below do not make sense to me ...
(a) Use SQL for XML data
(b) Use XML for Structured data
Thanks - Yesh -
Inserting Clob column containg xml without row tags
am on
Connected to:
Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
JServer Release 8.1.7.4.0 - Production
When I try and insert this its fine i.e with ROW AND ROWSET TAGS in place
|<?xml version = '1.0'?>
|<ROWSET>
| <ROW num="1">
| <COLLAR_NO>9463</COLLAR_NO>
| <QUAL_CODE>Rifle (MP5</QUAL_CODE>
| <START_DATE>10/1/2000 0:0:0</START_DATE>
| <END_DATE>9/30/2003 0:0:0</END_DATE>
| </ROW>
|</ROWSET>
But with this output it gives with error
|<?xml version = '1.0'?>
|<COLLAR_NO>9463</COLLAR_NO>
|<QUAL_CODE>Rifle (MP5</QUAL_CODE>
|<START_DATE>10/1/2000 0:0:0</START_DATE>
|<END_DATE>9/30/2003 0:0:0</END_DATE>
declare
ERROR at line 1:
ORA-29532: Java call terminated by uncaught Java exception: oracle.xml.sql.OracleXMLSQLException:
Expected 'EOF'.
ORA-06512: at "SYS.DBMS_XMLSAVE", line 91
ORA-06512: at "APPS.INSPROC", line 6
ORA-06512: at line 5This forum is for XML DB, which is a feature of 9iR2 and later. Questions related to using XML with pre 9.2 versions of the database should be posted in the general XML Technology forum
-
Generate XML from Oracle Table Data
Hi All,
I am new to this network. I am also new to oracle XML package. I want a help for the below query.
CREATE TABLE EMP(ID NUMBER PRIMARY KEY, NAME VARCHAR2(10), PHONE NUMBER);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (11,'Joy',1234);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (22,'Mike',5678);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (33,'Jason',NULL);
COMMIT;
I want to export the EMP table data in a XML file with the below format.
Required Output:
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>11</ID><NAME>Joy</NAME></EMP></STATICDATA>
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>22</ID><NAME>Mike</NAME></EMP></STATICDATA>
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>33</ID><NAME>Jason</NAME></EMP></STATICDATA>
I have used some XML functions and have written the below query.
select XMLROOT(XMLELEMENT(staticdata,XMLELEMENT(EMP,XMLELEMENT(ID,ID),XMLELEMENT(NAME,NAME))), version '1.0" encoding="UTF-8') xml FROM EMP;
output of my query:
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>11</ID>
<NAME>Joy</NAME>
</EMP>
</STATICDATA>
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>22</ID>
<NAME>Mike</NAME>
</EMP>
</STATICDATA>
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>33</ID>
<NAME>Jason</NAME>
</EMP>
</STATICDATA>
But i want the out as the required output above. every record in a single line. can any one help me in achieving the required output. also can i export all the columns of the table by some thing like select * from the table in XML file ?
Thanks,
Sartajuser13683418 wrote:
Hi All,
I am new to this network. I am also new to oracle XML package. I want a help for the below query.
CREATE TABLE EMP(ID NUMBER PRIMARY KEY, NAME VARCHAR2(10), PHONE NUMBER);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (11,'Joy',1234);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (22,'Mike',5678);
INSERT INTO EMP(ID,NAME,PHONE) VALUES (33,'Jason',NULL);
COMMIT;
I want to export the EMP table data in a XML file with the below format.
Required Output:
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>11</ID><NAME>Joy</NAME></EMP></STATICDATA>
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>22</ID><NAME>Mike</NAME></EMP></STATICDATA>
<?xml version="1.0" encoding="UTF-8"?><STATICDATA><EMP><ID>33</ID><NAME>Jason</NAME></EMP></STATICDATA>
I have used some XML functions and have written the below query.
select XMLROOT(XMLELEMENT(staticdata,XMLELEMENT(EMP,XMLELEMENT(ID,ID),XMLELEMENT(NAME,NAME))), version '1.0" encoding="UTF-8') xml FROM EMP;
output of my query:
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>11</ID>
<NAME>Joy</NAME>
</EMP>
</STATICDATA>
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>22</ID>
<NAME>Mike</NAME>
</EMP>
</STATICDATA>
<?xml version="1.0" encoding="UTF-8"?>
<STATICDATA>
<EMP>
<ID>33</ID>
<NAME>Jason</NAME>
</EMP>
</STATICDATA>
But i want the out as the required output above. every record in a single line.Why?
Some things output XML all as one stream, some things naturally display it structured. It doesn't matter as the XML is still the same because by it's very nature it is a structured data definition. Anything that reads XML will be able to read it whether it's on one line (streamed) or structured.
also can i export all the columns of the table by some thing like select * from the table in XML file ?A couple of ways of exporting XML to a file...
-- DBMS_XSLPROCESSOR.clob2file
-- outputs a clob to a file
DECLARE
ctx DBMS_XMLGEN.ctxtype;
BEGIN
ctx := DBMS_XMLGEN.newcontext ('select * from emp');
DBMS_XSLPROCESSOR.clob2file (DBMS_XMLGEN.getxml (ctx), 'TEMP', 'emp.xml');
DBMS_XMLGEN.closecontext (ctx);
END;
PL/SQL procedure successfully completed.or
..snip..
v_xml XMLTYPE;
v_doc XMLDOM.DOMDocument;
v_dir VARCHAR2(2000);
v_file VARCHAR2(2000);
BEGIN
v_xml := ... populate with XML ...;
v_dir := 'TEST_DIR'; -- directory object name (in UPPER CASE)
v_file := 'myfile.xml';
v_doc := DBMS_XMLDOM.NEWDOMDOCUMENT(v_xml);
DBMS_XMLDOM.WRITETOFILE(v_doc, v_dir||'\'||v_file, 'UTF-8');
DBMS_XMLDOM.FREEDOCUMENT(v_doc);
..snip.. -
Create XML from oracle table if not null
Hello dear community,
I have a problem by creating an XML file in oracle and hope you could help me.
What I have is an table named "description" with three rows there:
person varchar2(50)
adress varchar2(50)
Nr number
Reading this table I am going to create an XML file like that:
Procedure Create_XML (iNr IN number, cXmlFile OUT clob) is
varPerson varchar2(50);
varAdress varchar2(50);
Begin
varPerson := ... ;
varAdress := ... ;
select
xmlserialize
content
xmlelement
"Head",
xmlelement
"Node",
xmlelement
"Line",
xmlelement("ATNAM", 'PERSON'),
xmlelement("ATWRT", PERSON),
xmlelement("ATFOR", varPerson)
xmlelement
"Line",
xmlelement("ATNAM", 'ADRESS'),
xmlelement("ATWRT", ADRESS),
xmlelement("ATFOR", varAdress)
indent
) as xml
into cXmlFile
from description
where Nr = iNr;
End Create_XML;
What I want to do, is just to take the value from the both rows "person" and "adress" and fill the xml file with additional info.
1. My first question is, if it is possible to create any kind of routine for the xmlelement "Line" instead of doing it all over and over again? How?
2. An other issue is very important to me: how can I check here if f.i. the row person is empty or not? If it is, the xmlelement "Line" with person information in it should not be created at all.
Any answer would really help me!
Thank you a lot in advance!Hi,
Could you elaborate a little on your first question?
Are you looking for something like :
SELECT xmlquery(
'<head>
<node>
for $i in ora:view("DESCRIPTION")/ROW[NR=$nr]/*[local-name()!="NR"]
return element Line {
element ATNAM {local-name($i)},
element ATWRT {$i/text()}
</node>
</head>'
passing sys_xmlgen(1) as "nr"
returning content
FROM dual;but since you use a specific variable for each "line" type, I don't see how we can generalize the construction of the line element. -
Error trying to insert xml into Oracle table
Hi -
I am trying to (a)read a row from emp table and output the results in xml format
and (b) insert this row to another emp_new table (same structure as emp).
When I run it here is what I get:
OUTPUT IS:
<?xml verions='1.0'?>
<Employee>
<Emp num="1">
<EMPNO>7369</EMPNO>
<ENAME>Smith</ENAME>
<JOB>Clerk</JOB>
<MGR>7902</MGR>
<HIREDATE>12/7/1980</HIREDATE>
<SAL>800</SAL>
<DEPTNO>20</DEPTNO>
</Emp>
</Employee>
Exception in thread "main" oracle.xml.sql.OracleXMLSQLException:
No rows to modify -- the row enclosing tag is missing. Specify
the correct row enclosing tag.
etc...
The row enclosing tag is given by setRowTag("Emp").
What's wrong here? Any ideas?
PS: To Ambrose Padilla: Your response was helpful. Thank you.
Program
import java.sql.*;
import oracle.xml.sql.query.*;
import oracle.jdbc.driver.*;
import oracle.xml.sql.dml.*;
class testXML
public static void main(String[] args) throws SQLException
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
//initialize a JDBC connection
Connecton conn = DriverManager.getConnection("jdbc:oracle:thin:mytest:1521:acme", "scott", "tiger");
//initialize the OracleXMLQuery
OracleXMLQuery qry =
new OracleXMLQuery(conn,"select * from emp where rownum < 2");
// set the document name
qry.setRowsetTag("Employee");
// set the row element name
qry.setRowTag("Emp");
// get the XML result
String xmlString = qry.getXMLString();
// print result
System.out.println(" OUPUT IS:\n"+xmlString);
OracleXMLSave sav = new OracleXMLSave(conn,"emp_new");
sav.insertXML(xmlString);
sav.close();
}Try inserting
sav.setRowTag("emp");
before calling insertXML. -
Creating XML from Oracle Tables
Would it be possible to post me a snapshot of the ODI Flow diagram for an Oracle to XML conversion? Does the staging area have to be on the Target (XML)? What KMs & CM should be used? Can the XML be written straight back to an .xml file? What should the XML Schema look like?
These are the KMs I use: LKM-SQL to SQL; IKM-SQL Incremental Update; CKM-SQL.
My flow is straight from source (oracle) to target (xml), with staging area on target (doesn't feel right).
My Oracle Dataserver & Schema work fine. Not sure about the XML dataserver setup though - I think this is where the problem lies. These are my JDBC settings:
- com.sunopsis.jdbc.driver.xml.SnpsXmlDriver
- jdbc:snps:xml?f=E:\Oracle ODI\Member.xsd
I am evaluating ODI for a client and I wanted to throw together a quick demo showing how easily ODI can generate XML from any source. I know this is the case as I understand the concept of ODI's components - just haven't had time to read manuals thoroughly.
Many thanks for your help,
SteveHello,
1. Try to test the connection to the XML dataserver.
2. Create a model and reverse-engineer this dataserver. You'll see what the XML structure is mapped to immediately.
3. Integrate data to this model (using standard KM targeting "SQL").
You can put the staging area on the Oracle source or in the XML driver if you want. Both solutions will work.
just haven't had time to read manuals thoroughly.I think you should quickly read the "Sunopsis ODI with... XML" section in the manual.
It is not very long and very helpful. Have also a quick look at the XML driver documentation.
Regards,
-FX -
Hi All,
Help! Could someone tell me how to insert an empty string ( not null ) in a table using XML?
e.g if I had this table TEST
Name Null? Type
COL1 NOT NULL CHAR(5)
COL2 NOT NULL CHAR(1)
and this xml
<?xml version="1.0"?>
<tests>
<test>
<COL1>PPPPP</COL1>
<COL2> </COL2>
<test>
<tests>
I use OracleXmlSave to insert this xml into the database and I get this error
"Cannot insert null into TEST.COL2"
but I am actually trying to insert a blank.
Anybody came across this problem and knows how to fix it?
Thanks a lot!!!!I fixed my problem;
I changed my xml to this
<?xml version="1.0"?>
<tests>
<test>
<COL1>PPPPP</COL1>
<COL2><![CDATA[ ]]></COL2>
<test>
<tests>
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by pearlph:
Hi All,
Help! Could someone tell me how to insert an empty string ( not null ) in a table using XML?
e.g if I had this table TEST
Name Null? Type
COL1 NOT NULL CHAR(5)
COL2 NOT NULL CHAR(1)
and this xml
<?xml version="1.0"?>
<tests>
<test>
<COL1>PPPPP</COL1>
<COL2> </COL2>
<test>
<tests>
I use OracleXmlSave to insert this xml into the database and I get this error
"Cannot insert null into TEST.COL2"
but I am actually trying to insert a blank.
Anybody came across this problem and knows how to fix it?
Thanks a lot!!!!
<HR></BLOCKQUOTE>
null
Maybe you are looking for
-
How do I make and get calls with my US Phone in another country?
Do I just dial the local number or do I have to dial international stuff? Same question for getting calls from the US. How to people there call me? Sorry if this is a dumb question....... Oh the place in Asia is on the countries list for the Iphone.
-
No Video on Skype webcam Yosemite
I am using Skype 7.2.412 there is no video just a black screen (although ledi ndicates that it is on). Tried also with Skype_7.1.665 same problem ( did try to reinstall, reinstall + reset computer) nothing seems to work. MacBookPro11,2 OS: Yosemite
-
Reservation and Purchase requisistion
Hi, Sysytem is creating reservation for stock item and purchase req for non stock item. Anybody tell me where is the setting. Regards, KP
-
My raw video won't play in CS5? HELP PLEASE!
Ok I'm new to after effects and I just got ae cs5 for christmas. I just installed it and I wanted to do a test so I took some raw footage from my JVC HD3 Everio video camera. The raw video is in .TOD format and when i try to open it in ae cs5 it says
-
Urgent!Unable input Turkish Text in JTextField in Linux..
Hi all, I sorted the topics but i could not find any answer to my question. In q swing component like a JTextField, i can't input turkish characters ( like '?',S with a point). How can i found the turkish font, or must i sat the locale. Thanks...