DECLARE
data_line VARCHAR2(200); -- Data line read from input file
data_file UTL_FILE.FILE_TYPE; -- Data file handle
my_dir VARCHAR2(250); -- Directory containing the data file
my_filename VARCHAR2(50);
BEGIN
my_dir := 'c:\temp';
my_filename := 'Lab4AData.dat';
my_file := UTL_FILE.FOPEN(my_dir, my_filename, 'r');
LOOP;
UTL_FILE.GET_LINE(data_file, data_line);
EXCEPTION
WHEN no_data_found THEN
DBMS_OUTPUT.PUT_LINE('Finished');
exit;
END LOOP;
END;
/
问题是我甚至无法启动此匿名代码块。首先,我只是尝试打开我的数据文件并阅读它,然后从那里构建。但我甚至无法打开文件。
SQL Developer错误报告立即启动
Error starting at line 5 in command: DECLARE
然后重复代码块并添加:
ORA-06550: line 12, column 8: PLS-00103: Encountered the symbol ";" when expecting one of the following: ( begin case declare exit for goto if loop mod null pragma raise return select update while with <an identifier> <a double-quoted delimited-identifier> <a bind variable> << continue close current delete fetch lock insert open rollback savepoint set sql execute commit forall merge pipe purge The symbol "exit" was substituted for ";" to continue. ORA-06550: line 15, column 3: PLS-00103: Encountered the symbol "EXCEPTION" when expecting one of the following: ( begin case declare end exit for goto if loop mod null pragma raise return select update while with <an identifier> <a double-quoted delimited-i 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error. *Action:
答案 0 :(得分:1)
尝试以下方法:
DECLARE
data_line VARCHAR2(200); -- Data line read from input file
data_file UTL_FILE.FILE_TYPE; -- Data file handle
my_dir VARCHAR2(250); -- Directory containing the data file
my_filename VARCHAR2(50);
BEGIN
my_dir := 'c:\temp';
my_filename := 'Lab4AData.dat';
data_file := UTL_FILE.FOPEN(my_dir, my_filename, 'r');
LOOP
UTL_FILE.GET_LINE(data_file, data_line);
-- add code to do something with data_line here
END LOOP;
EXCEPTION
WHEN no_data_found THEN
DBMS_OUTPUT.PUT_LINE('Finished');
UTL_FILE.FCLOSE(data_file);
END;
@ ShannonSeverance关于将目录对象与UTL_FILE.FOPEN一起使用的评论是合适的,除非你的DBA没有接受它们的使用,并且坚持坚持使用“久经考验的”INIT.ORA参数UTL_FILE_DIR。不要问我怎么知道...: - )
分享并享受。