oracle PL/SQL TEXT_IO 包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5708686/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:23:24  来源:igfitidea点击:

PL/SQL TEXT_IO package

sqloracleplsqlsqlplus

提问by ktm5124

I am trying to write to a local file from a PL/SQL script. In order to do this, I am attempting to use the TEXT_IO package in PL/SQL.

我正在尝试从 PL/SQL 脚本写入本地文件。为了做到这一点,我试图在 PL/SQL 中使用 TEXT_IO 包。

DECLARE
file_out text_io.file_type;
len number;
blob_file blob;
my_var RAW(50);
bstart NUMBER := 1;
bytelen NUMBER := 50;

BEGIN

SELECT xxx
INTO blob_file
FROM yyy
WHERE zzz

dbms_lob.read(blob_file, bytelen, bstart, my_var);    
file_out := text_io.fopen('local_file_path', 'w');
text_io.put_raw(file_out, my_var);
text_io.fflush(file_out);
text_io.fclose(file_out);

END;
/

quit

However, when I run this script I get the error,

但是,当我运行此脚本时,出现错误,

PLS-00201: identifier 'TEXT_IO.FILE_TYPE' must be declared

Does anyone know how I can fix this error, and how I can write the contents of the blob to a file as I am attempting to do?

有谁知道我如何修复此错误,以及如何在尝试时将 blob 的内容写入文件?

Thanks,
ktm

谢谢,
ktm

回答by Justin Cave

TEXT_IOexists only in Oracle Forms which had (in the old client/ server days) a client-side PL/SQL interpreter. If you are using SQL*Plus to execute PL/SQL, as it appears you are doing here, the TEXT_IOpackage will not be available and you will not be able to write to a file on the client machine (barring the odd setup where the server mounts a drive that your client is exposing and then proceeds to write to that mount).

TEXT_IO仅存在于具有(在旧客户端/服务器时代)客户端 PL/SQL 解释器的 Oracle Forms 中。如果您正在使用 SQL*Plus 来执行 PL/SQL,正如您在此处所做的那样,该TEXT_IO程序包将不可用,您将无法写入客户端计算机上的文件(除非在服务器端进行奇怪的设置)挂载您的客户端正在公开的驱动器,然后继续写入该挂载)。

Now, you can generally use SQL*Plus to directly write to a local file using the SPOOL command. Unfortunately, it's probably unlikely that you could do this for a BLOB in the general case.

现在,您通常可以使用 SQL*Plus 使用 SPOOL 命令直接写入本地文件。不幸的是,在一般情况下,您可能不太可能为 BLOB 执行此操作。

回答by milan

The general approach is: write a file on the server and download it. Or event better, don't write it down, just stream it. Quite complicated, yes.

一般的做法是:在服务器上写一个文件,然后下载。或者事件更好,不要写下来,只需流式传输。相当复杂,是的。

回答by Klas Lindb?ck

If you want to create a file on the server UTL_FILE is a good choice. This package can write files in any DIRECTORY specified in the database. A DIRECTORY is created in Oracle using CREATE DIRECTORY and can be linked to any writable directory accessible by the DBMS (server-side).

如果要在服务器上创建文件 UTL_FILE 是一个不错的选择。这个包可以在数据库中指定的任何 DIRECTORY 中写入文件。目录是在 Oracle 中使用 CREATE DIRECTORY 创建的,并且可以链接到 DBMS(服务器端)可访问的任何可写目录。