ORA-28576: lost RPC connection to external procedure agent

Posted on 2009-02-12
Last Modified: 2013-11-05
Hi All,

Hope someone can offer some advise here. I'm attempting to develop a routine in C (as a shared library) and then call this from PL/SQL. The code compiles (via gcc) and links (via ld) fine but when called from PL/SQL I get error "ORA-28576: lost RPC connection to external procedure agent"

I have narrowed the problem as outlined in the sample code below. With "i = strlen("ABCDE");" commented in, the routine works normally and in PL/SQL I get a value of 5. When I comment this line out and comment in  "i = strlen(tmp);" then the RPC error results.

I'm at a loss on this so would appreciate any help.

System Information
Redhat Enterprise Linux AS R3
GCC 3.2.3
Oracle 10g

C Library


#include <stdio.h>

int LCS(char *string1, char *string2)


       	int i;

        char tmp[6] = "ABCDE";

        // i = strlen(tmp); This does not work

	i = strlen("ABCDE"); // This works


	return i;


Oracle Library Declaration


create or replace library lcs_lib as '/oracle/Ora10103/bin/';



create or replace function 

lcs_function(p_str1 in varchar2, p_str2 in varchar2)

return pls_integer

as external library lcs_lib name "LCS" language c

parameters(p_str1 STRING, p_str2 STRING, return int);




	res pls_integer;

	v_str1 char(20);

	v_str2 char(20);



	v_str1 := 'aa';

	v_str2 := 'aaa';

	res := lcs_function(v_str1, v_str2);

	dbms_output.put_line('LCS Output is: ' || res);


Open in new window

Question by:MichaelOS
    LVL 47

    Expert Comment

    This means that the C type doesn't correspond the PL/SQL type.
    Try to clarify and possibly change VARCHAR2 with CHAR.
    LVL 47

    Expert Comment

    Also PL/SQL has a set of character functions. What is the purpose to use
    C for this? You have to use C for system programming and for complex
    calculations that are either impossible or run slow in PL/SQL.

    Author Comment


    I'm just testing at the moment. The plan is to rewrite relatively complex approximate string matching algorithms in C  that my company has developed in another language and to use these on the Oracle system. I'm aware that Oracle has character functions but these are not what I need.

    I've messed around with the sample code quite a bit so apologies if I have caused some confusion. The 2 string parameters are not being used at the moment. I have changed types to varchar2 without success. The fact that when "i = strlen("ABCDE");" is commented in and "i = strlen(tmp);" commented out the code works would suggest that the parameter types are fine. Reading documentation suggests there can be many causes as to the error I'm encountering. I feel that an exception is occuring in the C routine in the line "i = strlen(tmp);" and this is being raised as a lost RPC connection
    LVL 3

    Expert Comment

    I think you're right that the C library is aborting which causes an unexpected termination of the connection from the PL/SQL wrapper function.  My C is a little rusty, so please forgive me, but what if you try terminating the string with a null (\0)?  Perhaps strlen is giving you fits because it isn't sure about the end of the string it's trying to measure.

    Author Comment

    Thanks for the feedback. Yes, I already tried this using the code below and I still receive the error.

    char tmp[6];

    tmp[0] = 'A';
    tmp[1] = 'B';
    tmp[2] = 'C';
    tmp[3] = 'D';
    tmp[4] = 'E';
    tmp[5] = '\0';

    i = strlen(tmp);

    The weird thing is that this code works fine when called in a simple C program
    LVL 3

    Accepted Solution

    Maybe it has to do with the way the compile and link is playing out.  I tried your code on my Linux server and it worked iwthout a hitch, whether using the tmp variable or not.  Here's how I did it:

    cc -g -c -fPIC lcs_lib.c

    (the following is all on one line)
    make -f $ORACLE_HOME/rdbms/demo/ extproc_no_context OBJS=lcs_lib.o

    Author Closing Comment

    Many thanks for the feedback. I was not compiling with the -fPIC option. When I included this, the PL/SQL call worked. I've looked up the -fPIC option does but to be honest I'm not entirely sure how it resolved the issue I was having. Just to add I'm testing this on a Dell PowerEdge 1850 server with 2*64bit Xeon. Thanks again for the assistance.

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Join & Write a Comment

    Suggested Solutions

    Introduction A previously published article on Experts Exchange ("Joins in Oracle", makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
    How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
    Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
    This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now