【问题标题】:Transfer Excel files to a database server directory path in APEX将 Excel 文件传输到 APEX 中的数据库服务器目录路径
【发布时间】:2018-01-10 14:03:15
【问题描述】:

我目前使用的是 APEX 5.1。我的页面中有一个文件浏览项。和一个上传按钮。

当用户选择一个文件并点击上传按钮时,该文件必须被传输到一个目录路径(创建的目录路径)。

我能够使用 blob 到 clob 转换和 UTL_FILE 包传输 .txt 文件。但是当我对.xls.xlsx 文件执行相同操作时,数据会以不可读的模式传输。

如何在 APEX 中使用 PL/SQL 或 JavaScript 将 excel 文件传输到数据库服务器目录路径?提前致谢!!

【问题讨论】:

    标签: javascript plsql oracle-apex


    【解决方案1】:

    我不是在复制 Excel 文件,而是图像;一切顺利。我正在使用 WWV_FLOW_FILES 表;您可能会使用自己的表,将 XLS 存储到其 BLOB 列中,然后使用此过程(代码如下),将 BLOB 和 UTL_FILE 读取到 P_DIR 参数指定的目录中。

       PROCEDURE p_write_blob_to_file (p_file_id IN NUMBER, p_dir IN VARCHAR2)
       IS
          /* 19.04.2012. Procedure copies image from WWV_FLOW_FILES into a
                         directory P_DIR. Taken from Eddie Awad's Blog
                         http://awads.net/wp/2011/09/20/create-an-application-to-upload-files-using-oracle-apex-in-less-than-10-minutes-video/
          */
          l_blob            BLOB;
          l_blob_length     INTEGER;
          l_out_file        UTL_FILE.file_type;
          l_buffer          RAW (32767);
          l_chunk_size      BINARY_INTEGER := 32767;
          l_blob_position   INTEGER := 1;
          l_file_name       pkg_general.subt_ime_slike;
       BEGIN
          -- Retrieve the BLOB for reading
          SELECT blob_content, filename
            INTO l_blob, l_file_name
            FROM wwv_flow_files
           WHERE id = p_file_id;
    
          -- Retrieve the SIZE of the BLOB
          l_blob_length := DBMS_LOB.getlength (l_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
          --       available in the UTL_FILE package with Oracle 10g or later
          l_out_file :=
             UTL_FILE.fopen (p_dir,
                             l_file_name,
                             'wb' -- important. If ony w then extra carriage return/line brake
                                 ,
                             l_chunk_size);
    
          -- Write the BLOB to file in chunks
          WHILE l_blob_position <= l_blob_length
          LOOP
             IF l_blob_position + l_chunk_size - 1 > l_blob_length
             THEN
                l_chunk_size := l_blob_length - l_blob_position + 1;
             END IF;
    
             DBMS_LOB.read (l_blob,
                            l_chunk_size,
                            l_blob_position,
                            l_buffer);
             UTL_FILE.put_raw (l_out_file, l_buffer, TRUE);
             l_blob_position := l_blob_position + l_chunk_size;
          END LOOP;
    
          -- Close the file handle
          UTL_FILE.fclose (l_out_file);
       END p_write_blob_to_file;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-31
      • 2016-08-21
      • 1970-01-01
      • 2015-02-18
      • 1970-01-01
      • 2011-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多