运行过程时出现转换错误 - Oracle SQL

时间:2015-10-09 09:12:22

标签: oracle plsql utl-file ora-06512

CREATE OR REPLACE PROCEDURE read_file IS
  f_line     VARCHAR2(2000);
  f          utl_file.file_type;
  comma1     VARCHAR(10);
  comma2     VARCHAR(10);
  comma3     VARCHAR(10);
  comma4     VARCHAR(10);
  comma5     VARCHAR(10);
  f_empno    emp.empno%TYPE;
  f_ename    emp.ename%TYPE;
  f_job      emp.job%TYPE;
  f_mgr      emp.mgr%TYPE;
  f_hiredate emp.doj%TYPE;
  f_sal      emp.sal%TYPE;
  BEGIN
    f := utl_file.fopen('LOG_FILES', 'ab1.txt', 'r');

    LOOP
      BEGIN
        utl_file.get_line(f, f_line);
        EXCEPTION WHEN no_data_found THEN EXIT;
      END;
      comma1 := INSTR(f_line, ',', 1, 1);
      comma2 := INSTR(f_line, ',', 1, 2);
      comma3 := INSTR(f_line, ',', 1, 3);
      comma4 := INSTR(f_line, ',', 1, 4);
      comma5 := INSTR(f_line, ',', 1, 5);

      f_empno := to_number(SUBSTR(f_line, 1, comma1 - 1));
      f_ename := SUBSTR(f_line, comma1 + 1, comma2 - comma1 - 1);
      f_job := SUBSTR(f_line, comma2 + 1, comma3 - comma2 - 1);
      f_mgr := to_number(SUBSTR(f_line, comma3 + 1, comma4 - comma3 - 1));
      f_hiredate := to_date(SUBSTR(f_line, comma4 + 1, comma5 - comma4 - 1), 'dd-mon-yyyy');
      f_sal := to_number(SUBSTR(f_line, comma5 + 1), '99999');

      dbms_output.put_line(f_empno || ' ' || f_ename || ' ' || f_job || ' ' || f_mgr || ' ' || f_hiredate || ' ' || f_sal);

      INSERT INTO emp12 VALUES (f_empno, f_ename, f_job, f_mgr, f_hiredate, f_sal);
    END LOOP;

    utl_file.fclose(f);

    COMMIT;
  END read_file;
  /

如果我在sql命令提示符下以exec read_file;

执行程序

我收到错误消息:

BEGIN read_file; END;

*

ERROR at line 1:

ORA-06502: PL/SQL: numeric or value error

ORA-06512: at "SYSTEM.READ_FILE", line 34

ORA-06512: at line 1

3 个答案:

答案 0 :(得分:1)

<div id="fb-root"></div>
        <script>
            window.fbAsyncInit = function() {
               FB.init({
                  appId     : '616151165162658', 
                 status     : true,
                 xfbml      : true,
                 version    : "v2.5",
                 cookie     : true
               });  

               FB.Canvas.Prefetcher.setCollectionMode(FB.Canvas.Prefetcher.COLLECT_MANUAL);

               FB.Canvas.Prefetcher.addStaticResource('https://staging.ae-mobile.com:20443/mytest/1.2.3.0/resource/en/spine/cavemen_freespin.swf');
            };</script>

f := utl_file.fopen('UTL_FILE_DIR',fname,'r'); 应该是您之前创建的目录。 例如

UTL_FILE_DIR

之后你可以在utl_file.fopen中使用这个目录。它将从UTL_FILE_DIR目录中读取文件,现在是C:\ LOG_FILES。

在执行程序之前,您应该只创建一次

我认为在这种情况下你不需要CREATE DIRECTORY UTL_FILE_DIR AS 'C:\LOG_FILES';

答案 1 :(得分:0)

你的问题有点不清楚。

如果要在SQL命令提示符(sqlplus.exe)中执行它,可以使用

exec read_file;

如果你想在其他程序中执行它,那么你需要指定你正在使用的编程语言。答案会因此而有所不同。

答案 2 :(得分:0)

SQL * Plus

EXEC[UTE] procedure_name;

PL / SQL

中调用它
BEGIN
   procedure_name;
END;
/