我正在尝试从DB导出blob并在unix服务器上写入pdf。但我得到的是unix服务器上的空pdf。我的代码如下:
*
CREATE OR REPLACE PROCEDURE write_to_file ()
IS
v_cn_letter_name VARCHAR2 (100);
v_buffer RAW (32767);
v_amount BINARY_INTEGER := 32767
v_pos INTEGER := 1;
v_blob_len INTEGER;
v_file UTL_FILE.FILE_TYPE;
ftp_fldr_loc_i VARCHAR2 := '/devl/apps/my_dir';
BEGIN
v_cn_letter_name := 'ConsolidatedConsumerNotificationLetter_'|| v_date ||'.pdf';
BEGIN
SELECT cnsmr_letter
INTO data_to_write
FROM my_table
WHERE letter_emailed_ind = 0;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
ent_logging_pkg.handle_exception_prc
(SQLCODE,
SQLERRM,
'No Records for letters');
END;
BEGIN
v_blob_len := DBMS_LOB.getlength(data_to_write);
-- Open the destination file.
v_file := UTL_FILE.fopen(ftp_fldr_loc_i, v_cn_letter_name, 'WB', 32767);
WHILE v_pos <= v_blob_len
LOOP
IF v_pos + v_amount - 1 > v_blob_len
THEN
v_amount := v_blob_len - v_pos + 1;
END IF;
DBMS_LOB.read(data_to_write, v_amount, v_pos, v_buffer);
UTL_FILE.put_raw(v_file, v_buffer, TRUE);
utl_file.fflush(v_file);
v_pos := v_pos + v_amount;
END LOOP;
-- Close the file.
UTL_FILE.fclose(v_file);
EXCEPTION
WHEN OTHERS
THEN
IF utl_file.is_open(v_file)
THEN
utl_file.fclose(v_file);
END if;
ent_logging_pkg.handle_exception_prc
(SQLCODE,
SQLERRM,
'EXCEPTION WRITING TO FILE');
END;
END write_to_file;
*
我对目录也有足够的权限。我正在使用Oracle 11g 执行时,将在服务器上创建pdf文件,但该文件为空。我试着写入txt文件,这很好。 为什么创建一个空的pdf? 请帮忙!