Update the passed XML in a PL/SQL procedure and then use DBMS_XMLSAVE
hi folks,
This is a great forum and most of you guys were awesome in replying to complex queries........
I have a small issue, I am trying to do a bulk insert from my application by constructing an XML result set and pass that XML to the SP as a CLOB and using DBMS_XMLSAVE package to insert it to the oracle table. It works like a charm for me when this is as straight forward as this. But when my requirement is, I need to generate sequence numbers for a particular column (Primary key column), while for other columns I pass values from the UI (as a XML object which my SP accepts as a CLOB), i am at a loss for solution to achieve this. It would mean, that I have to generate the sequence numbers for each row and then update this value to the passed XML clob. Any indicators on how to achieve this?
I found this solution at one of the thread which might most probably help me,
declare
2 l_cnt number;
3 begin
4 select count(*) into l_cnt from books,xmltable('/Books/Book' passing object_value);
5 for i in 1..l_cnt loop
6 update books set object_value =
7 updatexml(object_value,'/Books/Book['||i||']/BookID', xmlelement("BookID",sequence_bookid.nextval))
8 where existsnode(object_value,'/Books/Book['||i||']')=1;
9 end loop;
10 end;
11 /
But here, they are trying to update a XMLTable book, but in my case the XML is a clob object and not a XML table. Will this solution work for my case as well? Please provide any pointers to me... Thanks...
First if your version of Oracle has DBMS_XMLSTORE, use that instead.
Reason: {thread:id=876376} (See Marco's response).
It is possible you could run into issues, but you should start with DBMS_XMLSTORE.
Since you will have the XML in the SP, treat the data as an XMLType instead of a CLOB for as long as you can since you need to do UpdateXML on it.
For your sample PL/SQL code, lines 4-5 are replaced with the WHILE loop shown in Method 2 at
{message:id=3610259}.
The UPDATE would be replaced with the following pseudocode
SELECT UPDATEXML(<l_xmltype_variable>, ...)
INTO <l_xmltype_variable>
FROM dual;
Once your loop is done, l_xmltype_variable would contain your updated XML and then you can use that XMLType directly on the call to DBMS_XMLSTORE or convert it back to a clob via
l_clob_variable := l_xmltype_variable.getClobVal();
Similar Messages
-
Passing arrays through multiple PL/SQL procedures and functions
I am maintaining a large PL/SQL application. There is a main procedure that is initially called which subsequently passes information to other PL/SQL functions and procedures. In the end an error code and string is passed to PUT_LINE so it can be displayed. What I would like to be able to do is have an array that stores an error code and string for each error that it comes upon during going through each of the procedures and functions. This would involve passing these codes and strings from function to function within the pl/sql application. What would be the best way to implement this and is it possible to pass arrrays or records to other PL/SQL functions? Thanks.
Here is one simulation ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Elapsed: 00:00:00.20
satyaki>
satyaki>
satyaki>create or replace type n_array is table of number;
2 /
Type created.
Elapsed: 00:00:07.10
satyaki>
satyaki>CREATE OR REPLACE PROCEDURE Get_Array(array_in IN n_array,
2 array_out OUT n_array)
3 IS
4 BEGIN
5 array_out := n_array();
6 FOR i IN 1..array_in.count
7 LOOP
8 array_out.extend;
9 array_out(i) := array_in(i) * 2;
10 END LOOP;
11 END Get_Array;
12 /
Procedure created.
Elapsed: 00:00:00.89
satyaki>
satyaki>
satyaki>Create or Replace Procedure Set_Array(myArray IN n_array)
2 is
3 i number(10);
4 rec emp%rowtype;
5 w n_array:=n_array(1200,3200);
6 bucket n_array := n_array();
7 Begin
8 Get_Array(w,bucket);
9
10 for i in 1..myArray.count
11 loop
12 select *
13 into rec
14 from emp
15 where empno = myArray(i);
16 dbms_output.put_line('Employee No:'||rec.empno||' Name:'||rec.ename);
17 for j in 1..bucket.count
18 loop
19 dbms_output.put_line('Commission Sub Type: '||bucket(j));
20 end loop;
21 end loop;
22 End Set_Array;
23 /
Procedure created.
Elapsed: 00:00:01.33
satyaki>
satyaki>
satyaki>select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
9999 SATYAKI SLS 7698 02-NOV-08 55000 3455 10
7777 SOURAV SLS 14-SEP-08 45000 3400 10
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 4450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 7000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
13 rows selected.
Elapsed: 00:00:00.28
satyaki>
satyaki>declare
2 v n_array:=n_array(9999,7777);
3 begin
4 Set_Array(v);
5 end;
6 /
Employee No:9999 Name:SATYAKI
Commission Sub Type: 2400
Commission Sub Type: 6400
Employee No:7777 Name:SOURAV
Commission Sub Type: 2400
Commission Sub Type: 6400
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.15
satyaki>
satyaki>Regards.
Satyaki De. -
How to pass a parameter into execute sql task and later use it into dataflow task?
i am in a situation, where i have a logging table in which i have a primary key called ETL_log_ID which is an identity column and acts as a foreign key for various fact table and dimension tables which are populated using SSIS packages. Now i wanna use the
ETL_log_ID as a parameter in the execute sql task which populates the log table and pass the same value in the data flow task which populates the facts and dimension. Can you let me know how to pass the parameter in a step by step procedure.
Thanks,
Nikhil
Nikhil,
You can check the following :
http://www.programmersedge.com/post/2013/03/05/ssis-execute-sql-task-mapping-parameters-and-result-sets.aspx
http://stackoverflow.com/questions/7610491/how-to-pass-variable-as-a-parameter-in-execute-sql-task-ssis
Regarding the usage in Dataflow task, Can you elaborate on that a little?
Thanks,
Jay
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'> -
How to test PL/SQL procedures and functions?
What are the proven ways to test pl/sql procedures and functions? Specifically, procedures and functions that take cursor variables as IN OUT parameter, OR procedure and functions that takes an array as IN parameter?
Thx.HI,
One way could by using PL/SQL Develper tool, see Tools/Test Manager...
Also there are others tools, see [Cleaning Up PL/SQL Practices|http://www.oracle.com/technology/oramag/oracle/04-mar/o24tech_plsql.html] and specifically oUnit
Regards,
PS: Your question is very general, could you provide an specific example you are trying?
Edited by: Walter Fernández on Nov 11, 2008 4:04 PM - Adding PS -
Updating the whole xml file in XMLType column
Hi ,
I am facing the problem in updating the XMLTYPE column.
I need to update the whole xml file
This is my table
SQL> desc EMPJAL_TABLE;
Name Null? Type
EMPLOYEEID NOT NULL VARCHAR2(140)
EMPCOM VARCHAR2(100)
EMPJAL SYS.XMLTYPE(XMLSchema "www.EMPSIM.com" Element "EMPJAL") STORAGE
Object-relational TYPE "EMPJAL_T"
I am able to form the CLOB object and trying to use this sql command
UPDATE EMPJAL_TABLE SET EMPJAL = XMLType( ? ) ) WHERE EMPLOYEEID ='emp1234';
Here I want to update the whole xmlfile in XMLTYPE column.
Error is - ORA-00933: SQL command not properly ended
Please advise
Thanks
GovindsHi Mark,
I apologise for this mistake. I am really putting lot of efforts and also worked/working in advance topics of XML DB.
Yes I am extensively using Oracle 10g r2 and suggesting others to use this
This time I had put more effort before posting ,I had a series of queries to resolve most of then were working , this was the one giving problem inside my java code
I am sorry for this .
Any how I made another query which works better.
Thanks
Govinda -
Revision: 15200
Revision: 15200
Author: [email protected]
Date: 2010-04-02 07:46:55 -0700 (Fri, 02 Apr 2010)
Log Message:
Update the build.xml to include contents under /resources/clustering/2.9.0
Modified Paths:
blazeds/branches/3.x/build.xmlRevision: 15200
Revision: 15200
Author: [email protected]
Date: 2010-04-02 07:46:55 -0700 (Fri, 02 Apr 2010)
Log Message:
Update the build.xml to include contents under /resources/clustering/2.9.0
Modified Paths:
blazeds/branches/3.x/build.xml -
Generating an xml from a pl/sql procedure
Hi Friends,
I have come up with a requirement to generate an xml from a pl/sql procedure.
I did some R & D and also got some sample procedures but could not understand the datatypes being used.
The procedure declares variables like this:
doc xmldom.DOMDocument;
mainNode xmldom.DOMNode;
headerElem xmldom.DOMElement; Pls could anyone tell what do these xmldom.DOMDocument, xmldom.DOMNode and xmldom.DOMElement mean?
Later in the procedure, these variables are assigned values like
doc := xmldom.newDOMDocument;
mainNode := xmldom.makenode(doc); This went a bouncer on me.
Pls help.
Thanks in advance ...!You can check this one -- Learned this from michael.
satyaki>
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
satyaki>
satyaki>
satyaki>with person_h
2 as
3 (
4 select 1 id, 'M' gender, 'W' race, '170' weight from dual union all
5 select 1, 'M', 'W', '170' from dual union all
6 select 1, 'M', 'W', '180' from dual union all
7 select 1, 'M', NULL, '175' from dual union all
8 select 1, NULL, 'W', NULL from dual
9 )
10 select xmlelement("Person",(
11 select xmlagg(xmlelement("Sex", gender))
12 from (
13 select distinct gender
14 from person_h
15 where id = 1
16 and gender is not null
17 ) pg
18 ),
19 (
20 select xmlagg(xmlforest(race as "Race"))
21 from (
22 select distinct race
23 from person_h
24 where id = 1
25 ) pg
26 ),
27 (
28 select xmlagg(xmlforest(weight as "Weight"))
29 from (
30 select distinct weight
31 from person_h
32 where id = 1
33 ) pg
34 )
35 ).getstringval() Res
36 from dual;
RES
<Person><Sex>M</Sex><Race>W</Race><Weight>170</Weight><Weight>175</Weight><Weight>180</Weight></Person>
satyaki>Regards.
Satyaki De. -
Unable to capture the parameter values from a PL/SQL procedure
hi.
i'm trying to capture the parameter values of a PL/SQL procedure by calling inside a anonymous block but i'm getting a "reference to uninitialized collection error" ORA-06531.
Please help me regarding.
i'm using following block for calling the procedure.
declare
err_cd varchar2(1000);
err_txt VARCHAR2(5000);
no_of_recs number;
out_sign_tab search_sign_tab_type:=search_sign_tab_type(search_sign_type(NULL,NULL,NULL,NULL,NULL));
cntr_var number:=0;
begin
rt843pq('DWS','3000552485',out_sign_tab,no_of_recs,err_cd,err_txt);
dbms_output.put_line('The error is ' ||err_cd);
dbms_output.put_line('The error is ' ||err_txt);
dbms_output.put_line('The cntr is ' ||cntr_var);
for incr in 1 .. OUT_SIGN_TAB.count
loop
cntr_var := cntr_var + 1 ;
Dbms_output.put_line(OUT_SIGN_TAB(incr).ref_no||','||OUT_SIGN_TAB(incr).ciref_no||','||OUT_SIGN_TAB(incr).ac_no||','||OUT_SIGN_TAB(incr).txn_type||','||OUT_SIGN_TAB(incr).objid);
end loop;
end;
Error is thrown on "for incr in 1 .. OUT_SIGN_TAB.count" this line
Following is some related information.
the 3rd parameter of the procedure is a out parameter. it is a type of a PL/SQL table (SEARCH_SIGN_TAB_TYPE) which is available in database as follows.
TYPE "SEARCH_SIGN_TAB_TYPE" IS TABLE OF SEARCH_SIGN_TYPE
TYPE "SEARCH_SIGN_TYPE" AS OBJECT
(ref_no VARCHAR2(22),
ciref_no VARCHAR2(352),
ac_no VARCHAR2(22),
txn_type VARCHAR2(301),
objid VARCHAR2(1024))............We don't have your rt843pq procedure, but when commenting that line out, everything works:
SQL> create TYPE "SEARCH_SIGN_TYPE" AS OBJECT
2 (ref_no VARCHAR2(22),
3 ciref_no VARCHAR2(352),
4 ac_no VARCHAR2(22),
5 txn_type VARCHAR2(301),
6 objid VARCHAR2(1024))
7 /
Type is aangemaakt.
SQL> create type "SEARCH_SIGN_TAB_TYPE" IS TABLE OF SEARCH_SIGN_TYPE
2 /
Type is aangemaakt.
SQL> declare
2 err_cd varchar2(1000);
3 err_txt VARCHAR2(5000);
4 no_of_recs number;
5 out_sign_tab search_sign_tab_type:=search_sign_tab_type(search_sign_type(NULL,NULL,NULL,NULL,NULL));
6 cntr_var number:=0;
7 begin
8 -- rt843pq('DWS','3000552485',out_sign_tab,no_of_recs,err_cd,err_txt);
9 dbms_output.put_line('The error is ' ||err_cd);
10 dbms_output.put_line('The error is ' ||err_txt);
11 dbms_output.put_line('The cntr is ' ||cntr_var);
12 for incr in 1 .. OUT_SIGN_TAB.count
13 loop
14 cntr_var := cntr_var + 1 ;
15 Dbms_output.put_line(OUT_SIGN_TAB(incr).ref_no||','||OUT_SIGN_TAB(incr).ciref_no||','||OUT_SIGN_TAB(incr).ac_no||','||OUT_SIGN
TAB(incr).txntype||','||OUT_SIGN_TAB(incr).objid);
16 end loop;
17 end;
18 /
The error is
The error is
The cntr is 0
PL/SQL-procedure is geslaagd.Regards,
Rob. -
I have recently updated the new apps via creative cloud now photoshop and bridge no longer work, they open then say they have encountered a problem and close, I also tried opening the old version of photo shop but getting the same result
What OS version? What's the exact error? Exactly when does the error occur? What previous versions? What is on the screen when the error displays? Does Photoshop get fully open?
Try opening Photoshop holding down Shift key immediately to turn off plug-ins. Lots of good suggestions here: Photoshop: Basic Troubleshooting steps to fix most issues -
I'm currently running ios 5 beta on my iphone 4 and when i woke up this morning my phone had decided to automatically update the software OTA. After connecting to wifi and switching on location i proceeded to follow the instructions 'slide to setup'. I was informed that it may take 3 minutes to activate phone but was then presented with the screen 'Could not Activate iphone', this is because the activation server is unavailable. Can anybody shed some light on this for me?
Many thanksCan anybody shed some light on this for me?
Not here. iOS5 beta is only available to registered developers, and discussing it publicly outside of the private developer forums is a violation of the non-disclosure agreement you signed to access the beta. -
I have Photoshop CS5.1 (bought in 2011). The photoshop Camera Raw plug-in is not recognizing the format of my new Nikon D610. I updated the version of my Camera Raw plug in and am still getting this message when trying to open images in photoshop. Please help.
This link shows that ACR 8.3 supports the Nikon D610 and 6.7.1 was the final version for CS5.
Camera Raw plug-in | Supported cameras
So you can upgrade to CS6 and ACR 8.7.1
or using the DNG converter, convert your Nikon raw files to dng format to open in CS5.
Here is the download link: Adobe - Adobe Camera Raw and DNG Converter : For Macintosh : Adobe DNG Converter 8.7.1
or Windows: Adobe - Adobe Camera Raw and DNG Converter : For Windows : Adobe DNG Converter 8.7.1
And here is a great video tutorial on how to use the converter.
https://www.youtube.com/watch?v=0bqGovpuihw
Gene -
family sharing. i have set my wife up on family sharing and each time we try to download a book or an app, we are requested that i update the payment details. I have done this and we still cannot share.. what do i do or how do i update the payment details to enable my wife to download
Drrhythm2 wrote:
What's the best solution for this? I
Copy the entire /Music/iTunes/ folder from her old compouter to /Music/ in her account on this new computer. -
Every time i connect my iphone to itunes and trying to do a backup or get the new update it says i have to restore my iphone. and then that doesnt work, i tried to reinstall itunes but it doesnt work. i get this all the time. fix it please.
iTunes states " There's a problem with your Iphone, please contact apple service center " Also i took my iphone to a local service man and he told me the IMEI code has been corrupted and there's nothing that can be done about it. Please help, if you have any solution.
Thank you -
Are the Pl/sql procedure and function atomic by themself
i want to ask a question does oracle pl/sql procedure and function support Atomicity for the database by themself , or they became atomic incase we call them using begin -- end;
You appear to be discussing transaction scope which is completely independent of PL/SQL blocks like procedures or how you call procedures. It's all in where commits (or rollbacks) are issued.
If you have a procedure like this
CREATE PROCEDURE p1
AS
BEGIN
INSERT INTO some_table( key, value ) VALUES( 1, 'Foo' );
INSERT INTO some_table( key, value ) VALUES( 1, 'Bar' );
END;where the first statement succeeds and the second statement fails as a result of a duplicate key, there will still be a Foo row in the table but the procedure will have thrown an exception. The caller of the procedure may choose to commit or rollback the change-- that will determine whether the first statement's results are made permanent. If you have a procedure like this,
CREATE PROCEDURE p1
AS
BEGIN
INSERT INTO some_table( key, value ) VALUES( 1, 'Foo' );
commit;
INSERT INTO some_table( key, value ) VALUES( 1, 'Bar' );
END;the commit will make the first insert permanent regardless of whether the second statement fails no matter what the calling code does (that's one reason that putting commits in stored procedures is generally a bad idea-- the caller is in a much better position to know what other uncommitted work has been done and whether it is safe to commit.
Justin -
Im using iphone 4 uk unlock , it has ios 4.2.1 and it does not have software update option.Now i want to update the phone with latest ios is it possible and tel me how ?
The update to iOS 5.0 & higher is an erase/restore deal, so make sure you follow the directions here to update your phone:
http://support.apple.com/kb/ht4972
iOS 7.0.4 will be installed.
Maybe you are looking for
-
I'm getting messages on Apple TV that netflix and the itunes store are currently unavailable. This can't be a coincidence. Also, the iTunes store is working fine on my Mac, the message is only on the apple TV. Does anyone come across this frequen
-
IWork '09 same regardless of which country it's purchased from?
If I buy iWork '09 from an Apple store in the United States, will it work on my MacBook Pro purchased in Canada, where I live and want to use it? And would the answer be different if I purchase the iWork somewhere else around the world, such as Franc
-
An error occurred validating your storage server credentials
an error occurred validating your storage server credentials
-
How to install and configure external drivers for JDBC and JMS adapters
Hi, In that thread: [JDBC Driver for Progress Database;, N V Seshagiri gave a link to a "How to" guide that is not available now... can anybody send me the .pdf file? I'm trying to install a JDBC driver (com.jnetdirect.jsql.JSQLDriver) with the visu
-
Responsibilities and duties of oracle apps functional consultant in support project
Dear Gurus and Experience apps functional consultants, Experienced apps functional consultants and Gurus, Please kindly tell me. " what are the complete set of responsibilities and duties of a oracle apps functional consultant in support project?" Th