Passing information to a Stored Procedure with a BLOB

Cybrey

Member²
We're in the process of writing a SQL syntax checker for SQL which passes SQL to a stored procedure. Problem is with strings it runs into a 4000 character limit on PL/SQL. We have got around this using CLOB. Definition of Stored Procedure looks something like this...

function testSQL( sqltext IN clob, errdesc OUT varchar2, errpos OUT number ) RETURN VARCHAR2;

From searching the forum I've established that I need to use OracleQuery and SetComplexVariable. All the examples that I can find I think pass information from ORACLE rather than the other way around.

Can anyone provide any help.

Thanks in advance.
Dave.
 
Ok finally managed to get a solution from an almagmation from several sources.. I'll post here just to show people how we achieved it.

********************
** PL/ SQL Source
********************
PROCEDURE InitClob( Clobname OUT CLOB)IS
BEGIN
dbms_lob.CreateTemporary( Clobname, FALSE);
END;

PROCEDURE FreeClob( Clobname IN OUT CLOB)IS
BEGIN
dbms_lob.FreeTemporary(Clobname);
END;

-- Function and procedure implementations
function testSQL( sqltext IN OUT clob, errdesc OUT varchar2, errpos OUT number ) RETURN VARCHAR2 is
acursor integer;
asqltext dbms_sql.varchar2s;
csqltext clob;

pos INTEGER;
amt BINARY_INTEGER;
buf varchar2(256);
begin
--init vars
errdesc := '';
errpos := 0;

csqltext := sqltext;

--create table
buf := '';
pos := 1;
amt := 256;
Begin
loop
dbms_lob.read( csqltext,amt,pos, buf);
pos := pos+amt;
asqltext(asqltext.count+1):=buf;
end loop;
exception
when no_data_found then null;
end;
--dbms_lob.FreeTemporary( csqltext);
Begin
--create a cursor, parse the sql and see what happens
acursor := dbms_sql.open_cursor;
dbms_sql.parse(acursor,asqltext,1,asqltext.count,false,dbms_sql.V7);
dbms_sql.close_cursor(acursor);
return 'T';
exception
when others then
errpos :=dbms_sql.last_error_position;
errdesc := sqlerrm;
dbms_sql.close_cursor(acursor);
return 'F';
end;
end;
end checkSQL;

**************
DELPHI SOURCE
**************
procedure TForm1.Button1Click(Sender: TObject);
var
bSQL : TLOBLocator;
sqlString : string;
begin
OracleSession1.LogOn;

with OracleQuery1 do
begin
bSQL := TLOBLocator.create( OracleSession1, otCLOB);
SetComplexVariable('SQLTEXT', bSQL);
execute;
sqlString := 'Select * from currency2';
bSQL.write( sqlString[1], length( sqlString));
end;

with OracleQuery2 do
begin
SetComplexVariable('SQLTEXT', bSQL);
execute;
showmessage(getVariable('RESULT' ));
showmessage(getVariable('ERRDESC'));
end;

with OracleQuery3 do
begin
//bSQL := TLOBLocator.create( OracleSession1, otCLOB);
SetComplexVariable('SQLTEXT', bSQL);
execute;
bSQL.free;
end;
end;

And thats all there is to it.. There are 3 Oracle Querys on the form .. first one initialises the CLOB, second one calls the syntax checker, third one frees the CLOB. Any questions/comments.

Dave.

[This message has been edited by Cybrey (edited 18 October 2002).]
 
The code is amalgatmation of several sources, some of which were from this forum. For instance your code doesn't cover how to use the CLOB on the server side.

If it makes you feel any better you can claim that the code is yours as I don't really care. All I was posting was the solution that we arrived at for checking SQL on a stored procedure.
 
Back
Top