views:

1076

answers:

2

Has anyone seen this error when trying to call an external C function from an Oracle query? I'm using Oracle 10g and get this error every time I try to call one of the two functions in the library. A call to the other function returns fine every time, though the function that works is all self-contained, no calls to any OCI* functions.

Here's the stored procedure that is used to call the failing C code:

CREATE OR REPLACE PROCEDURE index_procedure(text in clob, tokens in out nocopy clob, location_needed in boolean)
as language c
name "c_index_proc"
library lexer_lib
with context
parameters
(
  context,
  text,
  tokens,
  location_needed
);

Any help would be appreciated. Everything I've found on this error message says that the action to take is: Contact Oracle customer support.

Edit: I've narrowed it down to the point that I know that there is a segfault deep in libclntsh after I call OCILobTrim (to truncate it down to 0 length) on the tokens clob. Here is the code I've been using to call this procedure.

declare text CLOB; tokens CLOB;
begin
dbms_lob.createtemporary(tokens, TRUE);
dbms_lob.append(tokens, 'token');
dbms_lob.createtemporary(text, TRUE);
dbms_lob.append(text, '<BODY>Test Document</BODY>');
index_procedure(text, tokens, FALSE);
dbms_output.put_line(tokens);
end;
/

Is there something wrong with this setup that might be causing OCILobTrim problems?

+1  A: 

It looks like this is one of those errors that essentially means any number of things could have gone wrong with the external procedure.

There is a known bug in 10.2.0.3, no idea if it's relevant:

ORA-28579 occurs when trying to select data from a pipelined table function implemented in "C" using the ODCITable/ANYDATASET interface. ODCITableDescribe works fine but ODCITableFetch generates an ORA-28579 error.

I would suggest:

  1. Look in the database server trace directories, and the directory where the external proc is located, for any log or trace files generated when the error occurs.
  2. Instrument your external proc in some way so that you can try to trace its execution yourself.
  3. Contact Oracle support
Dave Costa
Dave, do you have a link about that known issue? I'm not doing anything with the ODCITable interface, but maybe there is something related in there.
Ryan Ahearn
Oracle reworked their support website not long ago, and I don't see a way to get a link to a single document. I found it on metalink.oracle.com by searching for the error code. It is bug #5370332 and is described in doc #5370332.8. Hope that helps.
Dave Costa
A: 

Well, an upgrade to 10.2.0.4 (was using 10.2.0.1) at least gave me an understandable error instead of a fairly useless core file and the ORA-28579.

It turns out that the code I was debugging was assuming that calling OCILobRead would return all of the data in one pass. This is the case for any client using a fixed width character set.

For clients using a variable width character set, this isn't the case, OCILobRead was actually reading part of the data and returning OCI_NEED_DATA and future calls to OCILobTrim and OCILobWrite were failing because of the still pending call to OCILobRead. The solution was to loop OCILobRead calls until OCI_NEED_DATA was no longer returned and we had all of the needed data in our buffer.

A call to OCIBreak also would have allowed the OCILobTrim and OCILobWrite functions to continue, though we wouldn't have had all of the needed input data.

Ryan Ahearn