oracle 在不知道文件名的情况下使用 UTL_FILE.FRemove 从服务器删除文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32363099/
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
Delete file from server using UTL_FILE.FRemove without knowing the file name
提问by Ben O'Neill
I am a reporting analyst, who was asked to learn some PL/SQL to automate some processes. So I am almost finished, with one step standing in the way. I have a package that
我是一名报告分析师,他被要求学习一些 PL/SQL 来自动化一些流程。所以我几乎完成了,一步挡住了。我有一个包裹
- Loads a table with a query I wrote.
- Exports the results from that table to a .txt file on the server with the current_date tacked onto the file name .
- 用我写的查询加载一个表。
- 将结果从该表导出到服务器上的 .txt 文件,并将 current_date 附加到文件名上。
I am trying to delete the 3 files it creates using a wildcard, but I continually get errors such as "vendor_file.ia.*.txt is not defined":
我试图删除它使用通配符创建的 3 个文件,但我不断收到诸如“vendor_file.ia.*.txt 未定义”之类的错误:
- file_location is my path
- file_location 是我的路径
I can delete it no problem with:
我可以删除它没有问题:
utl_file.fremove(file_location,'vendor_file.ia.09.02.2015.txt');
utl_file.fremove(file_location,'vendor_file.il.09.02.2015.txt');
utl_file.fremove(file_location,'vendor_file.sd.09.02.2015.txt');
But obviously that won't delete it when it gets run next month. So am I missing a simple wildcard to search just for 'vendor_file.ia.*' And does the syntax look in Oracle?
但很明显,它不会在下个月运行时删除它。所以我错过了一个简单的通配符来搜索'vendor_file.ia.*' 并且语法在 Oracle 中查找吗?
If I didn't provide enough information please let me know!
如果我没有提供足够的信息,请告诉我!
Thanks a lot!
非常感谢!
回答by Turntablez
Old post but...
旧帖子但是...
You can make an external table list out a directory file contents. You could then write a loop to get your files names from the external table and execute utl_file.fremove
您可以使外部表列出目录文件的内容。然后您可以编写一个循环从外部表中获取您的文件名并执行 utl_file.fremove
回答by Richard Gambrell
You could use the preprocessor to run a shell script to delete the files. Oracle docs on preprocessor
您可以使用预处理器运行 shell 脚本来删除文件。 关于预处理器的 Oracle 文档
回答by Pankaj
This can be used to clear multiple files from the Oracle directorybegin
for i in (select filename from (select * from
table(RDSADMIN.RDS_FILE_UTIL.LISTDIR('DIR_NAME')) order by mtime) where filename like
'backup%')
loop
UTL_FILE.FREMOVE ('DIR_NAME', i.filename );
end loop;
end;
/
这可用于从 Oracle 目录中清除多个文件begin
for i in (select filename from (select * from
table(RDSADMIN.RDS_FILE_UTIL.LISTDIR('DIR_NAME')) order by mtime) where filename like
'backup%')
loop
UTL_FILE.FREMOVE ('DIR_NAME', i.filename );
end loop;
end;
/