62 lines
1.5 KiB
Markdown
62 lines
1.5 KiB
Markdown
# SEND_DATA_TO_DROPBOX
|
|
|
|
## Codice Sorgente
|
|
|
|
```sql
|
|
PROCEDURE "SEND_DATA_TO_DROPBOX" (ondemand boolean := false) AS
|
|
v_queryres clob := EMPTY_CLOB();
|
|
v_file_name varchar2(255);
|
|
|
|
l_file UTL_FILE.FILE_TYPE;
|
|
l_buffer RAW(32767);
|
|
l_amount BINARY_INTEGER := 32767;
|
|
l_pos INTEGER := 1;
|
|
l_blob BLOB := EMPTY_BLOB();
|
|
l_blob_len INTEGER;
|
|
BEGIN
|
|
|
|
if ondemand then
|
|
for c in (
|
|
select 'test' as a from dual
|
|
union all
|
|
select 'test2' as a from dual
|
|
) loop
|
|
v_queryres := v_queryres || c.a;
|
|
end loop;
|
|
else
|
|
v_queryres := 'test';
|
|
end if;
|
|
|
|
l_blob := CLOB2BLOB(v_queryres);
|
|
|
|
l_blob_len := DBMS_LOB.getlength(l_blob);
|
|
|
|
if ondemand then
|
|
v_file_name := 'backup_ondemand_'||to_char(sysdate, 'YYYYMMDDHH24MISS')||'.sql';
|
|
else
|
|
v_file_name := 'backup_'||to_char(sysdate, 'YYYYMMDD')||'.sql';
|
|
end if;
|
|
|
|
l_file := UTL_FILE.fopen('DROPBOXBCK', v_file_name, 'wb', 32767);
|
|
|
|
-- Read chunks of the BLOB and write them to the file
|
|
-- until complete.
|
|
WHILE l_pos <= l_blob_len LOOP
|
|
DBMS_LOB.read(l_blob, l_amount, l_pos, l_buffer);
|
|
UTL_FILE.put_raw(l_file, l_buffer, TRUE);
|
|
l_pos := l_pos + l_amount;
|
|
END LOOP;
|
|
|
|
-- Close the file.
|
|
UTL_FILE.fclose(l_file);
|
|
|
|
EXCEPTION
|
|
WHEN OTHERS THEN
|
|
-- Close the file if something goes wrong.
|
|
IF UTL_FILE.is_open(l_file) THEN
|
|
UTL_FILE.fclose(l_file);
|
|
END IF;
|
|
RAISE;
|
|
|
|
END SEND_DATA_TO_DROPBOX;```
|