2

I have an Oracle procedure called P_CREATE_USER. It takes a single varchar2 parameter:

create or replace PROCEDURE 
P_CREATE_USER (P_USERID varchar2)
...

I can run this from Oracle as EXEC P_CREATE_USER('MyUserId')

We have the Oracle server linked to our SQL Server.

I've tried:

EXECUTE('P_CREATE_USER(''MyUserId'')') AT ORACLE_SERVER

For my trouble, I get:

OLE DB provider "OraOLEDB.Oracle" for linked server "ORACLE_SERVER" returned message "ORA-00900: invalid SQL statement".
Msg 7215, Level 17, State 1, Line 1
Could not execute statement on remote server 'ORACLE_SERVER'.

I have tried a number of variants, using a space between P_CREATE_USER and the parameter instead of parenthesis. I've tried using @P_USERID=''MyUserId''. I have no problem running parameterless procedures this way, but I can't see to figure out how to pass a string...

Update: The UserId used for the linked server has permissions to run this procedure and can run it directly from Oracle. This is not a permissions issue. As best I can tell, the parameter is the only thing causing a problem.

5
  • Does the DB link on oracle has the grant permissions to execute this procedure? Commented Nov 19, 2013 at 16:56
  • Also, see if it helps you: dba-oracle.com/sf_ora_00900_invalid_sql_statement.htm Commented Nov 19, 2013 at 16:58
  • @JorgeCampos Yes, the userid used for the linked server has the necessary permissions. Commented Nov 19, 2013 at 19:14
  • So, it must be something related with the double quotes as mentioned on the link I provided you. Just to test. Create a procedure on oracle like this: create or replace procedure P_CREATE_USER_test as puserid varchar2(30):='MyUserId'; begin P_CREATE_USER(puserid); end; and call it from ms sql and see what happens. Commented Nov 19, 2013 at 19:19
  • @JorgeCampos I'm unsure what this is testing. As I already said in my post, I have no problem calling parameterless procedures. If this is merely to test whether or not I can call a parameterless procedure, I can. Commented Nov 19, 2013 at 19:38

1 Answer 1

3

The solution required checking the Dynamic Parameters property in the OraOLEDB.Oracle driver in SQL Server (Server Objects/Linked Servers/Providers/OraOLEDB.Oracle).

Then, to call the procedure, I had to do the following:

DECLARE @userid varchar(50)
SET @userid = 'MyUserId'
EXECUTE ('BEGIN P_CREATE_USER(?); END;', @userid) AT ORACLE_SERVER
Sign up to request clarification or add additional context in comments.

1 Comment

You should mark this as the answer. FWIW, I've also been able to call Oracle procedures using OUTPUT parameters. For instance, DECLARE @ReturnMessage varchar(255); EXECUTE ('BEGIN ORACLE_PROC(?);END;',@ReturnMessage OUTPUT) AT ORACLE_SERVER; PRINT @ReturnMessage

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.