Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 2.42 KB | None | 0 0
  1. DECLARE
  2.  
  3.   l_upload_size INTEGER;
  4.   l_upload_blob BLOB;
  5.   l_image_id    NUMBER;
  6.   l_image       ORDSYS.ORDImage;
  7.   l_lat VARCHAR2(100);
  8.   l_lng VARCHAR2(100);
  9.  
  10.  
  11. BEGIN
  12.  
  13.   --
  14.   -- Get the BLOB of the new image from the APEX_APPLICATION_TEMP_FILES (synonym for WWV_FLOW_TEMP_FILES)
  15.   -- APEX 5.0 change from APEX_APPLICATION_FILES which has been deprecated
  16.   -- APEX_APPLICATION_TEMP_FILES has fewer columns and is missing doc_size
  17.   --
  18.  
  19.   --generate co-ordinates from postcode
  20.   brian.GEOCODE_GM_XML (:P6_postcode, l_lat, l_lng);
  21.   DBMS_OUTPUT.PUT_LINE('Latitude ='||l_lat);
  22.   DBMS_OUTPUT.PUT_LINE('Longitude ='||l_lng);
  23.  
  24.   SELECT
  25.     blob_content
  26.   INTO
  27.     l_upload_blob
  28.   FROM
  29.     apex_application_temp_files
  30.   WHERE
  31.     name = :P6_image_filename;
  32.   --
  33.   -- Insert a new row into the table, initialising the image and
  34.   -- returning the newly allocated image_id for later use
  35.   --
  36.   INSERT
  37.   INTO
  38.     properties_images
  39.     (
  40.       p_i_id,
  41.       image_filename,
  42.       property_image
  43.     )
  44.     VALUES
  45.     (
  46.       seq_p_images_p_i_id.NEXTVAL,
  47.       :P6_image_filename,
  48.       ORDSYS.ORDImage()
  49.     )
  50.   RETURNING
  51.     p_i_id, property_image
  52.   INTO
  53.     l_image_id, l_image;
  54.    
  55.   INSERT INTO
  56.       properties
  57.       (
  58.           p_id,
  59.           p_i_id,
  60.           a_id,
  61.           address_line_1,
  62.           address_line_2,
  63.           city,
  64.           postcode,
  65.           geom_location,
  66.           notes
  67.       )
  68.   VALUES
  69.       (
  70.          
  71.           :P6_p_id,
  72.           l_image_id,
  73.           :P6_A_ID,
  74.           :P6_address_line_1,
  75.           :P6_address_line_2,
  76.           :P6_city,
  77.           :P6_postcode,
  78.           sdo_geometry(2001, 8307, sdo_point_type(l_lng, l_lat, NULL), NULL, NULL),
  79.           :P6_notes
  80.       );
  81.  
  82.   -- find the size of BLOB (get doc_size)
  83.   l_upload_size := DBMS_LOB.getlength(l_upload_blob);
  84.   -- copy the blob into the ORDImage BLOB container
  85.   DBMS_LOB.COPY( l_image.SOURCE.localData, l_upload_blob, l_upload_size );
  86.  
  87.   -- set the image properties
  88.   l_image.setProperties();
  89.  
  90.   UPDATE
  91.     properties_images
  92.   SET
  93.     property_image     = l_image -- original ORDImage image
  94.   WHERE
  95.     p_i_id = l_image_id;
  96.  
  97.   -- generate the thumbnail image from the ORDImage
  98.   create_blob_thumbnail(l_image_id);
  99.  
  100.   --Optimise text index's for text searching after inserting new row
  101.   CTX_DDL.OPTIMIZE_INDEX('properties_addr1_ctx_idx','FULL');
  102.  
  103.   COMMIT;
  104.  
  105. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement