【问题标题】:How to create zip folder in plsql (Oracle)如何在 plsql (Oracle) 中创建 zip 文件夹
【发布时间】:2016-09-12 10:15:58
【问题描述】:

我正在我指定的目录中创建一个文件。我希望为每次运行在具有不同文件名的目录中创建一个不同的文件夹名称。 这个文件夹应该被压缩。

目前我正在使用:

create or replace
PROCEDURE xx_WriteBLOBToFILE (myfilename IN VARCHAR2,L_PERSON_ID IN NUMBER) IS 

  v_blob         BLOB;
  blob_length    INTEGER;
    out_file utl_file.file_type;
  v_buffer       RAW(32767);
  chunk_size     BINARY_INTEGER := 32767;
  blob_position  INTEGER := 1;

BEGIN

  -- Retrieve the BLOB for reading
  Select Image Into V_Blob From Per_Images 
  Where Parent_Id =L_PERSON_ID;

  -- Retrieve the SIZE of the BLOB
  blob_length:=DBMS_LOB.GETLENGTH(v_blob);

  -- Open a handle to the location where you are going to write the BLOB to file
  -- NOTE: The 'wb' parameter means "write in byte mode" and is only availabe
  --       in the UTL_FILE package with Oracle 10g or later
  out_file := UTL_FILE.FOPEN ('INTF_DIR1', myfilename, 'wb', chunk_size);

  -- Write the BLOB to file in chunks 
  WHILE blob_position <= blob_length LOOP
    IF blob_position + chunk_size - 1 > blob_length THEN
      chunk_size := blob_length - blob_position + 1;
    END IF;
    DBMS_LOB.READ(v_blob, chunk_size, blob_position, v_buffer);
    UTL_FILE.PUT_RAW(out_file, v_buffer, TRUE);
    blob_position := blob_position + chunk_size;
  END LOOP;

  -- Close the file handle
  UTL_FILE.FCLOSE (out_file);
END;

这段代码将 blob 图像移动到目录中的文件夹。我希望在单独的文件夹中生成此 blob 图像,该文件夹将位于压缩文件夹下

【问题讨论】:

  • 你的意思是 zip 在操作系统压缩文件中,例如可以在数据库外部读取gzipwinzip 等?还是只是一个压缩文件,只能在数据库中解压?
  • @APC - 我的意思是压缩到服务器目录中
  • 所以这是我的选项 1,一个独立于数据库的文件,可以通过像 gzip 这样的操作系统实用程序解压缩?如果您准确地解释您的需求,您更有可能获得有用且及时的答案。
  • @daZza - 我确实通过了它,但我不明白如何在其中添加我的文件

标签: oracle plsql utl-file


【解决方案1】:
猜你喜欢
  • 2016-02-06
  • 2013-07-10
  • 2017-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多