Skip to content
The latest version of DbVisualizer was released 2024-12-04DOWNLOAD HERE ->

@export - Export query result

Only in DbVisualizer Pro

This feature is only available in the DbVisualizer Pro edition.

Instead of viewing and exporting query results from Result Set grids, you can export the result of one or more queries to a file from a script. For huge results, this may be the preferred choice due to memory constraints.

Introduction

To do a simple export of the result from a query, create a script as:

  1. an @export on command,
  2. an @export set command,
  3. one or more queries,
  4. an @export off command.

Here is a basic example:

@export on;
@export set filename="c:\backups\orders.csv";
select * from Orders;
@export off;

The @export set command is used to define how the exported output should be generated. It reads parameters in the following syntax:

@export set parameter1="value" parameter2="value" ...;

The parameter name is case-insensitive, and the value is also case-insensitive for parameters requiring a defined value as per the parameter descriptions below. The supported parameters is based on the format parameter for the output which can be any of:

  • format="CSV" (default)
  • format="HTML"
  • format="XML"
  • format="SQL"
  • format="TXT"
  • format="Excel"
  • format="JSON"

Parameters for @export set

The following chapters lists all supported parameters.

Generic parameters for all output formats

These parameters are valid for all output formats.

ParameterDefaultValid Values
AppendFilefalse
  • true
  • false
  • clear (start with a new file for the first result and then append following result sets to it)
