SQL 存储过程中的文件

发布于 2024-09-06 03:34:44 字数 98 浏览 5 评论 0原文

我目前的任务是将存储在平面文件中的一些数据读取到我的数据库中并针对它运行报告。我遇到的一个问题是检查文件是否确实存在。有没有一个简单的函数来检查文件是否存在?

谢谢!

I'm currently tasked with reading some data that stored in a flat file into my database and run reports against it. The one problem I'm running into is checking to see if a file actually exists. Is there a simple function to check if the file exists?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

臻嫒无言 2024-09-13 03:34:44

只是谷歌搜索我发现这个 SQL DBA 和 MS SQL 提示。

Just googling I found this at SQL DBA and this at MS SQL tips.

深海少女心 2024-09-13 03:34:44

你在存储过程中进行 ETL 吗?!!我认为你不应该,只是因为你可以。

我建议您使用 SSIS 来实现此目的。在存储过程或 TSQL 中执行 ETL 并不是推荐的做法,事实上,它经常被用作不应该执行的操作的示例。

You are doing ETL in a stored procedure?!! I don't think you should, just because you can.

I recommend you use use SSIS for this. Doing ETL in Stored Proc or TSQL is not a recommended practice, in fact, it is frequently used as an example of what not to do.

岛歌少女 2024-09-13 03:34:44

我相信你可以这样做:

DECLARE @Path varchar(128) ,
 @FileName varchar(128)
 SET @Path = 'C:\'
 SET @FileName = 'FILE_NAME.EXT'

DECLARE @objFSys int
DECLARE @i int
DECLARE @File varchar(1000)

 SET @File = @Path + @FileName
 EXEC sp_OACreate 'Scripting.FileSystemObject', @objFSys out
 EXEC sp_OAMethod @objFSys, 'FileExists', @i out, @File
 IF @i = 1
  PRINT 'file exists'
 ELSE
  PRINT 'file does not exists'
 EXEC sp_OADestroy @objFSys 

本文 介绍了此方法和其他几种方法。

I believe you can do something like this:

DECLARE @Path varchar(128) ,
 @FileName varchar(128)
 SET @Path = 'C:\'
 SET @FileName = 'FILE_NAME.EXT'

DECLARE @objFSys int
DECLARE @i int
DECLARE @File varchar(1000)

 SET @File = @Path + @FileName
 EXEC sp_OACreate 'Scripting.FileSystemObject', @objFSys out
 EXEC sp_OAMethod @objFSys, 'FileExists', @i out, @File
 IF @i = 1
  PRINT 'file exists'
 ELSE
  PRINT 'file does not exists'
 EXEC sp_OADestroy @objFSys 

This article goes over this method and a couple others.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文