Home » Developer & Programmer » Precompilers, OCI & OCCI » Keep getting ORA-22275 from extproc (ORACLE-XE 11g)
icon5.gif  Keep getting ORA-22275 from extproc [message #567290] Wed, 26 September 2012 04:30 Go to next message
MistaPink
Messages: 2
Registered: September 2012
Junior Member
Hi,

I am trying to give back data from a stored procedure written in C. I registered the functions as follows:
create or replace
procedure version(versioninfo OUT clob) as
	external name "version" library myLib language c with context 
	parameters (context, versioninfo, versioninfo INDICATOR SB4);

It compiles fine. The function being called look like this:
extern "C" DLLEXPORT 
void version(OCIExtProcContext* context, OCILobLocator **out, sb4 *ind_out){
	OCIEnv* envh;
	OCISvcCtx* svch;
	OCIError* errh;
	OCIExtProcGetEnv (context, &envh, &svch, &errh);

	std::string versioninfo = "104";

	oraub8 maxChar = 10;
	
	OCIDescriptorAlloc(envh, 
			  (dvoid **) out,
			  (ub4) OCI_DTYPE_LOB,       /* Type of Descriptor */
			  (size_t) 0, 
			  (dvoid **) 0);

	OCILobTrim2(svch, 
		    errh, 
	   	    *out,
		   (ub4)1);
		
	OCILobWrite2(/*svcctx*/svch, /*errh*/errh, /*ociloblocator*/*out,
		     /*byte_amtp*/NULL, /*char_amtp*/&maxChar, /*offset*/1,
		     /*bufp*/(void*)versioninfo.c_str(), /*buflen*/versioninfo.size(),
	             /*piece*/OCI_ONE_PIECE, /*context for callback*/NULL,
		     /*callback*/NULL, /*csid*/0, /*csfrm*/SQLCS_IMPLICIT);
	*ind_out = 0;
}

If I execute the procedure with SQLDeveloper by pressing "play" it is getting executed but there is no result. If I try to execute it from an anonymous block it results in ORA-22275 instead of doing anything.
declare
  res clob;
  begin
  -- the following doesnt help much
  --dbms_lob.createtemporary(res,true);
  version(res);
  dbms_output.put_line(res);
end;


Actually I have to questions:
1.) Why does Oracle give me the error? In my opinion all requirements mentioned by the error description are met.
2.) Why is there no output when executing the function via SQL Developer? Is the usage of OCILobWrite wrong?

Thank you all in advance and I am looking forward to you answers and suggestions.
Re: Keep getting ORA-22275 from extproc [message #568437 is a reply to message #567290] Thu, 11 October 2012 09:56 Go to previous messageGo to next message
MistaPink
Messages: 2
Registered: September 2012
Junior Member
Solved it by using `OCILobCreateTemporary` before working with that CLOB.
    	OCIDescriptorAlloc(envh, 
    					   (dvoid **) out,
    					   (ub4) OCI_DTYPE_LOB,       /* Type of Descriptor */
    					   (size_t) 0, 
    					   (dvoid **) 0);
    	OCILobCreateTemporary(svch, errh, *out, 0, SQLCS_IMPLICIT, OCI_TEMP_CLOB, OCI_ATTR_NOCACHE, OCI_DURATION_CALL);
    	ub4 amt = static_cast<ub4>(result.size());
    	OCILobTrim2(svch, 
    				errh, 
    				*out,
    				(ub4)amt);
    	
    	oraub8 amtp = static_cast<oraub8>(result.size());
    	OCILobWrite2(/*svcctx*/svch, /*errh*/errh, /*ociloblocator*/*out,
    				 /*byte_amtp*/NULL, /*char_amtp*/&amtp, /*offset*/1,
    				 /*bufp*/reinterpret_cast<dvoid*>(const_cast<char*>(result.c_str())), /*buflen*/amt,
    				 /*piece*/OCI_ONE_PIECE, /*context for callback*/NULL,
    				 /*callback*/NULL, /*csid*/0, /*csfrm*/SQLCS_IMPLICIT);
    	*ind = 0;
Re: Keep getting ORA-22275 from extproc [message #568446 is a reply to message #568437] Thu, 11 October 2012 10:24 Go to previous message
Michel Cadot
Messages: 68625
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Thanks to let us and provide the solution.

Regards
Michel
Previous Topic: Call Stored procedure with input variable as object type in pro *c
Next Topic: calling procedure from PRO C
Goto Forum:
  


Current Time: Fri Mar 29 05:55:01 CDT 2024