Calling oracle function using database link

Kapila Witharana picture Kapila Witharana · May 5, 2011 · Viewed 27.4k times · Source

I have created a oracle function called getEmployee(id in varchar) in my remote database and I'm trying to call it from my local database using database link.

In getEmployee, I'm trying to return a cursor with employee data.(Table: Employee (ID, Name, address)):

SELECT schema.getEmployee@dblink(id) 
  FROM DUAL;

How can I get the result set with column name (ID, Name, address)?

According to Contrad, I changed my local function like this;

FUNCTION LocalGetEmployee(ID in varchar2)
RETURN Schema.SomeRefCursor
AS  

OUTPUT Schema.SomeRefCursor;

BEGIN 

  OUTPUT := schema.getEmployee@dblink(ID);

  RETURN OUTPUT;
END;  

But, when I call this function from Java Code, the following error is raised:

"ORA-24338: statement handle not executed"

Answer

Andrew picture Andrew · Oct 17, 2011

Fetching the Ref Cursor at Remote site:

Let’s say we have two sites involved in Distributed transaction, Server1 and Server2. The Ref Cursor opened on Server1 procedure, cannot be fetched at Server2 site. If we try to fetch this cursor oracle raises an exception:

[ORA-02055: distributed update operation failed; rollback required
 ORA-24338: statement handle not executed]

“We cannot use the Ref Cursor over DBLink”

Solutions:

  1. Use PL-SQL Data table. OR
  2. Provide select grant and use select command over DBLink from initiator site instead of opening the Cursor.

Source: Distributed transaction in Oracle (Over Oracle DBLink)