?
Solved

Delete OPENQUERY Error

Posted on 2013-10-30
7
Medium Priority
?
906 Views
Last Modified: 2013-11-05
Hello, I am trying to run the following delete statement:

DELETE OPENQUERY(oraclelinkedserver,'SELECT A.* FROM SCHEMAA.TABLE1 A LEFT JOIN SCHEMAB.TABLE2 B ON A.DODIC = B.DODIC AND B.STATUS = ''C'' WHERE B.DODIC IS NULL')

The linked server is an Oracle 11g server and I am running SQL Server 2008 R2.  

I can do other simple delete openqueries but I can't figure out if its just the join it doesn't like or the naming conventions... I have tried changing the select list to be just the fields from table A but of course it doesn't like that cause the dodic field exists in both tables.

This is the error message:
OLE DB provider "OraOLEDB.Oracle" for linked server "oraclelinkedserver" returned message "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.".
Msg 7345, Level 16, State 1, Line 1

Any ideas?  Thanks!
0
Comment
Question by:Roxanne25
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 16

Expert Comment

by:DcpKing
ID: 39613254
Directly; make sure table1 and table2 have unique indexes, and is schemaa.table1 sufficient, or can you be more "precise"? Rather like using server.database.schema.table in ordinary T-SQL.

Indirectly; write a stored procedure on the Oracle side and run that from the SQL Server side. in the end it might be a lot easier!

hth

Mike
0
 

Author Comment

by:Roxanne25
ID: 39613260
I am unable to make sure they have indexes... I have limited permissions on this Oracle database.  With an openquery, the server is already specified and yes the syntax for the tables is correct.  I can run the exact query as a select statement just not a delete.  

I also would be unable to write a stored procedure in Oracle... The only access I have to these tables is via the linked server or Oracle SQL Plus directly.  They are external tables we are responsible for updating in another system.  

I can also run the delete statement directly in Oracle just fine... I'm assuming it has to do with the capabilities of openquery ...

My only other alternative is to just write it like a normal SQL statement in SQL Server using linkedservername..schema.table but it will be incredibly slow and inefficient.  

:(
0
 
LVL 16

Expert Comment

by:DcpKing
ID: 39613265
If "they" (the owners of the other system) are willing to let you delete data from their tables then I would have thought that they would have been delighted to spend 5 minutes or so writing a stored procedure you could run so they would know that you weren't deleting the wrong things!  <grin> !

I'd say ask about the indexes. More than that I don't know - sorry!

Mike
0
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 

Author Comment

by:Roxanne25
ID: 39613934
You would think so.... ;)  but "they" don't even know how their database works most of the time.  That's the government for ya.... ;)  They ask me a lot of the time how stuff works and I always have to tell them if they have a data load that failed (cause the table is empty or something) and then they are like ummmm ... which table?  *eyeroll*
0
 

Accepted Solution

by:
Roxanne25 earned 0 total points
ID: 39614117
Well, I guess I fixed it .... its not what I wanted but at least it works.  I changed the query so its not a join and uses a not in (select) instead.

delete openquery(linkedserver, 'select * FROM table1
WHERE dodic not in (select dodic from table2
where table2.dodic is not null and table2.status not in ('T', 'H', 'Q'))')

So, I guess openqueries just can't perform joins in a delete statement.

Thank you for trying to help though. :)
0
 
LVL 16

Expert Comment

by:DcpKing
ID: 39614353
Ok. Thanks for telling us all the answer you found, so others can benefit!
0
 

Author Closing Comment

by:Roxanne25
ID: 39623766
Changed the syntax of my query and resolved the issue.  Was not ideal, but solved the problem myself.
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question