sql server 读写磁盘文件
1.读取磁盘文件
DECLARE @data VARBINARY(MAX) SELECT @data = BulkColumn FROM OPENROWSET(BULK 'c:\demo.exe', SINGLE_BLOB) MyFile SELECT @data
2.写入磁盘文件
DECLARE @DATA VARBINARY(MAX) = (SELECT TOP 1 Data FROM " + tableName + @") DECLARE @filepath VARCHAR(MAX) = '" + destFilePath + @"' DECLARE @ObjectToken INT EXEC sp_OACreate 'ADODB.Stream', @ObjectToken OUTPUT EXEC sp_OASetProperty @ObjectToken, 'Type', 1 EXEC sp_OAMethod @ObjectToken, 'Open' EXEC sp_OAMethod @ObjectToken, 'Write', NULL, @DATA EXEC sp_OAMethod @ObjectToken, 'SaveToFile', NULL, @filepath, 2 EXEC sp_OAMethod @ObjectToken, 'Close' EXEC sp_OADestroy @ObjectToken SELECT @filepath
桂棹兮兰桨,击空明兮溯流光。