Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: ejonesThanks. So have you been able to call this Java code from SQL*Plus or any SQL tool? My first thought is that you might make sure it works inside SQLPlus because if it doesn't work there you can more easily get help from Oracle experts. I am unfamiliar with calling Java from Oracle and based on what I see you doing here there are only a couple steps to getting it done.
One possible answer is that Oracle functions have to be called in such a way that they can put the value they return somewhere. So in a block of PL/SQL code you need to assign the results to a variable or pass it as a parameter in another function call. Or, and I think this might be the answer you need, you can call the function in a select statement. Oracle has a system table that is very helpful in situations like this named DUAL which always has exactly one record. So replace this code that is in the Attachment node:
sql1 = "begin FN_WRITE_BLOB_TO_FILE(attachmentId); end;"
sqlNonSelect(sql1,'ATTACHMENT_ID')
with this:
sql1 = "select FN_WRITE_BLOB_TO_FILE(:1) as FUNCTION_RETURNED_THIS from dual"
sqlSelect(1,sql1,'ATTACHMENT_ID')
Notice the change to a different function, sqlSelect() which will take the results of the SQL statement and send it to the output specified as its first parameter. And when using the DB Execute node you need to use bind parameters to indicate where to put the values that come from the input stream. In this case there is only one value indicated by :1 and this is matched to the 'ATTACHMENT_ID' field, the third parameter in the call to the sqlSelect() function. (Disclaimer: I didn't test the code so I hope I have the syntax right)
One more thing, in case you want to understand the error message above better, the "index out of bounds: 0 / 0" is because the 'ATTACHMENT_ID' parameter didn't have a matching ":1" in the SQL statement. So it seems that somewhere in the internal processing it must have created an array variable to hold the parameter values and since there are no parameters, its size is set to zero. Then when it attempts to place the value currently in 'ATTACHMENT_ID' field into that array it throws the "index out of bounds" error.
I hope this helps.
Ernest