Note that when format="Excel" and appending to an existing excel file any manually added formatting in the old sheets will be lost.
BinaryFileDirPath for data files when BinaryFormat="File", see Exporting a Table for details. Note: Variables for column names must include the scope variable option when entered manually into a script, e.g. C:\tmp\${dbvis-date}$\${COUNTRIES||||||scope=post}$
BinaryFormatDon't Export
  • Don't Export
  • Size
  • Value
  • Hex
  • Base64 File
  • BooleanFalseFormatfalse
  • false
  • no
  • 0
  • off
    (you can specify custom entries separated by comma)
  • BooleanTrueFormattrue
  • true
  • yes
  • 1
  • on
    (you can specify custom entries separated by comma)
  • CLOBFileDirPath for data files when CLOBFormat="File", see Exporting a Table for details. Note: Variables for column names must include the scopevariable option when entered manually into a script, e.g. C:\tmp\${dbvis-date}$\${COUNTRIES||||||scope=post}$.clob
    CLOBFormatDon't Export
  • Don't Export
  • Size
  • Value
  • File
  • DateFormatyyyy-MM-ddSee valid formats in Changing the Data Display Format document
    DecimalNumberFormatUnformattedSee valid formats in Changing the Data Display Format document
    DecimalNumberSeparator.The Decimal separator character to use. Note: this setting have no effect when DecimalNumberFormat or NumberFormat is Unformatted.
    DestinationFile
  • File
  • Clipboard
  • SQL Commander
  • EncodingUTF-8Check supported encodings for all encodings. (Use the encoding in the Canonical Name for java.nioAPI column).
    FilenameThe output file name for exported file. This parameter is required if Destination="file". If setting a relative filename the output path depends on the current working folder set by any @cd command.
    FormatBased on file extension, or CSV if not specified.
  • CSV
  • HTML
  • XML
  • SQL
  • TXT
  • Excel
  • JSON
    If Format is not specified, the file extension is used to determine the format. If there is no recognized file extension, CSV is used as the default.
  • NumberFormatUnformattedSee valid formats in Changing the Data Display Format document.
    NumberGroupingSeparator,The number grouping separator to use. Example using NumberFormat=“#,###” and NumberGroupingSeparator="." the formatting of 2000 will produce the result 2.000. If using NumberGroupingSeparator="space" the result will be 2 000. Note: this setting have no effect when DecimalNumberFormat or NumberFormat is Unformatted.
    QuoteAllValuesfalse
  • true
  • false
  • QuoteDuplicateEmbeddedtrue
  • true
  • false
    (quote char is the same as QuoteTextData)
  • QuoteTextDataNone
  • None
  • Single
  • Double
  • SettingsThe path to an XML file containing all settings
    ShowNullAs(null)The text representation for null values.
    TextFunctionCan be set if DbVisualizer cannot determine the value for the ${dbvis-object}$ variable
    TimeFormatHH:mm:ssSee valid formats in Changing the Data Display Format document
    TimeStampFormatyyyy-MM-dd HH:mm:ss.SSSSSSSee valid formats in Changing the Data Display Format document

    CSV parameters

    ParameterDefaultValid Values
    CsvColumnDelimiter\t (TAB)The delimiter between columns. In addition to literals Unicode Code Points such as \u2656 can be used.
    CsvColumnHeaderIsColumnAliastrue
  • true
  • false
  • CsvIncludeColumnHeadertrue
  • true
  • false
  • CsvIncludeColumnHeaderPerResultfalse
  • true
  • false
    (adds separate column headers for each query e.g. when you have several selects with different structure of the result sets)
  • CsvIncludeSQLCommandDon't Include
  • Don't Include
  • Top
  • Bottom
  • CsvRemoveNewlinesfalse
  • true
  • false
  • CsvRowCommentIdentifier
    CsvRowDelimiter\n
  • \n (Linux/macOS)
  • \r\n (Windows)
    (you may set this to any literal)
  • CsvSplitFileSize-1Split the result over multiple files if it is larger than the specified size, or -1 to never split.
    The size must be specified as: size [ K | M | G ]

    HTML parameters

    ParameterDefaultValid Values
    HtmlColumnHeaderIsColumnAliastrue
  • true
  • false
  • HtmlConvertCharstrue
  • true
  • false
    Set to false if you have HTML code in the exported data, so that e.g. < and > characters are not converted to &lt; and &gt;
  • HtmlFooter[ Generated by: DbVisualizer version ]Any text to use in the document footer. Can be set to blank to remove the footer.
    HtmlIncludeSQLCommandfalse
  • true
  • false
  • HtmlIntroTextAny description
    HtmlPerTableHeaderHTML code that describes the table. To fit into the rest of the HTML code, it must start with <tr> and end with </tr>. The pre-defined DbVisualizer variables can be used, e.g. ${dbvis-object}$ to include the table name.
    HtmlPerTableHeaderGridExportWhen using the append parameter, use this paramater to set a header for each result set that is exported.
    HtmlTitleThe title of the HTML page.

    XML parameters

    ParameterDefaultValid Values
    XmlColumnHeaderIsColumnAliastrue
  • true
  • false
  • XmlIncludeSQLCommandfalse
  • true
  • false
  • XmlIntroTextDescription of the XML.
    XmlStyleDbVisualizer
  • DbVisualizer
  • XmlDataSet
  • FlatXmlDataSet
  • SQL parameters

    ParameterDefaultValid Values
    SqlAfterExportStmtsAny statements to include in the script after the SQL statements for the exported objects, e.g. set foreign_key_checks = 1;
    SqlBeforeExportStmtsAny statements to include in the script before the SQL statements for the exported objects, e.g. set foreign_key_checks = 0;
    SqlBeginIdentifierCharacter to use to begin a quoted identifier. Note: To specify a double-quote, you must duplicate it since double-quote is also used to enclose the parameter value.
    SqlBlockBeginDelimString to use to begin an SQL block when exporting complex DDL statements using the @ddl command.
    SqlBlockEndDelimString to use to end an SQL block
    SqlDelimitedIdentifierstrue
  • true
  • false
  • SqlEndIdentifierCharacter to use to end a quoted identifier. Note To specify a double-quote, you must duplicate it since double-quote is also used to enclose the parameter value.
    SqlGenCreateWithStoragefalse
  • true
  • false
    Only applicable for Db2 and Cassandra.
  • SqlGenerateSqlModefalse
  • true
  • false
    Only applicable for MariaDB and MySQL.
  • SqlGroupByObject
  • Object
  • Statement
    Set to Object to generate DROP, CREATE, INSERT, and ALTER statements (where applicable) for each exported object in turn.
    Set to Statement to group all statements of the same type together, e.g. first DROP statements for all exported objects, then CREATE statements for all exported objects, etc.
  • SqlIncludeAutoGeneratedValuestrue
  • true
  • false
    Set to false to exclude columns declared as AUTO_INCREMENT or IDENTITY in the INSERT statements.
  • SqlIncludeCreateDDLfalse
  • true
  • false
  • SqlIncludeSQLCommandDon't Include
  • Don't Include
  • Top
  • Bottom
  • SqlMergeStatementfalse
  • true
  • false
  • SqlMergeStatementMatchColumnsA comma-separated list of columns to use when matching rows
    SqlMergeTemplate
  • single-merge-sql92
  • single-merge-oracle INCLUDE EXAMPLES! SHOULD BE SAME FORMAT as SqlMultiRowInsertTemplate
  • SqlMultiRowInsertfalse
  • true
  • false
    If true Multiple rows are included in each INSERT statement. The number of rows to include in each INSERT statement is limited by the SqlMultiRowInsertLimit parameter.
  • SqlMultiRowInsertLimit10The maximum number of rows to include in a multirow INSERT.
    SqlMultiRowInsertTemplatemulti-insert-sql92The following show the formats and the INSERT syntax that is generated for one block having the SqlMultiRowInsertLimit="2" parameter set.

  • multi-insert-sql92
    INSERT INTO TAB (ID, FI, LA) VALUES
    (1, 'abc', 'def'),
    (2, 'abc', 'def');
  • multi-insert-cassandra
    --/
    BEGIN BATCH
    INSERT INTO TAB (ID, FI, LA) VALUES (1, 'abc', 'def');
    INSERT INTO TAB (ID, FI, LA) VALUES (2, 'abc', 'def');
    APPLY BATCH;
    /
  • multi-insert-oracle
    INSERT ALL
    INTO TAB (ID, FI, LA) VALUES (1, 'abc', 'def')
    INTO TAB (ID, FI, LA) VALUES (2, 'abc', 'def')
    SELECT 1 FROM dual;
  • multi-insert-union
    INSERT INTO TAB (ID, FI, LA)
    SELECT 1, 'abc', 'def' UNION ALL
    SELECT 2, 'abc', 'def';
  • SqlQualifierQualifier to use when qualifying table names. If not set, DbVisualizer tries to determine the schema and use it as the qualifier.
    SqlQualifyColumnNamefalse
  • true
  • false
  • SqlQualifyObjectNametrue
  • true
  • false
  • SqlRowCommentIdentifier--
    SqlSeparator;Statement separator character.
    SqlSplitFileSize-1Split the result over multiple files if it is larger than the specified size, or -1 to never split.
    The size must be specified as: size [ K | M | G ]
    TableNameCan be set if DbVisualizer cannot determine the value for the ${dbvis-object}$ variable

    TXT parameters

    ParameterDefaultValid Values
    TxtAlignNumbersleft
  • left
  • right
  • TxtColumnDelimiter\t (TAB)The delimiter between columns. In addition to literals it can also be specified using Unicode Code Points as \u2656.
    TxtColumnHeaderIsColumnAliastrue
  • true
  • false
  • TxtIncludeColumnHeadertrue
  • true
  • false
  • TxtIncludeColumnHeaderPerResultfalse
  • true
  • false
  • TxtIncludeSQLCommandDon't Include
  • Don't Include
  • Top
  • Bottom
  • TxtRemoveNewlinesfalse
  • true
  • false

  • Removes newlines when formatting text. This includes when displaying binary values as text.
    TxtRowCommentIdentifierFIX!
    TxtRowDelimiter\n
  • \n (Linux/macOS)
  • \r\n (Windows)
    (you may set this to any literal)
  • TxtSplitFileSize-1Split the result over multiple files if it is larger than the specified size, or -1 to never split.
    The size must be specified as: size [ K | M | G ]
    TxtTruncateLength-1Specifies the length at which truncation of a column will happen.

    Excel parameters

    ParameterDefaultValid Values
    ExcelAutoResizeColumnsfalse
  • true
  • false
  • ExcelColumnHeaderIsColumnAliastrue
  • true
  • false
  • ExcelFileFormatIf ExcelFileFormat is not specified, the file extension is used to set this parameter to one of xls for binary (or legacy) Excel max 65 535 rows, or xlsx which is the current and recommended format.
    ExcelIncludeColumnHeadertrue
  • true
  • false
  • ExcelIncludeSQLCommandfalse
  • true
  • false
  • ExcelIntroTextA description of the Excel document.
    ExcelSheetNameUsed when exporting to excel. Sets the name of exported excel sheet.
    ExcelTextDateTimetrue
  • true
  • false
    Convert date, time and timestamp data to text in the Excel file if true.
  • ExcelTextOnlyfalse
  • true
  • false
    Convert numeric values to text in the Excel file if true.
  • ExcelTitleAny title

    JSON parameters

    ParameterDefaultValid Values
    JsonColumnHeaderIsColumnAliastrue
  • true
  • false
  • JsonSplitFileSize-1Split the result over multiple files if it is larger than the specified size, or -1 to never split.
    The size must be specified as: size [ K | M | G ]
    JsonStyleArray
  • Array
  • Rows
  • Here are a few examples using some of these settings.

    Automatic table name to file mapping

    This example shows how to make the filename the same as the table name in the select statement. The example also shows several select statements. Each will be exported in the SQL format. Since the filename is defined to be automatically set, this means that there will be one file per result set and each file is named by the name of its table.

    @export on;
    @export set filename="C:\backups\${dbvis-object}$" format="sql";
    select * from Orders;
    select * from Products;
    select * from Transactions;
    @export off;
    

    There must be only one table name in a select statement to automatically set the filename with the ${dbvis-object}$ variable, i.e., if the select joins from several tables or pseudo tables are used, you must explicitly name the file.

    The ${dbvis-object}$ variable is not substituted with a table name if using the AppendFile="true/clear" parameter.

    Multiple results to a single file

    This example shows how all result sets can be exported to a single file. The AppendFile parameter supports the following values.

    • true
      The following result sets will all be exported to a single file
    • false
      Turn off the append processing
    • clear
      Same as the true value but this will in addition clear the file before the first result set is exported
    @export on;
    @export set Format="sql" Filename="C:\Backups\alltables.sql" AppendFile="clear";
    select * from Orders;
    select * from Products;
    select * from Transactions;
    @export off;
    

    Using predefined settings

    If you save settings when exporting a table or a schema, you can use the Settings parameter to reference the settings file.

    @export on;
    @export set Settings="C:\tmp\htmlsettings.xml" Filename="C:\backups\${dbvis-object}$";
    select * from Orders;
    select * from Products;
    select * from Transactions;
    @export off;
    

    Limit the number of exported rows

    You can use the @set maxrows command to override the Max Rows field value specified in the SQL Commander tab toolbar.

    @set maxrows 10;
    @export on;
    @export set Format="sql" Filename="c:\Backups\alltables.sql";
    select * from Orders;
    select * from Products;
    select * from Transactions;
    @export off;
    

    @set maxrows="-1"; will export all rows.

    Other Ways to Export Table Data