Stored Procedure Output VarChar Parameter returns garbage

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ardent
Posts: 2
Joined: Sun 15 Nov 2009 13:29

Stored Procedure Output VarChar Parameter returns garbage

Post by ardent » Sun 15 Nov 2009 13:32

Hi,
We have a problem where varchar output parameters are returned with allot of spaces and then some garbage chars at the end. It seems the parameter returned value is padded with spaces+few garbage chars to fill all the size. This does not happen when executing queries that return the same varchar strings.
We are using Delphi 7 and Oracle Server&Client 11.1.0.7 (I remember we had the same issue with Oracle 10.x)
Here is a dump of such a string (each number is the unicode value)
UseUnicode is true (doesn't help setting it to false) and we're not using the direct option.
The NLS_LANG is AMERICAN_AMERICA.UTF8, and the database is of UTF8 as well.

{1502,46,1512,46,1502,46,32,45,32,1502,1506,1512,1499,1514,32,1500,1504,1505,1497,1493,1504,1493,1514,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,65530,65535,30,}

The stored procedure is simple:
procedure Get_Entity_Desc
(
p_edesc out CHAR,
p_etable INTEGER,
p_eentry INTEGER
)as
begin
begin

select
ENTDESC
into
p_edesc

from CTRENTITIES
where
ENTTABLE = p_etable and
ENTENTRY = p_eentry;
exception
when NO_DATA_FOUND THEN
begin
p_edesc:= '';
end;
end;
end;

The code (simplified here):

SP := TOraStoredProc.Create(nil);
SP.Session := DB; // My TOraSession
SP.StoredProcName := 'CTRPKG.Get_Entity_Desc';
SP.params.clear;

p := TOraParam.create(nil);
with p do begin
Name := 'p_edesc';
ParamType := ptOutput;
DataType := ftwideString;
size := 254;
end;
SP.Params.AddParam(p);

p := TOraParam.create(nil);
with p do begin
Name := 'p_etable';
ParamType := ptInput;
DataType := ftwideString;
Value := 4;
end;
SP.Params.AddParam(p);

p := TOraParam.create(nil);
with p do begin
Name := 'p_eentity';
ParamType := ptInput;
DataType := ftwideString;
Value := 997;
end;
SP.Params.AddParam(p);

SP.ExecProc;
widestr = parameters.items[0].Value;


Any suggestions?

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Mon 16 Nov 2009 09:30

You should use VARCHAR as type of stored procedure parameter. If you use CHAR, Oracle adds spaces to the value to fill all its size.

ardent
Posts: 2
Joined: Sun 15 Nov 2009 13:29

Post by ardent » Mon 16 Nov 2009 10:04

Thanks It works great! For some reason I thought that function parameters can only be CHAR. I can't see why it should have returned the garbage as it did, but as long as it works :)

Alon.

Post Reply