Oracle Clob 列导出到 .msg 文件

发布于 2025-01-16 10:02:52 字数 1402 浏览 3 评论 0原文

我已经成功创建了两个将 clob 数据导出到 .msg 文件的过程 - 但由于某种原因,所有 clob 数据都没有导出到文件 - 不知道该怎么做 - 任何帮助


Declare
   Cursor c_emp_files
      is
    SELECT id, clob_content
            FROM table;
            
Begin

   for c in c_emp_files loop
      clob_to_file('c:\temp\', 'F'||c.file_id||'.msg', c.clob_content);
   end loop;
End;

create or replace PROCEDURE blob_to_file (i_dir IN VARCHAR2,
                                          i_file_name   IN VARCHAR2,
                                          i_clob   IN CLOB)
AS



   l_file       UTL_FILE.file_type;
   l_buffer     RAW (32767);
   l_amount     BINARY_INTEGER := 32767;
   l_pos        INTEGER := 1;
   l_blob_len   INTEGER;
 
BEGIN
   l_blob_len := DBMS_LOB.getlength (i_clob);
  
   l_file :=
      UTL_FILE.fopen (i_dir,
                      i_file_name,
                      'WB',
                      32767);

   WHILE l_pos < l_blob_len
   LOOP
      DBMS_LOB.read (i_clob,
                     l_amount,
                     l_pos,
                     l_buffer);
      UTL_FILE.put_raw (l_file, l_buffer, TRUE);
    
    
      l_pos := l_pos + l_amount;
   END LOOP;

   UTL_FILE.fclose (l_file);
EXCEPTION
   WHEN OTHERS
   THEN
      IF UTL_FILE.is_open (l_file)
      THEN
         UTL_FILE.fclose (l_file);
      END IF;
END blob_to_file;

我得到文件输出作为例外,但我不能无法打开文件 - 我猜它没有导出完整内容

I have managed to create two procedure for exporting clob data to .msg file - But for some reason all the clob data is not been exported to the file - Not sure what to do - Any help


Declare
   Cursor c_emp_files
      is
    SELECT id, clob_content
            FROM table;
            
Begin

   for c in c_emp_files loop
      clob_to_file('c:\temp\', 'F'||c.file_id||'.msg', c.clob_content);
   end loop;
End;

create or replace PROCEDURE blob_to_file (i_dir IN VARCHAR2,
                                          i_file_name   IN VARCHAR2,
                                          i_clob   IN CLOB)
AS



   l_file       UTL_FILE.file_type;
   l_buffer     RAW (32767);
   l_amount     BINARY_INTEGER := 32767;
   l_pos        INTEGER := 1;
   l_blob_len   INTEGER;
 
BEGIN
   l_blob_len := DBMS_LOB.getlength (i_clob);
  
   l_file :=
      UTL_FILE.fopen (i_dir,
                      i_file_name,
                      'WB',
                      32767);

   WHILE l_pos < l_blob_len
   LOOP
      DBMS_LOB.read (i_clob,
                     l_amount,
                     l_pos,
                     l_buffer);
      UTL_FILE.put_raw (l_file, l_buffer, TRUE);
    
    
      l_pos := l_pos + l_amount;
   END LOOP;

   UTL_FILE.fclose (l_file);
EXCEPTION
   WHEN OTHERS
   THEN
      IF UTL_FILE.is_open (l_file)
      THEN
         UTL_FILE.fclose (l_file);
      END IF;
END blob_to_file;

I am getting file output as excepted but I couldn't open the file - I guess it is not exporting full content

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感受沵的脚步 2025-01-23 10:02:52

经过一些朋友的帮助,我发现了以下内容:他们是 Oracle 中已经存在的程序 - 可以转换 Colb2file - 这在 Oracle 11g 中完美运行

Clob2file 过程

参考自链接

示例代码:

Declare
   Cursor c_emp_files
      is
    SELECT id, clob_data        
    FROM table;
            
Begin
    -- it will loop the whole emp_files table 

   for c in c_emp_files loop
  
    DBMS_XSLPROCESSOR.CLOB2FILE(c.clob_data,'c:\temp\',c.file_id||'.msg');
    
   end loop;
End;

After some friends help I found the below: their is a procedure in place already in Oracle - which can convert Colb2file - This worked perfectly in Oracle 11g

Clob2file procedure

reference from link

Example code:

Declare
   Cursor c_emp_files
      is
    SELECT id, clob_data        
    FROM table;
            
Begin
    -- it will loop the whole emp_files table 

   for c in c_emp_files loop
  
    DBMS_XSLPROCESSOR.CLOB2FILE(c.clob_data,'c:\temp\',c.file_id||'.msg');
    
   end loop;
End;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文