Stored Proc to create XML (using nested cursors)?
From previous posts and from the
documentation for XSQL I have
discovered the joys of the
CURSOR operator to create
nested tables: i.e:
SELECT dname,
CURSOR (SELECT ename, sale....) as employees
FROM dept
However, I can not find any other
documentation on how to program (PL/SQL)
this functionality.
I would like to use XSQL as
it is exactly what I need, but
I can not because my client does
not want to use Java and they
require IIS, but do not want to
use JRUN, etc... (I tried this
first).
Since I only need to do an XML
dump to a variable for processing
by other parts of the program, life
is fairly easy. I have already done
this using Microsoft Data Shapes in
VB (client does not want VC++ either...)
However this was slow.
In order to speed things up I want to
create a stored procedure in Oracle to
dump out the XML hierarchy to a variable given
an SQLQuery input. If I use
nested CURSORS this should be very easy.
I would like to create a recursive PL/SQL
function to handle this, but I have the
following questions:
1) I want the function to have an
input of an open cursor,
My plan is to detect the column
type, when it is a nested cursor
I would recurse with the open cursor
to handle the nested cursor.
2) I can not find a reference on to
programatically handle "untyped collections
based on an SQL statement" in anything
other than the XSQL documentation.
I am assuming that I can detect the
column type of nested cursor somehow
and then recurse on this to handle
dump the recordset to an XML tagset.
But I wuold like to find some documentation
or examples on the calls, type statements,
etc....
I think the CURSOR() thing is an invention of the XSQL Servlet; not available elsewhere.
You can accomplish nesting via user defined types and object views, using the "cast(multiset())" syntax, which is not documented particularly well either. This does require some setup, and so is not particularly dynamic.
Similar Messages
-
Stored Proc to create .csv file from table
Hi all,
I have a table with 4 columns and 10 rows. Now I need a stored proc to create a .csv file from the table data. Here the scripts to create a table and insert the row's.
Create table emp(emp_id number(10), emp_name varchar2(20), department varchar2(20), salary number(10));
Insert into emp values ('1','AAAAA','SALES','10000');
Insert into emp values ('2','BBBBB','MARKETING','8000');
Insert into emp values ('3','CCCCC','SALES','12000');
Insert into emp values ('4','DDDDD','FINANCE','10000');
Insert into emp values ('5','EEEEE','SALES','11000');
Insert into emp values ('6','FFFFF','MANAGER','90000');
Insert into emp values ('7','GGGGG','SALES','12000');
Insert into emp values ('8','HHHHH','FINANCE','14000');
Insert into emp values ('9','IIIII','SALES','20000');
Insert into emp values ('10','JJJJJ','FINANCE','21000');
commit;
Now I need a stored proc to create a .csv file in my local location. Please let me know If you need any other details....Some pointers:
http://www.oracle-base.com/articles/9i/GeneratingCSVFiles.php
http://tkyte.blogspot.com/2009/10/httpasktomoraclecomtkyteflat.html
also, doing a search on this forum or http://asktom.oracle.com will give you many clues.
.csv file in my local location.What is your 'local location'?
A client machine? The database server machine?
What database version are you using?
(the result of: select * from v$version; ) -
How to get UTF-8 encoding when create XML using DBMS_XMLGEN and UTL_FILE ?
How to get UTF-8 encoding when create XML using DBMS_XMLGEN and UTL_FILE ?
Hi,
I do generate XML-Files by using DBMS_XMLGEN with output by UTL_FILE
but it seems, the xml-Datafile I get on end is not really UTF-8 encoding
( f.ex. cannot verifying it correct in xmlspy )
my dbms is
NLS_CHARACTERSET = WE8MSWIN1252
NLS_NCHAR_CHARACTERSET = AL16UTF16
NLS_RDBMS_VERSION = 10.2.0.1.0
I do generate it in this matter :
declare
xmldoc CLOB;
ctx number ;
utl_file.file_type;
begin
-- generate fom xml-view :
ctx := DBMS_XMLGEN.newContext('select xml from xml_View');
DBMS_XMLGEN.setRowSetTag(ctx, null);
DBMS_XMLGEN.setRowTag(ctx, null );
DBMS_XMLGEN.SETCONVERTSPECIALCHARS(ctx,TRUE);
-- create xml-file:
xmldoc := DBMS_XMLGEN.getXML(ctx);
-- put data to host-file:
vblob_len := DBMS_LOB.getlength(xmldoc);
DBMS_LOB.READ (xmldoc, vblob_len, 1, vBuffer);
bHandle := utl_file.fopen(vPATH,vFileName,'W',32767);
UTL_FILE.put_line(bHandle, vbuffer, FALSE);
UTL_FILE.fclose(bHandle);
end ;
maybe while work UTL_FILE there is a change the encoding ?
How can this solved ?
Thank you
Norbert
Edited by: astramare on Feb 11, 2009 12:39 PM with database charsetsMarco,
I tryed to work with dbms_xslprocessor.clob2file,
that works good,
but what is in this matter with encoding UTF-8 ?
in my understandig, the xmltyp created should be UTF8 (16),
but when open the xml-file in xmlSpy as UTF-8,
it is not well ( german caracter like Ä, Ö .. ):
my dbms is
NLS_CHARACTERSET = WE8MSWIN1252
NLS_NCHAR_CHARACTERSET = AL16UTF16
NLS_RDBMS_VERSION = 10.2.0.1.0
-- test:
create table nh_test ( s0 number, s1 varchar2(20) ) ;
insert into nh_test (select 1,'hallo' from dual );
insert into nh_test (select 2,'straße' from dual );
insert into nh_test (select 3,'mäckie' from dual );
insert into nh_test (select 4,'euro_€' from dual );
commit;
select * from nh_test ;
S0 S1
1 hallo
1 hallo
2 straße
3 mäckie
4 euro_€
declare
rc sys_refcursor;
begin
open rc FOR SELECT * FROM ( SELECT s0,s1 from nh_test );
dbms_xslprocessor.clob2file( xmltype( rc ).getclobval( ) , 'XML_EXPORT_DIR','my_xml_file.xml');
end;
( its the same when using output with DBMS_XMLDOM.WRITETOFILE )
open in xmlSpy is:
<?xml version="1.0"?>
<ROWSET>
<ROW>
<S0>1</S0>
<S1>hallo</S1>
</ROW>
<ROW>
<S0>2</S0>
<S1>straޥ</S1>
</ROW>
<ROW>
<S0>3</S0>
<S1>m㢫ie</S1>
</ROW>
<ROW>
<S0>4</S0>
<S1>euro_</S1>
</ROW>
</ROWSET>
regards
Norbert -
Problem with generating xml and nested cursor (ora-600)
I have a problem with generating xml (with dbms_xmlquery or xmlgen) and nested cursors.
When I execute the following command, I get a ORA-600 error:
select dbms_xmlquery.getxml('select mst_id
, mst_source
, cursor(select per.*
, cursor(select ftm_fdf_number
, ftm_value
from t_feature_master
where ftm_mstr_id = pers_master_id ) as features
from t_person per
where pers_master_id = mst_id ) as persons
from f_master
where mst_id = 3059435')
from dual;
<?xml version = '1.0'?>
<ERROR>oracle.xml.sql.OracleXMLSQLException: ORA-00600: internal error code, arguments: [kokbnp2], [1731], [], [], [], [], [], []
</ERROR>
The problem is the second cursor (t_feature_master).
I want to generate this:
<master>
<..>
<persons>
<..>
<features>
<..>
</features>
</persons>
<persons>
<..>
<features>
<..>
</features>
</persons>
</master>
If i execute the select-statement in sql-plus, then I get the next result.
MST_ID MST_SOURCE PERSONS
3059435 GG CURSOR STATEMENT : 3
CURSOR STATEMENT : 3
PERS_MASTER_ID PERS_TITLE PERS_INITI PERS_FIRSTNAME PERS_MIDDL PERS_LASTNAME
3059435 W. Name
CURSOR STATEMENT : 15
FTM_FDF_NUMBER FTM_VALUE
1 [email protected]
10 ....
I use Oracle 8.1.7.4 with Oracle XDK v9.2.0.5.0.
Is this a bug and do somebody know a workaround?Very simple...Drop all type objects and nested tables and create them again. You will get no error. I'll explain the reason later.
-
Calling stored proc from java to return ref cursor
Hi All,
We have a requirement to display all the records from a table on a JAVA screen. Due to some constraints, we have to write the query in the stored proc. We are trying to return a result set from the stored proc to the java code by using a ref cursor. Please refer to the code below.
Following is the PL/SQL proc ?
procedure sp_user_course2(v1 OUT ref_cursor, persid in varchar2) as
begin
open v1 for
SELECT lrn_exp_id, crs_name FROM emp_crs
WHERE personid = persid;
end;
Here ref_cursor is of TYPE REF CURSOR declared in the package specification.
The java code is ?
Callable stmt = conn.prepareCall("call sp_user_course2(?,?)");
stmt.registerOutParameter(1,OracleTypes.CURSOR);
stmt.setString(2,emplId);
stmt.execute();
OracleCallableStatement tstmt = (OracleCallableStatement) stmt;
ResultSet rs = tstmt.getCursor (1);
When I run the program, I get the following error (at stmt.execute()):
[Oracle][ODBC][Ora]ORA-06553: PLS-306: wrong number or types of arguments in call to 'SP_USER_COURSE2' 6553
Can anyone tell me what could be the problem with this code? I have read somewhere that REF CURSOR feature is available from Oracle 9i onwards. If so, then, is there any workaround for mapping REF CURSOR to Resultsets in Oracle 8i?These may help
http://www.google.co.uk/search?q=jdbc+OracleTypes.CURSOR+tutorial -
Hi I want to create a xml using JSP For eg I want to create a report
and I want to take all the data required for the report from the user
and want to put all the information in a session and whenever a user
wants to see the html output I should be able to parse the xml file
and show it to user.
I know it is doable but I am confused about storing the data in
session and concerting that data into XML file any help would be
great.
Thanks,
Preeti
Sounds like you might want to look at XML data binding. Something like JAXB
or Castor can create an object that can be turned into XML by merely calling
a single method and probably streamed to Xalan or whatever to create HTML.
However, don't quote me on this - I am having enough troubles with trying to
get the compiled Objects to be as I wish. Basically, they both take your
DTD with an extra file that defines the types to be used in the classes -
i.e. instead of string int might be used - and which tags to turn into
classes and general information such as this about the output of your
classes. You then simply call Unmarshal (for both castor and JAXB) and it
loads the file from the selected input stream into the created object, you
edit the object, what ever - store it on the server... and call Marshal to
get back the xml... as this is all using streams it could be passed to Xalan
for processing i think...
Hope I've helped, and answered your question a little!
"Preeti Sikri" <[email protected]> wrote in message
news:[email protected]...
> Hi I want to create a xml using JSP For eg I want to create a report
> and I want to take all the data required for the report from the user
> and want to put all the information in a session and whenever a user
> wants to see the html output I should be able to parse the xml file
> and show it to user.
>
> I know it is doable but I am confused about storing the data in
> session and concerting that data into XML file any help would be
> great.
>
> Thanks,
> Preeti
-
Java stored proc performance parsing XML docs
Hi
We are using ORACLE 8i(8.1.6). I have a JAVA Stored procedure that parses XML doc and returns tha values. If I am testing on the box, I get an avg. return time of 2 secs. If I have 20 users, my return time for all went to 25 to 35 secs?
Are there any parameters on ORACLE I can modify to increase the performance. We are developing app for 1000 to 1500 users. I dont want to guess the time based on my test with 20 users.
Any help will be greatly appreciated.
Thank You
RajuRaju,
Oracle 8.1.7 should be better choice for you since it does have the XML stuff
natively compiled.
Regarding scaleability the JVM should scale
very well. However let us know what you find.
- Stefan -
Storing data in data bse using nested tables
using nested tables data can be stored in data base or not.
if yes i need simple example for taht and how to retireve the data from data base.http://download.oracle.com/docs/cd/E11882_01/appdev.112/e11822/adobjvew.htm#ADOBJ00511
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e17126/composites.htm#LNPLS99981 -
Create XML using Data Templates
Is anyone familiar will a tool, other than oracle that will create XML from data template definitions.
I trying to understand if the data template definitions are an Oracle specific tool that only Oracle can use to generate XML files.
If this is specific to Oracle, is there an easier way to use the data templates to generate XML without registering them in the concurrent manager, XMLP Admin, and then executing the concurrent process?
I'm looking for a shortcut to testing these files without having to register everything.Why not using XML Publisher Standalone aka Enterprise 5.6.2 ?
There you can generate the XML based on data templates without registering anything. The installation is quite easy.
Juergen -
Creating XML using JCA functionality
dear friends,
I am working on connection of EP to R3 using JCO and JCA architecture.
Using JCO, i could able to create XML file
i.e.,
JCO.Table sales_orders =function.getTableParameterList().getTable("KOMV");
sales_orders.writeXML("F:
usr
crpts
" + request.getUser().getUniqueName() + ".xml");
In the same manner i would like to create XML file using JCA functionality. But i did't found any functionality in any way as my knowledge.
can anybody help me out this
Secondly,
is it possible to create XML file with in the par path?
like instead of desktop F:
usr
crpts
path i would like to use like dist/xml
suggestion required.
Kanthadear friends,
I am working on connection of EP to R3 using JCO and JCA architecture.
Using JCO, i could able to create XML file
i.e.,
JCO.Table sales_orders =function.getTableParameterList().getTable("KOMV");
sales_orders.writeXML("F:
usr
crpts
" + request.getUser().getUniqueName() + ".xml");
In the same manner i would like to create XML file using JCA functionality. But i did't found any functionality in any way as my knowledge.
can anybody help me out this
Secondly,
is it possible to create XML file with in the par path?
like instead of desktop F:
usr
crpts
path i would like to use like dist/xml
suggestion required.
Kantha -
Dynamically creating XML using Sap-xMII Colum and Row Action Block
Hi,
I am trying to create a xMII-format XML using IlluminatorDocument Action Block.
My problem statement is during run time I am required to create columns on the fly.which I have done using xMII Colum Action block.but now I am required to assing values to these dynamically created columns.I have tried using Data Item and Row action block but am not sucessful in doing so.Can anyone help in creating this xml Dynamically.
The steps that I have followed is
defined
tagquery action block and defined tagquery
blank Illuminator Document Action block
put a repeater on result of tag query
set a counter
updated the counter
used column action block and mapped the column name i.e IlluminatorColumn_0.Name------"test"&Local.count
my column output looks like
Rowsets DateCreated="2007-03-27T12:59:39" EndDate="2007-03-27T11:42:40" StartDate="2007-03-27T11:42:40" Version="11.5.0">
<Rowset>
<Columns>
<Column Description="" MaxRange="100" MinRange="0" Name="test1" SQLDataType="1" SourceColumn="test1"/>
<Column Description="" MaxRange="100" MinRange="0" Name="test2" SQLDataType="1" SourceColumn="test2"/>
<Column Description="" MaxRange="100" MinRange="0" Name="test3" SQLDataType="1" SourceColumn="test3"/>
<Column Description="" MaxRange="100" MinRange="0" Name="test4" SQLDataType="1" SourceColumn="test4"/>
<Column Description="" MaxRange="100" MinRange="0" Name="test5" SQLDataType="1" SourceColumn="test5"/>
</Columns>
</Rowset>
</Rowsets>
after this action block i want to assign values to each column i.e
<Row/>
<Row/>
<Row/>
<Row/>
<Row/>
i.e erach row tags should be filled with columntag and value
but i am not able to achieve the same
Can anyone help me doing thisAfter adding IllumColum Action block I have created 5 columns dynamically
but now I am unable to add row.
currently for everycolumn created it is giving one row without any column node
the configurations that I have done in Data Item Action Block is
In My Link Editor
IlluminatorColumn_0.Name----
>IlluminatorDataItem_0.Name
hardcoded the value i.e 20----
>IlluminatorDataItem_0.Value
IlluminatorDocument_0.Output----
>IlluminatorDataItem_0.IlluminatorDocument
current resultset I am getting is
<?xml version="1.0" encoding="UTF-8"?>
<Rowsets DateCreated="2007-03-27T12:59:39" EndDate="2007-03-27T11:42:40" StartDate="2007-03-27T11:42:40" Version="11.5.0">
<Rowset>
<Columns>
<Column Description="" MaxRange="100" MinRange="0" Name="test1" SQLDataType="1" SourceColumn="test1"/>
<Column Description="" MaxRange="100" MinRange="0" Name="test2" SQLDataType="1" SourceColumn="test2"/>
<Column Description="" MaxRange="100" MinRange="0" Name="test3" SQLDataType="1" SourceColumn="test3"/>
<Column Description="" MaxRange="100" MinRange="0" Name="test4" SQLDataType="1" SourceColumn="test4"/>
<Column Description="" MaxRange="100" MinRange="0" Name="test5" SQLDataType="1" SourceColumn="test5"/>
</Columns>
<Row/>
<Row/>
<Row/>
<Row/>
<Row/>
</Rowset>
</Rowsets> -
hi,
i want to know if the following is possible using EJB and XML.
using HTML/javascript, a form has been created. now the user makes selections using the form. i want to create a XML file that encapsulates the user selections ie this XML file should contain the selections made by the user. this XML file should also automatically change whenever the user makes new selections on the HTML form.
someone suggested me that Beans are the best option to use. can u guide me on how to proceed using Beans.
thanks in advance.Why not use a JSP? Much quicker.
(When someone suggested you use Beans, I doubt they meant Enterprise Beans - cf. SledgeHammer vs Nut). -
Hello,
I want to creat XML document using Dom and XPath, as per my knowledge goes I can't create it using XPath {I may b wrong, if I am then pls tell me know :-) }.
If there doesn't exists any thing like this I am thinkin of wrapping a class {say its XPathProcesserDom} which takes the XPath querry and internaly creates XML Document and returns on request. Is this a good idea :-)
waiting for comments :-)....
thanks and regards,
MaheshPujariHi Piyush
I don't see how you can create a XML document via xpath!?!? xpath it's only used to reference data in an XML document...
Chris -
Storing data in data abse using nested table
using nested table is it possible 2 store data in data base .give me simple example how tos tore data in data abse usingnested tables.and how to retieve it from data abse.
See: http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:410619303624
-
Create XML using data from Oracle
Other than using OracleXMLQuery, how do I create an XML file from the data from a table in Oracle?
Rgds,
SeeteshVetsrini:
Thanks for your response. I no longer can receive email at [email protected], because I am at a different company now. So please post directly to this forum so I can receive my messages.
I would imagine that "look ahead" is a feature needed by many applications, since the heading of a document may depend on the data within. In my case, we have a Pack Slip that we want the bold heading title to change if the word "FAX" is inside the body of the document. Instead of saying "Pack Slip", it would say "Fax Pack Slip".
Any hints would be greatly appreciated.
Regards,
Rich Locus
Maybe you are looking for
-
My iPhone and iMac can't connect to my 3G wifi via my MacPro
Currently I have an iMac (on IOS 10.6.8 - haven 't upgraded it to new OSX yet); an iPhone 5, a Macbook Pro 13" (which belongs to work) and a new Macbook Pro 15" which I bought. To connect to the web, I use a 3G stick. Usually I plug that into the iMa
-
Dear all SAP ECC6.0 retail for provogue implementation, I am submitting the queries, can u please make solutions for all, these are the pending queries for provogue. Which canu2019t able to go for live? Please your people can support for the is
-
Display has disappeared!!
hello all , new to mac... went to change screensaver tonight and .... no Display in System Preferences, what have I inadvertently done??? Thanking you all in advance for any help!
-
Not prompted to set Administrator password at logon after Sysprep
As far as I know, the following are facts regarding the Administrator password on Windows 2008 R2: - By default the Administrator account is enabled and the password is blank, but you are forced to set a password at first logon after Windows installa
-
Hey guys, been struggling to get rid of loads of 'Spotify' apps on my open with menu, looks like this: any ideas how to get rid of them?