Guest User

Untitled

a guest
Jul 29th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 2.27 KB | None | 0 0
  1. CREATE OR REPLACE
  2. PACKAGE file_api AS
  3.  
  4.   /* TODO enter package declarations (types, exceptions, methods etc) here */
  5.   /* small subset of possible functionality for now, no exceptions etc) */
  6.  
  7.   /* file_upload function, returns id of newly uploaded file */
  8.   FUNCTION file_upload (
  9.     p_name IN VARCHAR2,            /* IN name of the file e.g. myResume.pdf */
  10.     p_upload_time IN DATE,         /* IN upload time of the file */
  11.     p_content_type IN VARCHAR2,    /* IN content type e.g. application/pdf */
  12.     p_data IN BLOB,                /* IN binary data of file */
  13.     p_data_size IN INTEGER)        /* IN size of file in bytes */
  14.     RETURN INTEGER;                /* IN returns id of the uploaded file */
  15.    
  16.   /* file_download function takes in ID and sets output parameters */
  17.   PROCEDURE file_download (
  18.     p_id IN INTEGER,               /* IN id of the file to download */
  19.     p_name OUT VARCHAR2,            /* OUT name of the file e.g. myResume.pdf */
  20.     p_upload_time OUT DATE,         /* OUT upload time of file */
  21.     p_content_type OUT VARCHAR2,    /* OUT content type of file e.g. application/pdf */
  22.     p_data OUT BLOB,                /* OUT binary data of file */
  23.     p_data_size OUT INTEGER         /* OUT size of file in bytes */
  24.   );
  25.  
  26.   /* exceptions... file does not exist exception etc. */
  27. END file_api;
  28.  
  29. CREATE OR REPLACE PACKAGE BODY file_api AS
  30.  
  31.   FUNCTION file_upload (
  32.     p_name IN VARCHAR2,            
  33.     p_upload_time IN DATE,        
  34.     p_content_type IN VARCHAR2,    
  35.     p_data IN BLOB,                
  36.     p_data_size IN INTEGER)        
  37.     RETURN INTEGER
  38.   IS out_id INTEGER;
  39.   BEGIN
  40.   out_id := files_seq.NEXTVAL;
  41.   INSERT INTO files$ f (f.id, f.name, f.upload_time, f.content_type, f.data, f.data_size)
  42.     VALUES (out_id, p_name, p_upload_time, p_content_type, p_data, p_data_size);
  43.   RETURN(out_id);
  44.   END;
  45.  
  46.   PROCEDURE file_download (
  47.     p_id IN INTEGER,
  48.     p_name OUT VARCHAR2,
  49.     p_upload_time OUT DATE,
  50.     p_content_type OUT VARCHAR2,
  51.     p_data OUT BLOB,
  52.     p_data_size OUT INTEGER)
  53.   IS
  54.   BEGIN
  55.     SELECT f.name, f.upload_time, f.content_type, f.data, f.data_size INTO
  56.       p_name, p_upload_time, p_content_type, p_data, p_data_size FROM
  57.       files$ f WHERE f.id = p_id;
  58.   END;
  59. END file_api;
Add Comment
Please, Sign In to add comment