Skip to content

Instantly share code, notes, and snippets.

@jon-dixon
Last active September 2, 2022 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jon-dixon/2d8b8b38d634cf05628ecbf560a8ce9a to your computer and use it in GitHub Desktop.
Save jon-dixon/2d8b8b38d634cf05628ecbf560a8ce9a to your computer and use it in GitHub Desktop.
Blog REST Large Volumes Function to fetch JSON, ZIP it and return it
FUNCTION fetch_items_zip RETURN BLOB IS
l_json_clob CLOB;
l_json_blob BLOB;
l_zip_blob BLOB;
BEGIN
-- Fetch all 100,000 Rows into a JSON Array.
SELECT JSON_OBJECT (KEY 'ITEMS' VALUE (
SELECT JSON_ARRAYAGG(JSON_OBJECT (*) RETURNING CLOB)
FROM REST_TRANSFER_TEST) RETURNING CLOB
) INTO l_json_clob
FROM DUAL;
-- Convert the JSON CLOB into a BLOB.
-- Note: clob_to_blob is a custom function to convert the CLOB to a BLOB
l_json_blob := clob_to_blob (p_data => l_json_clob);
-- ZIP the JSON BLOB.
apex_zip.add_file (
p_zipped_blob => l_zip_blob,
p_file_name => 'data.json',
p_content => l_json_blob);
apex_zip.finish (p_zipped_blob => l_zip_blob );
-- Return the ZIP file.
RETURN l_zip_blob;
END fetch_items_zip;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment