Help on update statement in Apply DML Handler
I followed the example given in Streams document.
The document has the code for converting DELETE on the source to INSERT on the target. I added the dml handler code INSERT and UPDATE statements also.
In DELETE, INSERT, UPDATE dml handler code, I am setting the command type to 'INSERT' so that I can insert the data in the target table.
It is working fine for DELETE and INSERT statements.
When I do update on the source table,
I see only the value for the column I updated and all other columns are showing blank. May be this is the normal behaviour. How do I see the values for entire record. Do I need to join the source table based on the key column to get the data for the columns that were not updated.
Also, I thought I should at least see the values for key column and updated column in the target table. It only shows the value for updated column but not for key column. But, When I choosed the old values (I know we need new values, but I just did it for test purpose) in the UPDATE DML handler, it shows the values for key column and the updated column.
When I read the data in the LCR record using get_value('old', 'EMPLOYEE_ID') and get_value('NEW', 'FIRST_NAME')
for key column, it shows the value in both old and new. I do not understand why it is not inserting the key column value in the target table.
Thanks for your help in advance.
Best regards,
I forgot to mention these things.
We added supplmental logging using alter database add supplemental log data (primary key, unique index) columns;
I also added the supplemental logging on the source key column (employee_id) using ALTER TABLE emp ADD SUPPLEMENTAL LOG GROUP log_group_emp_pk (employee_id) ALWAYS;
I also set the key column on the target table using DBMS_APPLY_ADM.SET_KEY_COLUMNS.
Thanks for your help in advance.
Best regards,
Similar Messages
-
Need a help on Update statement
Hi All,
I Need a help in updating a table column. PFB my requirement.
Table1
ItemID OrgId Date
1 82 12/sep/2012
2 82 25/oct/2012
3 82 17/Nov/2012
4 82 22/Jan/2013
5 82 26/sep/2012
Table2
Itemid orgid Date1
1 82 23/sep/2012
2 82 25/Dec/2012
3 82 17/Sep/2012
4 82 22/Feb/2013
5 82 26/Oct/2012
Table3
Itemid orgid Date3
1 82 10/sep/2012
7 82 30/Dec/2012
3 82 12/Sep/2012
10 82 27/Feb/2013
5 82 29/Oct/2012
I Need to Update Date column of Table1 With Date3 of table3
If
Item and org combination is present in table3 and date column of table1 is less than Date3 of table3
Else
I need to Update with date2 of table2.Can we acheive this in a single update statement, can any one help me on this.
Thanks and regards,
Rakesh
Edited by: Venkat Rakesh on Sep 27, 2012 11:04 PMYou can probably also use MERGE:
--DROP TABLE table1;
--DROP TABLE table2;
--DROP TABLE table3;
ALTER SESSION SET nls_language = 'AMERICAN';
CREATE TABLE table1
itemid CHAR (1),
orgid CHAR (2),
thedate DATE
INSERT INTO table1 SELECT '1', '82', TO_DATE ('10/sep/2011', 'dd/mon/yyyy') FROM DUAL;
INSERT INTO table1 SELECT '2', '82', TO_DATE ('10/oct/2011', 'dd/mon/yyyy') FROM DUAL;
INSERT INTO table1 SELECT '3', '82', TO_DATE ('10/nov/2011', 'dd/mon/yyyy') FROM DUAL;
INSERT INTO table1 SELECT '4', '82', TO_DATE ('10/jan/2011', 'dd/mon/yyyy') FROM DUAL;
INSERT INTO table1 SELECT '5', '82', TO_DATE ('10/sep/2011', 'dd/mon/yyyy') FROM DUAL;-- won't be updated
CREATE TABLE table2
itemid CHAR (1),
orgid CHAR (2),
thedate DATE
INSERT INTO table2 SELECT '1', '82', TO_DATE ('01/sep/2012', 'dd/mon/yyyy') FROM DUAL;
INSERT INTO table2 SELECT '2', '82', TO_DATE ('01/dec/2012', 'dd/mon/yyyy') FROM DUAL;
INSERT INTO table2 SELECT '3', '82', TO_DATE ('01/sep/2012', 'dd/mon/yyyy') FROM DUAL;
INSERT INTO table2 SELECT '4', '82', TO_DATE ('01/feb/2012', 'dd/mon/yyyy') FROM DUAL;
CREATE TABLE table3
itemid CHAR (1),
orgid CHAR (2),
thedate DATE
INSERT INTO table3 SELECT '2', '82', TO_DATE ('30/dec/2009', 'dd/mon/yyyy') FROM DUAL; -- date less than table1, so picks from table2
INSERT INTO table3 SELECT '4', '82', TO_DATE ('30/mar/2013', 'dd/mon/yyyy') FROM DUAL; -- larger than table1 , so pick this date
-- table1 original data
SELECT * FROM table1;
-- merge new data
MERGE INTO table1
USING (SELECT NVL (t1.itemid, t2.itemid) itemid,
NVL (t1.orgid, t2.orgid) orgid,
t2.thedate prefdate ,
t1.thedate nextdate
FROM table2 t1
FULL OUTER JOIN
table3 t2
ON t1.itemid = t2.itemid AND t1.orgid = t2.orgid) dat
ON (dat.itemid = table1.itemid AND dat.orgid = table1.orgid)
WHEN MATCHED
THEN
UPDATE SET table1.thedate = (case when prefdate > table1.thedate then prefdate else nextdate end) ;
--table1 updated data
SELECT * FROM table1;OUTPUT:
Session altered.
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
Table created.
1 row created.
1 row created.
ITEMID ORGID THEDATE
1 82 10.09.2011
2 82 10.10.2011
3 82 10.11.2011
4 82 10.01.2011
5 82 10.09.2011
5 rows selected.
4 rows merged.
ITEMID ORGID THEDATE
1 82 01.09.2012
2 82 01.12.2012
3 82 01.09.2012
4 82 30.03.2013
5 82 10.09.2011
5 rows selected. -
Hi All,
I would like to create an update statement which produces the desired result(below) but find that the update statement I have created does not perform.
<pre>
CREATE TABLE RACE(
S_ID NUMBER,
D_PID VARCHAR2(15),
OCCURENCE NUMBER);
</pre>
<pre>
insert into RACE
values(1,'HYD01',null);
insert into RACE
values(2,'HYD01',null);
insert into RACE
values(3,'HYD01',null);
insert into RACE
values(4,'HYD02',null);
insert into RACE
values(5,'HYD02',null);
insert into RACE
values(6,'HYD03',null);
</pre>
<pre>
CREATE TABLE RACE_LOOKUP_CNT AS
select d_pid,count(s_id)occurence
from race
GROUP BY d_pid;
</pre>
--Need to update the RACE table as
S_ID DPID OCCURENCE
1 HYD01 3
2 HYD01 3
3 HYD01 3
4 HYD02 2
5 HYD02 2
6 HYD03 1
Tried this subquery but kept getting multiple rows update.
<pre>
update RACE c
set
c.occurence = (
select (a.occurence)
from RACE_LOOKUP_CNT a
where a.occurence in
select occurence
from RACE b
AND a.d_pid =c.d_pid);
</pre>
Thank you all.-Closed-
-
Need help with update statement with multiple joins
I've got the following select statement that is pulling 29 records:
SELECT
PPA.PROJECT_ID,
PPA.SEGMENT1,
peia.expenditure_item_id,
peia.expenditure_type,
pec.expenditure_comment
FROM PA.PA_PROJECTS_ALL PPA,
pa.pa_expenditure_items_all peia,
pa.pa_expenditure_comments pec
where PPA.segment1 < '2008' and
PPA.project_id = 52 and -- just run for project # 20077119 for testing
peia.expenditure_type = 'PAYROLL' and
peia.project_id = ppa.project_id and
PEC.EXPENDITURE_ITEM_ID = PEIA.EXPENDITURE_ITEM_ID;
I need to update the pec.expenditure_comments to a static field for those 29 records. I assume I should start with the following, but not sure how to complete the where:
update
pa.pa_expenditure_comments pec
set pec.expenditure_comment = 'REFERENCE HD#728'
where
First time that we've ever needed to update, so any and all help appreciated.Try using exists:
update pa.pa_expenditure_comments pec
set pec.expenditure_comment = 'REFERENCE HD#728'
where exists ( select null
from pa.pa_projects_all ppa
, pa.pa_expenditure_items_all peia
, pa.pa_expenditure_comments pec2
where ppa.segment1 < '' -- not sure what you posted here, so for next time:
-- please put your examples between the code tags.
and ppa.project_id = 52 -- just run for project # 20077119 for testing
and peia.expenditure_type = 'PAYROLL'
and peia.project_id = ppa.project_id
and pec2.expenditure_item_id = peia.expenditure_item_id
and pec2.expenditure_item_id = pec.expenditure_item_id
); -
Hi, Please help me on the following update scenario
I have a column in a table PRD_NM which is a not null column.. I want to update this column with a set of values from another query..
UPDATE Table1 tg
set PRD_NM=(select PRD_NM from( select prd_nm,state,item_no,bar_code from products) sr
where tg.state=sr.state and tg.item_no=sr.item_no and tg.bar_code=sr.bar_code
and tg.PRD_NM='NA')
basically i want to update all those PRD_NM with value 'NA' to the value coming from the source query...
but when I run the statement I am getting an error saying that the PRD_NM cannot be set to null... But here I am not considering anything that can be a null when updated.
Please help with any idea...
Edited by: user626688 on Jan 21, 2009 11:18 AMHi,
If you can't UPDATE via an in-line view (as Someoneelse suggested), and you don't want to basically do the same query twice (once in the scalar sub-query, then again in an EXISTS subquery, as in Someoneelse's next to last message), you can use MERGE:
MERGE INTO Table1 tg
USING ( SELECT prd_nm, state, item_no, bar_code
FROM products
) sr
ON ( tg.state = sr.state
AND tg.item_no = sr.item_no
AND tg.bar_code = sr.bar_code
AND tg.PRD_NM = 'NA'
WHEN MATCHED THEN
UPDATE SET tg.prd_nm = sr.prd_nm;Without copies of your tables and data, I can't test. -
hi,
how can i achieve the following logic
I have table ABC with column A varchar(20), B(int), C(varchar(20))
if A is null and B is valid number then C has to be updated with 'text'
if A is valid text and B is null then C has to be updated with 'number'
if A is valid text and B is valid number then C has to be updated with 'text-number'
thanks in advanceFirst Update
UPDATE ABC
SET C= 'text'
where A is null;since B is int data type it will always storeintegeres hence check not required.
Second Update
UPDATE ABC
set C = 'number'
where A is not null
and B IS NULLThird Update
UPDATE ABC
SET C = 'number-text'
WHERE A IS NOT NULL;Hope this answers.
You can get this in single update too
AND B IS NOT NULL -
Create table temp_sibs as
(select 1701 sib_1, 1702 sib_2 from dual
union all
select 1171,1172 from dual
union all
select 1701,1172 from dual
union all
select 1171,1174 from dual
union all
select 1173,1176 from dual
union all
select 2001,2004 from dual
union all
select 2001,2006 from dual
union all
select 2002,2006
from dual)
create table temp_sib_data as
(select 111 pid, 1701 sibid, 5 amt from dual
union all
select 111 pid, 1176 sibid, 5 from dual
union all
select 222 pid, 2006 sibid, 5 from dual
union all
select 333 pid, 2001 sibid, 5 from dual
union all
select 333 pid, 2002 sibid, 5 from dual
union all
select 333 pid, 1171 sibid, 5 from dual
First table is a lookup table that defines relationships sib_1 is related to sib_2
Second table consists of a column pid and column sibid which is either sib_1 or sib_2
The user would pass parameter pid and sibid and I want to update all the related rows with any matching sibid to 0.
It is like 1701 matches with 1702 and 1701 matches with 1174 so indirectly 1701 and 1174 match...and 1171 matches because
1171 matches with 1174
so all 1701,1702,1171,1172, 1173,1174,1176 match (indirectly with each other)
So for example if the user passes 333 pid and 2001 rows with 333,2001 and 333,2002 should update the amt to 0
and if the user passes 111 and 1176 than 1st 2 rows should be updated to 0.Hi,
try this:
DEFINE PID='333'
DEFINE sibid='2001'
-- SELECT is only for test.
-- Replace SELECT with: UPDATE TEMP_SIB_DATA SET AMT = 0
SELECT * FROM TEMP_SIB_DATA
WHERE PID = &PID AND SIBID IN (
WITH TEMP AS(
SELECT SIB_1, SIB_2 FROM TEMP_SIBS
START WITH SIB_1 = &&SIBID OR SIB_2 = &&SIBID
CONNECT BY NOCYCLE PRIOR SIB_2 = SIB_1
OR PRIOR SIB_1 = SIB_2
OR SIB_2 = PRIOR SIB_2
OR SIB_1 = PRIOR SIB_1
SELECT SIB_1 FROM TEMP
UNION ALL
SELECT SIB_2 FROM TEMP
);For pid=333 and sibid=2001 it returns desired records for update:
PID SIBID AMT
333 2001 5
333 2002 5For pid=111 and=1176 it returns one row - 1176 matches only with 1173 and 1173 doesn't match with any other rows,
so only 5th row, not first 2, should be updated ... maybe I missed something ?
PID SIBID AMT
111 1176 5 -
Update statement, with dups
This query has worked well for me, but now, the driving table (tt) has duplicates in it, because of a database upgrade and the client wants to keep the duplicates there is value to them there...
The problem is that now I get, you guessed it: ORA-01427: single-row subquery returns more than one row
I need help to update so that it can handle the more than one row, duplicates are ok.
UPDATE /*+ PARALLEL (16) */ UPDATE_TABLE_07092011 ta
SET (ta.GO_TO_PERSON, ta.UPDATE_DT) =
(SELECT /*+ PARALLEL (16) */ tt.GO_TO_PERSON, SYSDATE
FROM DRIVER_TABLE tt
WHERE ta.cust_id = tt.cust_id
AND ta.STAMP_DATE = tt.STAMP_DATE)
WHERE EXISTS (SELECT 1
FROM DRIVER_TABLE tt
WHERE ta.cust_id = tt.cust_id
AND ta.STAMP_DATE = tt.STAMP_DATE
AND (NVL(ta.GO_TO_PERSON, 'X') != NVL(tt.GO_TO_PERSON, 'X')));Edited by: Kodiak_Seattle on May 10, 2012 11:04 AMHow about adding "AND ROWNUM = 1" to the first subquery ?
-
DML Handler for update - need help
Hi,
I am trying a simple DML handler to INSERT all the column values in a target table (CHANNELS_DML)..which are sourced from an updated table (CHANNEL). Both of these tables are in the same database.
Here is the procedure I'm using for this purpose..
+++++++++++++++++
CREATE OR REPLACE PROCEDURE chn_dml_handler(in_any IN ANYDATA) IS
lcr SYS.LCR$_ROW_RECORD;
rc PLS_INTEGER;
command VARCHAR2(30);
old_values SYS.LCR$_ROW_LIST;
old_pk_val sys.anydata;
new_values SYS.LCR$_ROW_LIST := NULL;
BEGIN
rc := in_any.GETOBJECT(lcr);
command := lcr.GET_COMMAND_TYPE;
old_values := lcr.GET_VALUES('old');
new_values := lcr.GET_VALUES('new');
IF command = 'UPDATE' THEN
old_values := lcr.GET_VALUES('old','y');
lcr.SET_VALUES('new', old_values);
lcr.ADD_COLUMN('new', 'TIMESTAMP', ANYDATA.ConvertDate(SYSDATE));
lcr.ADD_COLUMN('new', 'OPERATION', ANYDATA.Convertvarchar2('UPDATE'));
lcr.SET_COMMAND_TYPE('INSERT');
lcr.SET_OBJECT_NAME('CHANNELS_DML');
ELSIF command = 'DELETE' THEN
lcr.SET_COMMAND_TYPE('INSERT');
lcr.SET_OBJECT_NAME('CHANNELS_DML');
lcr.SET_VALUES('new', old_values);
lcr.SET_VALUES('old', NULL);
lcr.ADD_COLUMN('new', 'TIMESTAMP', ANYDATA.ConvertDate(SYSDATE));
lcr.ADD_COLUMN('new', 'OPERATION', ANYDATA.Convertvarchar2('DELETE'));
ELSE
lcr.SET_COMMAND_TYPE('INSERT');
lcr.SET_OBJECT_NAME('CHANNELS_DML');
lcr.ADD_COLUMN('new', 'TIMESTAMP', ANYDATA.ConvertDate(SYSDATE));
lcr.ADD_COLUMN('new', 'OPERATION', ANYDATA.Convertvarchar2('INSERT'));
END IF;
lcr.EXECUTE(true);
END;
++++++++++++++++++++
INSERT, DELETE are working fine. However, when it comes to UPDATE I encounter "ORA-23605: invalid value "" for STREAMS parameter command_type".
Would appreciate, if you can point me to any missed steps!
Both source, target tables have the pk and supplemental logging is enabled for all the source tbl columns. (BTW, is it mandatory to enable supplemental logging ?)
Thanks,
SharasYou need to put this statement into IF 'UPDATE'
lcr.SET_VALUES('old', NULL);
old values in case of INSERT should be NULL.
You may want to use case instead of IF ELSEIF...
You might also have problems with LOBS... LOBs are not covered by this code. -
Help needed with Update statements.
Hello All,
I am trying to learn Berkeley XMLDB and facing problem to query the inserted XML file. I have a small XML file with the following contents:
<?xml version="1.0" standalone="yes"?>
<Bookstore>
<Book>
<book_ID>1</book_ID>
<title>Harry Potter and the Order of the Phoenix</title>
<subtitle>A Photographic History</subtitle>
<author>
<author_fname>J.K.</author_fname>
<author_lname>Rowling</author_lname>
</author>
<price>9.99</price>
<year_published>2004</year_published>
<publisher>Scholastic, Inc.</publisher>
<genre>Fiction</genre>
<quantity_in_stock>28997</quantity_in_stock>
<popularity>20564</popularity>
</Book>
</Bookstore>
When I try to update the TITLE of this node I have the following error message:
C:\Users\Chandra\Desktop\BDB>javac -classpath .;"C:\Program Files\Sleepycat Soft
ware\Berkeley DB XML 2.1.8\jar\dbxml.jar";"C:\Program Files\Sleepycat Software\B
erkeley DB XML 2.1.8\jar\db.jar" bdb.java
bdb.java:75: illegal start of expression
public static final String STATEMENT1 = "replace value of node collection("twopp
ro.bdbxml")/Bookstore/Book/bookid/title with 'NEWBOOK'";
^
bdb.java:80: ')' expected
System.out.println("Done query: " + STATEMENT1);
^
2 errors
But when I remove the update statements and just try to display the TITLE of this node, I dont see any outputs. Please help me to catch up with my mistakes. Below is source code I am using to run this functionality.
Thanks.
import java.io.File;
import java.io.FileNotFoundException;
import com.sleepycat.db.DatabaseException;
import com.sleepycat.db.Environment;
import com.sleepycat.db.EnvironmentConfig;
import com.sleepycat.dbxml.XmlContainer;
import com.sleepycat.dbxml.XmlException;
import com.sleepycat.dbxml.XmlInputStream;
import com.sleepycat.dbxml.XmlManager;
import com.sleepycat.dbxml.XmlUpdateContext;
import com.sleepycat.dbxml.XmlDocument;
import com.sleepycat.dbxml.XmlQueryContext;
import com.sleepycat.dbxml.XmlQueryExpression;
import com.sleepycat.dbxml.XmlResults;
import com.sleepycat.dbxml.XmlValue;
public class bdb{
public static void main(String[] args)
Environment myEnv = null;
File envHome = new File("D:/xmldata");
try {
EnvironmentConfig envConf = new EnvironmentConfig();
envConf.setAllowCreate(true); // If the environment does not
// exits, create it.
envConf.setInitializeCache(true); // Turn on the shared memory
// region.
envConf.setInitializeLocking(true); // Turn on the locking subsystem.
envConf.setInitializeLogging(true); // Turn on the logging subsystem.
envConf.setTransactional(true); // Turn on the transactional
envConf.setRunRecovery(true);
// subsystem.
myEnv = new Environment(envHome, envConf);
// Do BDB XML work here.
} catch (DatabaseException de) {
// Exception handling goes here
} catch (FileNotFoundException fnfe) {
// Exception handling goes here
} finally {
try {
if (myEnv != null) {
myEnv.close();
} catch (DatabaseException de) {
// Exception handling goes here
XmlManager myManager = null;
XmlContainer myContainer = null;
// The document
String docString = "D:/xmldata/test.xml";
// The document's name.
String docName = "cia";
try {
myManager = new XmlManager(); // Assumes the container currently exists.
myContainer =
myManager.createContainer("twoppro.bdbxml");
myManager.setDefaultContainerType(XmlContainer.NodeContainer); // Need an update context for the put.
XmlUpdateContext theContext = myManager.createUpdateContext(); // Get the input stream.
XmlInputStream theStream =
myManager.createLocalFileInputStream(docString); // Do the actual put
myContainer.putDocument(docName, // The document's name
theStream, // The actual document.
theContext, // The update context
// (required).
null); // XmlDocumentConfig object
theStream.delete();
// Update the title
public static final String STATEMENT1 = "*replace value of node collection("twoppro.bdbxml")/Bookstore/Book/[bookid=1]/title with 'NEWBOOK'";*
XmlQueryContext context = myManager.createQueryContext();
XmlQueryExpression queryExpression1 = myManager.prepare(STATEMENT1, context);
System.out.println("Try to execute query: " +
System.out.println("Done query: " + STATEMENT1);
queryExpression1.execute(context);
// Get a query context
XmlQueryContext context = myManager.createQueryContext();
// Set the evaluation type to Lazy.
context.setEvaluationType(XmlQueryContext.Lazy);
// Declare the query string
String queryString =
"for $u in collection('twoppro.dbxml')/Bookstore/Book/[bookid=1]"
+ "*return $u/title";*
// Prepare (compile) the query
XmlQueryExpression qe = myManager.prepare(queryString, context);
XmlResults results = qe.execute(context);
System.out.println("ok");
System.out.println(results);
} catch (XmlException e) {
// Error handling goes here. You may want to check
// for XmlException.UNIQUE_ERROR, which is raised
// if a document with that name already exists in
// the container. If this exception is thrown,
// try the put again with a different name, or
// use XmlModify to update the document.
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (myContainer != null) {
myContainer.close();
if (myManager != null) {
myManager.close();
} catch (XmlException ce) {
// Exception handling goes hereThanks Rucong. The change you suggested did helped me to run the program correct. But I also have the display function to retrive the results and my program is parsed without any output.
C:\Users\C\Desktop\BDB>Clientbuild.bat
C:\Users\C\Desktop\BDB>javac -classpath .;"C:\Program Files\Sleepycat Soft
ware\Berkeley DB XML 2.1.8\jar\dbxml.jar";"C:\Program Files\Sleepycat Software\B
erkeley DB XML 2.1.8\jar\db.jar" bdb.java
C:\Users\C\Desktop\BDB>Client.bat
C:\Users\C\Desktop\BDB>java -classpath .;"C:\Program Files\Sleepycat Softw
are\Berkeley DB XML 2.1.8\jar\dbxml.jar";"C:\Program Files\Sleepycat Software\Be
rkeley DB XML 2.1.8\jar\db.jar" bdb
See there is no OUPUT displayed. Is there somethinglike a 'print' I have to use in this java code.
Any ideas ? Below is the code I am using now
import java.io.File;
import java.io.FileNotFoundException;
import com.sleepycat.db.DatabaseException;
import com.sleepycat.db.Environment;
import com.sleepycat.db.EnvironmentConfig;
import com.sleepycat.dbxml.XmlContainer;
import com.sleepycat.dbxml.XmlException;
import com.sleepycat.dbxml.XmlInputStream;
import com.sleepycat.dbxml.XmlManager;
import com.sleepycat.dbxml.XmlUpdateContext;
import com.sleepycat.dbxml.XmlDocument;
import com.sleepycat.dbxml.XmlQueryContext;
import com.sleepycat.dbxml.XmlQueryExpression;
import com.sleepycat.dbxml.XmlResults;
import com.sleepycat.dbxml.XmlValue;
public class bdb{
public static void main(String[] args)
Environment myEnv = null;
File envHome = new File("D:/xmldata");
try {
EnvironmentConfig envConf = new EnvironmentConfig();
envConf.setAllowCreate(true); // If the environment does not
// exits, create it.
envConf.setInitializeCache(true); // Turn on the shared memory
// region.
envConf.setInitializeLocking(true); // Turn on the locking subsystem.
envConf.setInitializeLogging(true); // Turn on the logging subsystem.
envConf.setTransactional(true); // Turn on the transactional
envConf.setRunRecovery(true);
// subsystem.
myEnv = new Environment(envHome, envConf);
// Do BDB XML work here.
} catch (DatabaseException de) {
// Exception handling goes here
} catch (FileNotFoundException fnfe) {
// Exception handling goes here
} finally {
try {
if (myEnv != null) {
myEnv.close();
} catch (DatabaseException de) {
// Exception handling goes here
XmlManager myManager = null;
XmlContainer myContainer = null;
// The document
String docString = "D:/xmldata/test.xml";
// The document's name.
String docName = "cia";
try {
myManager = new XmlManager(); // Assumes the container currently exists.
myContainer =
myManager.createContainer("twoppro.bdbxml");
myManager.setDefaultContainerType(XmlContainer.NodeContainer); // Need an update context for the put.
XmlUpdateContext theContext = myManager.createUpdateContext(); // Get the input stream.
XmlInputStream theStream =
myManager.createLocalFileInputStream(docString); // Do the actual put
myContainer.putDocument(docName, // The document's name
theStream, // The actual document.
theContext, // The update context
// (required).
null); // XmlDocumentConfig object
theStream.delete();
// Update the title
String STATEMENT1 = "for $n in collection('twoppro.bdbxml')/Bookstore/Book[book_ID=1]/title return replace value of node $n with 'NEWBOOK'";
XmlQueryContext context = myManager.createQueryContext();
XmlQueryExpression queryExpression1 = myManager.prepare(STATEMENT1, context);
System.out.println("Done query: " + STATEMENT1);
queryExpression1.execute(context);
// Get a query context
XmlQueryContext thiscontext = myManager.createQueryContext();
// Set the evaluation type to Lazy.
context.setEvaluationType(XmlQueryContext.Lazy);
// Declare the query string
String queryString =
"for $u in collection('twoppro.dbxml')/Bookstore/Book/[bookid=1]"
+ "return $u/title";
// Prepare (compile) the query
XmlQueryExpression qe = myManager.prepare(queryString, thiscontext);
XmlResults results = qe.execute(thiscontext);
System.out.println("ok");
System.out.println(results);
} catch (XmlException e) {
// Error handling goes here. You may want to check
// for XmlException.UNIQUE_ERROR, which is raised
// if a document with that name already exists in
// the container. If this exception is thrown,
// try the put again with a different name, or
// use XmlModify to update the document.
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (myContainer != null) {
myContainer.close();
if (myManager != null) {
myManager.close();
} catch (XmlException ce) {
// Exception handling goes here
Thanks. -
How to update a column value by comparing old value by using DML Handler...
Hi Can anyone post the DML Handler code for updating a column value by comparing the old value.
Thanks,
RayHi,
Here is an example of a DML handler.
BEGIN
DBMS_APPLY_ADM.SET_DML_HANDLER(
object_name => 'scott.emp',
object_type => 'TABLE',
operation_name => 'UPDATE',
error_handler => false,
user_procedure => 'strmadmin.update_column',
apply_database_link => NULL,
apply_name => 'MY_APPLY');
END;
This DML handler which will send any LCR matching the specified conditions to the strmadmin.update_column for customised processing.
You can write the strmadmin.update_column procedure so that it extracts the old values from the LCR. You can then use the old values from the LCR to identify the row in the table. Once you identify the row, you can update it as you want.
I haven't really tried to do any customised processing using DML handlers, but this should work.
Hope this is of help.
Sujoy -
Need help to write a query for Update statement with join
Hi there,
The following update statement gives me error as the given table in set statement is invalid. But its the right table .
Is the statement correct? Please help .
update (
select distinct(vpproadside.VEHICLE_CRED_OVERRIDE.vin)
from vpproadside.VEHICLE_CRED_OVERRIDE
join vpproadside.vpp_vehicle
on vpproadside.vpp_vehicle.vin = vpproadside.VEHICLE_CRED_OVERRIDE.vin
where VPP_CARRIER_SEQ_NUMBER = 90
and EXPIRY_DATE = '17-MAR-10'
set vpproadside.VEHICLE_CRED_OVERRIDE.EXPIRY_DATE = '15-SEP-10';Edited by: Indhu Ram on Mar 12, 2010 1:00 PM
Edited by: Indhu Ram on Mar 12, 2010 1:22 PM
Edited by: Indhu Ram on Mar 12, 2010 2:35 PM
Edited by: Indhu Ram on Mar 15, 2010 8:04 AM
Edited by: Indhu Ram on Mar 15, 2010 8:06 AM
Edited by: Indhu Ram on Mar 15, 2010 8:28 AMAsk Tom has very good discussion about this, if UPDATE does not work for PK issue, you can use MERGE
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:760068400346785797 -
DML Error logging for Update statement
Hello,
I am facing a problem with regard to DML Error logging with Update statement .
oracle : 10.2
I am executing following DML update:
BEGIN
UPDATE
table_1 a
SET a.Exp_DATE =a.EFF_DATE
WHERE a.col_a1 != (SELECT b.colb1
FROM table_2 b
WHERE a.msisdn =b.msisdn )
LOG ERRORS INTO table_1_ERR REJECT LIMIT UNLIMITED;
END ; I was expecting that "ORA-01427: single-row subquery returns more than one row" would be captured in LOG error table "table_1_err"
but instead I got run time error and whole dml was rolled back.
Please let me know whether this exception is not captured by DML error logging.
Thanks,
Abhishek*Oracle logs the following errors during DML operations:** Column values that are too large.
* Constraint violations (NOT NULL, unique, referential, and check constraints).
* Errors raised during trigger execution.
* Errors resulting from type conversion between a column in a subquery and the corresponding column of the table.
* Partition mapping errors.
>
http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/transform.htm#sthref777 -
How to use a update statement which has a string containing '&' - Pls help
When used the following select statment in SQL plus it is working fine:
SELECT * FROM REDEMPTION_OFFERS
WHERE portfolio=203 AND display_description= '$100 Bed Bath'||' & '||'Beyond Gift Card' AND ext_redemption_type_lc = 'ERT_CERT'
But when using the same statement in a Update statement it is not working. Can some one please help me: Thanks in advance
UPDATE REDEMPTION_OFFERS SET LONG_DESCRIPTION = 'null'
WHERE portfolio=203 AND display_description= '$100 Bed Bath'||' & '||'Beyond Gift Card' AND ext_redemption_type_lc = 'ERT_CERT'When used the following select statment in SQL plus
it is working fine:
SELECT * FROM REDEMPTION_OFFERS
WHERE portfolio=203 AND display_description= '$100
Bed Bath'||' & '||'Beyond Gift Card' AND
ext_redemption_type_lc = 'ERT_CERT'
But when using the same statement in a Update
statement it is not working. Can some one please
help me: Thanks in advance
UPDATE REDEMPTION_OFFERS SET LONG_DESCRIPTION =
'null'
WHERE portfolio=203 AND display_description= '$100
Bed Bath'||' & '||'Beyond Gift Card' AND
ext_redemption_type_lc = 'ERT_CERT'looks like You are using the UPDATE statement in SQL*PLUS too. Your statement is also working....
SQL> select * from a;
F1 F2 F3
1 BED BATH
2 BED BATH
5 BED BATH
3 BED BATH
-2 BED BATH
-4 BED BATH
-1 BED BATH
7 rows selected.
SQL> update a set f3 = 'BED '||'&'||' BATH';
7 rows updated.
SQL> select * from a;
F1 F2 F3
1 BED & BATH
2 BED & BATH
5 BED & BATH
3 BED & BATH
-2 BED & BATH
-4 BED & BATH
-1 BED & BATH
7 rows selected. -
Sender JDBC: help to construct Update statement
Hi,
I need help in writing a update statement to DB2 database in sender JDBC adapter.
The sender adapter picks up only few records say 10 at a time which match the Select query condition. So I would need to update only those selected "n" records and not all the records that match the Select query condition.
Select looks like :
Select * from <table> where <condition> fetch first <n> rows only.
But it is not allowing the following update
update <table> set <field> = <value> where <field> IN (Select * from <table> where <condition> fetch first <n> rows only)
The above statement errors because DB2 does not allows u201CFetchu201D statement within the update sub query.
Any pointers to a write update statement for n records is highly appreciatedu2026
~SaNvu2026Hi Santosh,
In JDBC Sender Adapter provide the following select & update statements
Select Statement:
select * from <table> where <condition> AND ROWNUM<N (N==No.of Rows)
Update Statement:
update <table> set <field> = <value> where <field> IN (Select * from <table> where <condition> AND ROWNUM<N)
(N==No.of Rows)
And for the error you are facing is because of the server communication link failure between the two systems.
Check the connections and try to stop & start communication channels once.
Regards
Venkat Rao .G
Maybe you are looking for
-
GR/IR clearing account not having cleared document
Hi Friends, In FBL3N, Against GR/IR (160224) clearing account, is it mandatory to have clearing document against each line items. MIGO and MIRO done. client is asking for some line items it's showing cleared doc, for some line items's it's not update
-
NEED HELP, old hard disk failed, new hard disk not detected.
My hard disk died, not working, not detected when I restart with the MacOS X DVD and attempt to reinstall. I have bought a new hard drive, 160 GB ATA - IDE Samsung drive, and carefully replaced it following service manual instructions. All connectors
-
PROBLEM USING FILTER TO KNOW SESSION EXPIRATION
Hi, i'm using a filter to know when the session expires but it appeasr not to work, so i am a bit confuse because the filter always executes well but when the session gets the timeout and the user send a request it isnt executed, the server redirects
-
Hi All, Our client has a requirement for approval of travel expenses. The employee's manager approves the travel request which is raised by the employee. 1.Just in case an employee's manager is absent, the provision for a substitution should be explo
-
ITunes messed up my songs everytime i connect my iPhone
Hi, I am using a Windows 8 laptop and I have iTunes 11.0 Installed, i use this laptop to sync with my iPhone 5 (running iOS 6.0.2) which i don't really do alot. But when i'm just connecting the iPhone to the laptop just to charge the battery, iTunes