AllExperts > Experts 
Search      

Oracle

Volunteer
Answers to thousands of questions
 Home · More Questions · Answer Library  · Encyclopedia ·
More Oracle Answers
Question Library

Ask a question about Oracle
Volunteer
Experts of the Month
Expert Login

Awards

About Us
Tell friends
Link to Us
Disclaimer

 
 
 
 
About Suchitra Joshi
Expertise
I can answer questions regarding SQL, PL/SQL, Procedures, Functions, Triggers, SQL Loader and some basic dba activities or performance tuning for Oracle 8i database. I cannot answer questions related to major dba activities, backup and recovery.

Experience
10+ years
D2K

Awards and Honors
OCP - SQL and PL/SQL
Brainbench certifications in Oracle Administration, Database, PL/SQL

 
   

You are here:  Experts > Computing/Technology > Oracle > Oracle > Calling SQL Stored procedure from PLSQL function

Topic: Oracle



Expert: Suchitra Joshi
Date: 6/11/2008
Subject: Calling SQL Stored procedure from PLSQL function

Question
Hi,



I have created a simple PLSQL function to return a value that is pulled back from SQL server.



******************************************************
Oracle Function
******************************************************
CREATE OR REPLACE FUNCTION TEMP_ORACLE_FUNCTION ( i_param IN VARCHAR2
)
RETURN NUMBER
IS
tmp_result NUMBER;
BEGIN
"dbo"."TempSQLSP"@PLCSQL.PLCOADM(i_param,tmp_result);
RETURN tmp_result;
END TEMP_ORACLE_FUNCTION;

******************************************************
SQL Server Stored Procedure
******************************************************
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[TempSQLSP]
(
@InParam varchar(50),
@OutParam INT OUTPUT
)
AS
BEGIN
IF @InParam = 'OADM'
select @OutParam = 1
ELSE
select @OutParam = 0
END

******************************************************
Execution
******************************************************
SELECT TEMP_ORACLE_FUNCTION('OADM') FROM dual;


I am expecting an output as 1. But unfortunately i get the error
ORA-06571: Function TempSQLSP does not guarantee not to update database.

Any input will be greatly appreciated.



Thanks,

Shashi



PS: I am using the DB Link (@PLCSQL.PLCOADM) setup using DG4MSQL - link between oracle and sql server database.


Answer
Hi Shashi,

I am not quite sure of this. But you can try writing a packaged function as follows -

CREATE OR REPLACE PACKAGE my_pkg AS

 FUNCTION my_func(arg1 IN NUMBER) RETURN VARCHAR2;

 PRAGMA RESTRICT_REFERENCES(my_func, RNPS, WNPS, WNDS);

END my_pkg;


Then use

select my_pkg.my_func(..) from ...


Hope this helps

Regards

Suchitra

Add to this Answer    Ask a Question



  Rate this Answer
   Was this answer helpful?
Not at allDefinitely              
   12345  

     
About Us | Advertise on This Site | User Agreement | Privacy Policy | Help
Copyright  © 2008 About, Inc. About and About.com are registered trademarks of About, Inc. The About logo is a trademark of About, Inc. All rights reserved.