0
無法檢索文件夾中pdf文件的大小,下面的代碼返回表中的空列,我也想知道是否可以存儲文件名和大小都在一張表中。無法檢索文件夾中的pdf文件的大小
Create table #PDFFiles
(
PDFFile varchar(300)
)
Declare @param as varchar(100)
Declare @Path as varchar(1000)
Declare @PreparedBatch as Nvarchar(max);
Set @PreparedBatch =
'DECLARE @pdf pdf
SELECT @pdf = CAST(BulkColumn AS pdf)
FROM OPENROWSET(BULK ''?'', SINGLE_BLOB) AS x
INSERT dbo.PDFDocument (PDFdoc)
SELECT @pdf;';
Set @Path = 'C:\dump\'
Set @param = 'dir ' + @Path + '*.pdf /b'
Insert into #PDFFiles
Exec master..xp_cmdshell @param
Update #PDFFiles Set PDFFile = @Path + PDFFile
While Exists(select * from #PDFFiles where PDFFile is not null)
Begin
Declare @CurrentFile Table (PDFFile varchar(300));
Delete Top (1) from #PDFFiles
OUTPUT DELETED.PDFFile INTO @CurrentFile
Where PDFFile is not null
Declare @Batch as Varchar(max)
Select @Batch = Replace(@PreparedBatch,'?',PDFFile) from @CurrentFile
Exec (@Batch)
Delete from @CurrentFile
End
這是運行該代碼時,我正在錯誤
Column, parameter, or variable #1: Cannot find data type pdf.
Parameter or variable '@pdf' has an invalid data type.
當我將其更改爲varbinary時,出現此錯誤 類型pdf不是定義的系統類型。 – Zack
你在多個位置有這樣的定義:'SELECT @pdf = CAST(BulkColumn AS pdf)' –