DBMS_SCHEDULER.get_file数据问题

时间:2015-04-15 18:46:41

标签: oracle procedure

我正在尝试使用DBMS_SCHEDULER.get_file包从stdout和stderr文件中获取输出。但是数据以二进制形式显示。如何将其转换为varchar2?

SET SERVEROUTPUT ON
DECLARE
  l_clob             CLOB;
  l_additional_info  VARCHAR2(100);
  l_external_log_id  VARCHAR2(100);
BEGIN
  SELECT additional_info, external_log_id
  INTO   l_additional_info, l_external_log_id
  FROM   (SELECT log_id, 
             additional_info,
             REGEXP_SUBSTR(additional_info,'job[_0-9]*') AS external_log_id
          FROM   user_scheduler_job_run_details
          WHERE  job_name = 'SCRIPT_DISABLE_USER'
          ORDER BY log_id DESC)
  WHERE  ROWNUM = 1;

  DBMS_OUTPUT.put_line('ADDITIONAL_INFO: ' || l_additional_info);
  DBMS_OUTPUT.put_line('EXTERNAL_LOG_ID: ' || l_external_log_id);

  dbms_scheduler.create_credential
  (credential_name => 'WORKFLOW_CRED1',
  username => 'dsadasd',
  password => 'dasdsa');

  DBMS_LOB.createtemporary(l_clob, FALSE);

  DBMS_SCHEDULER.get_file(
  source_file     => l_external_log_id ||'_stdout',
  credential_name => 'WORKFLOW_CRED',
  file_contents   => l_clob,
  source_host     => NULL);

  DBMS_OUTPUT.put_line('stdout:');
  DBMS_OUTPUT.put_line(l_clob);
  dbms_scheduler.drop_credential('WORKFLOW_CRED1');
END;
/

输出生成:

anonymous block completed
ADDITIONAL_INFO: EXTERNAL_LOG_ID="job_44793_12759",
USERNAME="workflow"
EXTERNAL_LOG_ID: job_44793_12759
stdout:
㈰ㄵⴰ㐭ㄳ弱ㄺ㐶㨳〠ⴠ卣物灴慵湣桥搠睩瑨⁡牧畭敮琠❲浩整畳✮ਲ〱㔭〴ⴱ㍟ㄱ㨴㘺㌳‭⁕獥爠❲浩整   畳✠獵捣敳獦畬汹⁤楳慢汥搮ਲ〱㔭〴ⴱ㍟ㄱ㨴㘺㌳‭⁅硩瑩湧⁷楴栠牥瑵牮⁣潤攠〮

非常感谢任何帮助。感谢..

1 个答案:

答案 0 :(得分:0)

多个字符中的

file_contents 。它们应该通过更复杂的方法来读取:将file_contents转换为blob,然后转换为clob,如

    function blob_to_clob (p_blob in blob) return clob as
  l_clob    clob;
  l_varchar varchar2(32767);
  l_start      pls_integer := 1;
  l_buffer  pls_integer := 32767;
begin
  dbms_lob.createtemporary(l_clob, true);
  for i in 1..ceil(dbms_lob.getlength(p_blob) / l_buffer)
  loop
    l_varchar := utl_raw.cast_to_varchar2(dbms_lob.substr(p_blob, l_buffer, l_start));
    dbms_lob.writeappend(l_clob, length(l_varchar), l_varchar);
    l_start := l_start + l_buffer;
  end loop;
  return l_clob;
end;