ORA-06512:在“SYS.UTL_FILE”,第536行

时间:2016-02-26 16:04:05

标签: sql oracle stored-procedures oracle11g

我们在Ubuntu上的SQL过程中遇到以下错误。在Windows上正确执行相同的过程。该过程的目标是将.csv文件导入外部oracle表。

Oracle错误:

ORA-29283: invalid file operation ORA-06512: at "SYS.UTL_FILE", line 536 ORA-29283: invalid file operation

这个SO问题可能是一个解决方案,但即使在向相关文件提供适当的权限chmod 777(解决了这种情况下的问题)后,我们也面临同样的错误。

ORA-29283: invalid file operation ORA-06512: at “SYS.UTL_FILE”, line 536

该程序的有关部分是:

for i in c loop   
    dbms_output.put_line('Inside for loop');
    select count(file_name) into f_n from t_filenames_exp e where i.file_name=e.file_name;
    if f_n=0 then
        dbms_output.put_line('Inside if statement');
        insert into t_filenames_exp(file_name,status) values(i.file_name,'need_to_read');
        select f_id into f_idn from t_filenames_exp e where e.file_name=i.file_name;
        select substr(i.file_name,instr(i.file_name,'exp_'),4) into fchk from dual;
        select to_char(to_date(to_char(SEQ_DATE,'dd-MON-yyyy'),'dd-MON-yyyy'),'D') into v_sufix from M_LAB_ID_SEQ_TAB;
        if(fchk='exp_') then
              file_handle := UTL_FILE.FOPEN('EXP_DATA',i.file_name,'R');
              file_handle1 := UTL_FILE.FOPEN('EXP','staging.txt','W');
            loop
                begin
                   utl_file.get_line(file_handle,output_line);
                   utl_file.put_line(file_handle1,output_line);  
                   exception when no_data_found then
                    exit;
                end;  
            end loop;

            if utl_file.is_open(file_handle) then
               utl_file.fclose(file_handle);
            end if;

            if utl_file.is_open(file_handle1) then
               utl_file.fclose(file_handle1);
            end if;  

               /*insert into  t_files_data_exp(f_id,patient_last_name,patient_name,patient_id_code,method_internal_index,method_acronym,index_repeat,result,unit_of_measurement,minimum_reference_value,maximum_reference_value,date_)
               select f_idn,patient_last_name,patient_name,(patient_id_code ||'H'||v_sufix),method_internal_index,method_acronym,index_repeat,result,  unit_of_measurement,minimum_reference_value,maximum_reference_value,date_ from files_data;*/
               insert into  t_files_data_exp(f_id,patient_last_name,patient_name,patient_id_code,method_internal_index,method_acronym,index_repeat,result,unit_of_measurement,minimum_reference_value,maximum_reference_value,date_)
                select f_idn,'Unknown','Unknown',(r.patient_id_code ||'H'||v_sufix),m.CANONICAL_ID,r.METHOD_ACRONYM,0,r.RESULT,r.unit_of_measurement,'','','' from files_data r ,M_METHODS_EXP m where m.METHOD_ACRONYM=r.METHOD_ACRONYM;

        else  
           file_handle := UTL_FILE.FOPEN('EXP_DATA',i.file_name,'R');
           file_handle1 := UTL_FILE.FOPEN('EXP','staging1.txt','W');
            loop
                begin
                   utl_file.get_line(file_handle,output_line);
                   utl_file.put_line(file_handle1,output_line);
                     exception when no_data_found then
                      exit;
                end;  
            end loop;

            if utl_file.is_open(file_handle) then
               utl_file.fclose(file_handle);
            end if;

            if utl_file.is_open(file_handle1) then
               utl_file.fclose(file_handle1);
            end if;
                 insert into  t_files_data_exp(f_id,patient_last_name,patient_name,patient_id_code,method_internal_index,method_acronym,index_repeat,result,unit_of_measurement,minimum_reference_value,maximum_reference_value,date_)  
                 select f_idn,'Unknown','Unknown',r.PATIENT_ID_CODE,m.CANONICAL_ID,r.METHOD_ACRONYM,0,r.RESULT,r.unit_of_measurement,'','','' from rfiles_data r ,M_METHODS_EXP m where m.METHOD_ACRONYM=r.METHOD_ACRONYM;                 
        end if;          
       -- Check whether the data in csv file is same as data in external table.         
        if trace='on' then
            if(fchk='expr_')  then    
              dbms_output.put_line('**************************************************');
              select i.file_name,count(*) into filename,rows_in_file from files_data;
              dbms_output.put_line('File name :'||filename);
              dbms_output.put_line('Total no of rows :'||rows_in_file);
              select replace(filename,'exp','_exp')  into new_filename from dual;       
              file_handle2 := UTL_FILE.FOPEN('EXP_LOG',new_filename,'W');
                for i1 in cur loop                      
                  /*data:=to_char (i1.patient_last_name||';'||i1.patient_name||';'||i1.patient_id_code||';'||i1.method_internal_index||';'||i1.method_acronym||';'||i1.index_repeat||';'||i1.result||';'||i1.unit_of_measurement||';'||i1.minimum_reference_value||';'||i1.maximum_reference_value||';'||i1.date_);*/

                  data:=to_char(i1.patient_id_code||';'||i1.method_acronym||';'||i1.result||';'||i1.unit_of_measurement);
                  utl_file.put_line(file_handle2,data);
                end loop;  
            else
                dbms_output.put_line('**************************************************');
                select i.file_name,count(*) into filename,rows_in_file from rfiles_data;
                dbms_output.put_line('File name :'||filename);
                dbms_output.put_line('Total no of rows :'||rows_in_file);
                select replace(filename,'expr','_expr')  into new_filename from dual;         
                file_handle2 := UTL_FILE.FOPEN('EXP_LOG',new_filename,'W');     
                for i1 in cur1 loop                      
                   /*data:=to_char (i1.m_id||';'||i1.date_||';'||i1.METHOD_ACRONYM||';'||i1.PATIENT_ID_CODE||';'||i1.TEST_TYPE||';'||i1.UNIT_OF_MEASUREMENT||';'||i1.RESULT||';'||i1.RESULT_FLAG); */
                   data:=to_char(i1.patient_id_code||';'||i1.method_acronym||';'||i1.result||';'||i1.unit_of_measurement);
                 utl_file.put_line(file_handle2,data);
                end loop;  
            end if;

            if utl_file.is_open(file_handle2) then
              utl_file.fclose(file_handle2);
            end if;         
               dbms_output.put_line('*************************************************');

        end if;

    end if;   
  end loop; 

发生错误的行是:

file_handle := UTL_FILE.FOPEN('EXP_DATA',i.file_name,'R');

给予该文件的权限如下:

-rwxrwxrwx 1 rama rama 240 Feb 26 11:24 exp_41_02_2016.csv

如何追踪导致此问题的问题?如果您还想了解其他信息,请与我们联系?

1 个答案:

答案 0 :(得分:0)

这是一个o / s文件错误......可能来自权限。正在执行包的数据库影子进程的所有者是需要权限的o / s所有者 - 这可能是'oracle'。您可以通过在数据库服务器上以“oracle”身份登录来进行测试,并查看是否可以读取相关文件。 @alex poole非常考虑检查所有父目录的权限。