Great answer
Joel, November 12, 2001 - 12:32 pm UTC
Thanks, Tom
Which is the more efficient
Neil, April 15, 2004 - 3:14 am UTC
I have a requirement to pass a host array into a pl/sql server-side pl/sql package. Would it be more efficient to pass the array into a pl/sql block defined in the host program and let it call the server-side package for each element of the array, or should I code a further procedure in the server-side package to receive the array and have it call the relevant procedure for each element? Either way, the array will go across the network, right?
April 15, 2004 - 8:31 am UTC
plsql blocks "defined" in the host are SENT to the server to be compiled and executed.
plsql does not talk to itself over the network -- if you have a plsql block "in your client code", that string is sent to the server where it executes.
Just bind the input array to the procedure and execute it.
Host arrays into pl/sql and back
Neil, April 21, 2004 - 11:06 am UTC
I would like to pass a number host arrays into my pl/sql block. Some of them will already be populated, and some need to be populated by a server side package. The pl/sql block loops through the arrays that are populated and calls the server side package for each populating those arrays that empty. That's the theory.
I know you can make an assignment within a pl/sql block from a host array to a pl/sql table after making the required definintions:
pl_sql_table := :host_array;
But can you assign a pl/sql table to a host array like this
:host_array := pl_sql_table; ?
If so, does one need to nul-terminate the new elements outside the block?
Or to put it another way
Neil, April 29, 2004 - 3:54 am UTC
Is there any way of returning an array from pl/sql to a pro*c host program?
April 29, 2004 - 8:15 am UTC
static void process( )
{
EXEC SQL BEGIN DECLARE SECTION;
varchar input_array[25][50];
int input_dim;
exec sql arraylen input_array(input_dim);
varchar output_array[25][50];
int output_dim;
exec sql arraylen output_array(output_dim);
int num_elements;
int i;
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER SQLERROR DO sqlerror_hard();
input_dim = 17;
for( i = 0; i < input_dim; i++ )
{
sprintf( input_array[i].arr, "Element %d", i );
input_array[i].len = strlen(input_array[i].arr );
}
output_dim = 0;
exec sql execute
begin
for i in 1 .. :input_array.count
loop
:output_array(i) := upper(:input_array(i));
end loop;
:output_dim := :output_array.count;
end;
end-exec;
printf( "output dim = %d\n", output_dim );
for( i = 0; i < output_dim; i++ )
printf( "%d) %.*s\n", i, output_array[i].len, output_array[i].arr );
}
Looks promising
Neil, May 18, 2004 - 10:26 am UTC
But I couldn't get it to work. It compiles and it runs, but I get no output.
I'm using 8.1.7 on HP - should this matter?
May 18, 2004 - 4:52 pm UTC
just ran it on 8174, worked - -should work. if no output at all -- put in more prints and see what is happening a little more.
Pilot error
Neil, May 24, 2004 - 8:12 am UTC
It wasn't giving me any output because I wasn't connected to the database! Doh! How stupid is tha? I just went back to it to see if I could get it to work, and the penny dropped! Sorry for wasting your time!