尝试在pl sql中写入文件时路径无效 [英] invalid path while trying to write the file in pl sql

查看:125
本文介绍了尝试在pl sql中写入文件时路径无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在oracle pl sql(10 g)中写入文本文件. 我已经创建了目录,但它仍然存在,但路径仍然无效. 下面是代码.

i am trying to write to a text file in oracle pl sql(10 g). i have created the directory it is existing but still getting invalid path. below is the code.

CREATE DIRECTORY test_dir AS 'c:\';
-- CREATE DIRECTORY test_dir AS '/tmp';

DECLARE
  fileHandler UTL_FILE.FILE_TYPE;
BEGIN
  fileHandler := UTL_FILE.FOPEN('test_dir', 'test_file.txt', 'W');
  UTL_FILE.PUTF(fileHandler, 'Writing TO a file\n');
  UTL_FILE.FCLOSE(fileHandler);
EXCEPTION
  WHEN utl_file.invalid_path THEN
     raise_application_error(-20000, 'ERROR: Invalid PATH FOR file.');
END;
/

the following is the error:
*
ERROR at line 1:
ORA-20000: ERROR: Invalid PATH FOR file.
ORA-06512: at line 9

推荐答案

Oracle区分大小写.但是,除非用双引号引起来,否则SQL和PL/SQL中的所有名称都会自动转换为大写.

Oracle is case sensitive. But all names in SQL and PL/SQL are automatically converted to uppercase unless enclosed in double quotes.

所以:

CREATE DIRECTORY test_dir AS 'c:\';

实际执行为:

CREATE DIRECTORY TEST_DIR AS 'c:\';

因此,您定义的目录称为TEST_DIR.如果在字符串中引用它(与SQL或PL/SQL中的符号名称相反),则必须使用'TEST_DIR'. 'test_dir'无法正常工作.

Therefore the directory you have defined is called TEST_DIR. If you refer to it in a string (as opposed to a symbol name in SQL or PL/SQL), you must use 'TEST_DIR'. 'test_dir' won't work.

因此尝试:

fileHandler := UTL_FILE.FOPEN('TEST_DIR', 'test_file.txt', 'W');

这篇关于尝试在pl sql中写入文件时路径无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