Export LOB (BLOB / CLOB) data to files

mssql-cmd - SQL Server interactive and batch query command-line tool »

Download mssql-cmd Free Trial »

mssql-cmd writes each LOB value to its own file. The table can store the file name and extension in columns, or you can use a serial number and a fixed extension.

parameters:

schema: schema name (for MySQL: database name)

table: table name

lobfield: the LOB column to export (BLOB, BYTEA, VARBINARY, CLOB, TEXT, NVARCHAR(MAX))

namefield: use this column value as the file name (otherwise 1, 2, 3, ...)

extfield: use this column value as the file extension

fileext: fixed file extension

folder: output folder

where: optional WHERE clause

countpersub: create a subfolder every N exported files

buffer: fetch batch size

Example

mssql-cmd> exportlob table=t_file lobfield=filedata namefield=id fileext=dat
      > folder="e:\temp\lob" where="id < 10";

Batch example

mssql-cmd dsn="user:password@host:1433/dbname" task=exportlob table=t_file lobfield=filedata namefield=id fileext=dat folder="e:\temp\lob" where="id < 10" quit=y

See also import LOB files, export CLOB/TEXT in a text file.