Delete OPENQUERY Error

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!
Roxanne25Asked:
Who is Participating?
 
Roxanne25Connect With a Mentor Author Commented:
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
 
DcpKingCommented:
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
 
Roxanne25Author Commented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
DcpKingCommented:
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
 
Roxanne25Author Commented:
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
 
DcpKingCommented:
Ok. Thanks for telling us all the answer you found, so others can benefit!
0
 
Roxanne25Author Commented:
Changed the syntax of my query and resolved the issue.  Was not ideal, but solved the problem myself.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.