I\'m trying to create a Java source object on an oracle database using JDBC.
The source I want to create is the following:
create or replace and reso
Please post a complete thorough example. Your code is working, following is the result on my 11.1.0.7.0
db. First the setup:
SQL> create or replace directory TMP as '/tmp';
Directory created
SQL> CREATE TABLE testBlob (a BLOB);
Table created
SQL> INSERT INTO testBlob VALUES (utl_raw.cast_to_raw('StackOverflow'));
1 row inserted
The first function:
SQL> CREATE OR REPLACE FUNCTION blob2File(p_blob BLOB,
2 p_path VARCHAR2,
3 p_buffer NUMBER)
4 RETURN NUMBER AS
5 LANGUAGE JAVA NAME
6 'dbjava.BlobIO.blobToFile(java.sql.Blob,
7 java.lang.String,
8 int) return int';
9 /
Function created
SQL> DECLARE
2 l_blob BLOB;
3 l_return INT;
4 BEGIN
5 SELECT * INTO l_blob FROM testBlob;
6 l_return := blob2File(l_blob, '/tmp/test.blob', 1024);
7 dbms_output.put_line(l_return);
8 END;
9 /
1
For the second function:
SQL> CREATE OR REPLACE FUNCTION queryBlob2File(p_query VARCHAR2,
2 p_path VARCHAR2,
3 p_buffer NUMBER) RETURN NUMBER AS
4 LANGUAGE JAVA NAME
5 'dbjava.BlobIO.blobToFile(java.lang.String,
6 java.lang.String,
7 int) return int';
8 /
Function created
SQL> DECLARE
2 l_query VARCHAR2(1000);
3 l_return INT;
4 BEGIN
5 l_query := 'SELECT * FROM testBlob';
6 l_return := queryBlob2File(l_query, '/tmp/test.blob', 1024);
7 dbms_output.put_line(l_return);
8 END;
9 /
1
PL/SQL procedure successfully completed
You can use the UTL_FILE package to deal with files directly in PL/SQL:
SQL> DECLARE
2 l_file utl_file.file_type;
3 l_line VARCHAR2(1024);
4 BEGIN
5 l_file := utl_file.fopen(location => 'TMP',
6 filename => 'test.blob',
7 open_mode => 'R');
8 utl_file.get_line(l_file, l_line);
9 dbms_output.put_line(l_line);
10 utl_file.fclose(l_file);
11 END;
12 /
StackOverflow
Ok found the problem eventually, it needed to be CallableStatement
with setEscapeProcessing(false)
.