Home » SQL & PL/SQL » SQL & PL/SQL » To log the row in error while selecting from database (Oracle 10g)
To log the row in error while selecting from database [message #623242] Sun, 07 September 2014 05:16 Go to next message
gopal.biswal
Messages: 11
Registered: October 2013
Location: Pune
Junior Member
With dml error logging, we can add a clause to our bulk DML statements (INSERT, UPDATE, MERGE and DELETE) to prevent the statement failing on hitting exceptions (i.e. "bad data"). Exceptional rows are added to a specifically-created errors table for investigation and/or intervention. As per my understanding there is no such feature in Oracle in which case a long running query(bulk select) returning more than one row to continue in stead of failing whenever it finds some error in one row. In this case the whole query fails though we have one row in error. Per example a query returning thousands rows fail whenever one row fails due to bad data in one date field. So in this case, the only way to handle this is to process query row by row. Wondering is there any built in approach to log the row in error while fetching rows from database just like we have DML error logging to log the rows in exception.
Re: To log the row in error while selecting from database [message #623243 is a reply to message #623242] Sun, 07 September 2014 06:26 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
whenever one row fails due to bad data in one date field.


There is no bad data in a field unless you didn't do your job to prevent from any bad data being inserted, for instance creating a field as varchar2 or number when it will record dates.
So the culprit if this happens is you not the rdbms.
And this is why the rdbms does not implement such useless and irrelevant (for itself) thing.

Re: To log the row in error while selecting from database [message #623244 is a reply to message #623243] Sun, 07 September 2014 06:35 Go to previous messageGo to next message
gopal.biswal
Messages: 11
Registered: October 2013
Location: Pune
Junior Member
Unfortunately we get this bad data in the form of XML from upstream system in which we don't have control.
Re: To log the row in error while selecting from database [message #623245 is a reply to message #623244] Sun, 07 September 2014 07:14 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
And what do you do with XML? You just select from it or your goal is to populate some table with data from that XML?

SY.
Re: To log the row in error while selecting from database [message #623247 is a reply to message #623244] Sun, 07 September 2014 08:07 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
gopal.biswal wrote on Sun, 07 September 2014 13:35
Unfortunately we get this bad data in the form of XML from upstream system in which we don't have control.


And what prevent you from checking the XML data before inserting it in a table?

Re: To log the row in error while selecting from database [message #623250 is a reply to message #623247] Sun, 07 September 2014 08:20 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Unfortunately we get this bad data in the form of XML from upstream system in which we don't have control.

why do you blindly load bad data into the database?
Modify the load procedure to filter out the bad data.
Re: To log the row in error while selecting from database [message #623303 is a reply to message #623250] Mon, 08 September 2014 03:10 Go to previous messageGo to next message
gopal.biswal
Messages: 11
Registered: October 2013
Location: Pune
Junior Member
Yes you are correct, we should have filtered out the data before loading.However,due to poor design of application, the data was not filtered loaded in to table. The XMLTYPE column MESSAGE in CONTRACT_MSG_DETAIL contains the XML data.

Now, we are doing a one time migration activity of already loaded data in CONTRACT_MSG_DETAIL

We are using XMLTABLE to query the XML data. For some records for any of column (COL1,COL2,COL3), data length exceeds more than 4000 and we receive this error ORA-01706: user function result value was too large. We could use CLOB in stead of VARCHAR2 but this might affects the performance.

SELECT A.MSG_ID, B.PRODUCT_ID, C.*
                      FROM CONTRACT_MSG_DETAIL A,
                           CONTRACT_MSG_INFO B,
                           XMLTABLE (
                              '//MxML/trades/trade[2]'
                              PASSING MESSAGE
                              COLUMNS COL1 VARCHAR2 (4000)
                                            PATH 'tradeBody/interestRateSwap/stream[1]/capital/initialCapitalAmount/text()',
                                      COL21  VARCHAR2 (4000)
                                            PATH 'tradeBody/interestRateSwap/stream[1]/capital/initialCapitalCurrency/text()',
                                      COL31 VARCHAR2 (4000)
                                            PATH 'tradeBody/interestRateSwap/stream[1]/floatingRateStream/margin/text()') C
                     WHERE     a.MSG_ID = B.MSG_ID
                           AND B.PRODUCT_ID IN
                                  (1014)
                           AND B.EVENT_ID IN (6123, 6111)
                           AND B.IS_LATEST_VERSION = 'Y';


Regards;
Gopal


Lalit : Added code tags.
Please do it yourself in future, read How to use [code] tags

[Updated on: Mon, 08 September 2014 03:30] by Moderator

Report message to a moderator

Re: To log the row in error while selecting from database [message #623304 is a reply to message #623245] Mon, 08 September 2014 03:13 Go to previous messageGo to next message
gopal.biswal
Messages: 11
Registered: October 2013
Location: Pune
Junior Member
Our goal is to SELECT those from one table and populate in another table. The SELECT fails when one of the record contains bad data.
Re: To log the row in error while selecting from database [message #623305 is a reply to message #623303] Mon, 08 September 2014 03:14 Go to previous message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
So fix the bad data in the DB or write a query that pre-emptively skips the problem records.
I'd go with the first option since you are presumably going to have to do that sooner or later.
Previous Topic: Getting only the first occurrence of the sub string in the given string
Next Topic: ORDER BY gives good performance or INDEX hint gives good performance.
Goto Forum:
  


Current Time: Thu Apr 18 20:08:01 CDT 2024