[英]Getting conversion error while running a procedure - Oracle SQL
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;
/
If I execute the program in sql command prompt as exec read_file;
如果我在sql命令提示符下以
exec read_file;
形式exec read_file;
I got error message as: 我收到以下错误消息:
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
f := utl_file.fopen('UTL_FILE_DIR',fname,'r');
UTL_FILE_DIR
should be a directory which you created earlier. UTL_FILE_DIR
应该是您先前创建的目录。 For example 例如
CREATE DIRECTORY UTL_FILE_DIR AS 'C:\LOG_FILES';
After it you can use this directory in utl_file.fopen. 之后,您可以在utl_file.fopen中使用此目录。 It will read file from UTL_FILE_DIR directory which is C:\\LOG_FILES now.
它将从UTL_FILE_DIR目录(现在为C:\\ LOG_FILES)读取文件。
You should create it only once, before you execute the procedure 在执行该过程之前,您应该只创建一次
And I think you don't need f_dir
in that case 而且我认为您在这种情况下不需要
f_dir
Your question is a bit unclear. 您的问题还不清楚。
If you want to execute it in SQL command prompt (sqlplus.exe) you can use 如果要在SQL命令提示符(sqlplus.exe)中执行它,则可以使用
exec read_file;
If you want to execute it inside some other program then you need to specify which programming language you're using. 如果要在其他程序中执行它,则需要指定使用的编程语言。 The answer will vary depending on that.
答案将因情况而异。
In SQL*Plus : 在SQL * Plus中 :
EXEC[UTE] procedure_name;
To call it within PL/SQL : 要在PL / SQL中调用它:
BEGIN
procedure_name;
END;
/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.