Download a table or some columns of the table to a text file. Temporary tables with automatically generated name are also supported (name specified with the "@" symbol).
1 table.unload
<table.unload
columns='columns'
date-format='date-format'
decimal-format='decimal-format'
delimiter='delimiter'
enclosing-char='enclosing-char'
encoding='encoding'
gzip='gzip'
qrycond='qrycond'
orderby='orderby'
table='table'
>
<file /> ?
</table.unload>
Attributes | |||||
---|---|---|---|---|---|
Name | Type | Required | Default | Description | |
Acolumns | string | List of columns (separated by comma) of the desired table that you want to download. If not specified, all columns will be downloaded. | |||
Adate-format | string | Date type value format. | |||
Adecimal-format | string | Decimal Type Value Format. | |||
Adelimiter | string | Character separator of the fields in the output. If not specified, default character is |. | |||
Aenclosing-char | string | Character that allows to include the separator character. That is, when the separator character is within the area defined by the character defined here, it is not evaluated as a separator but is taken as the literal value of the column in which it is located. This always applies and by default it is the double quote [""]. It has the same effect as for the table.load function. | |||
Aencoding | string | OS encoding | Indicates the character encoding of the data that is downloaded. | ||
Agzip | string | Sin definir.. | |||
Aqrycond | string | Selection condition. | |||
Aorderby | string | Order by of the selection. | |||
Atable | string | Table name. |
Arguments | |||||
---|---|---|---|---|---|
Name | Type | Required | Unique | Nullable | Description |
Efile | file | File where the data will be written. |
Exceptions
requires 1 arguments, received: [...]
Wrong number of arguments specified.
Download all columns of a table.
<xsql-script name='table_unload_sample1'> <body> <table name='persones'> <column name='dni' type='char' size='9' /> <column name='nom' type='varchar' size='20' /> <column name='cognom' type='varchar' size='25' /> </table> <insert table='persones'> <column name='dni'>X58847731</column> <column name='nom'>Pedro</column> <column name='cognom'> Martinez de la Rosa</column> </insert> <insert table='persones'> <column name='dni'>X58847732</column> <column name='nom'>Juan</column> <column name='cognom'>Sebastina veron</column> </insert> <insert table='persones'> <column name='dni'>988377456</column> <column name='nom'>Ramiro</column> <column name='cognom'>Sanchez ordoñez</column> </insert> <table.unload table='persones'> <file name='export.unl' /> </table.unload> <file.in.open id='in1'><file name='export.unl' /></file.in.open> <println><file.in.readAll id='in1' /></println> <drop table='persones' /> </body> </xsql-script>
El resultado de la ejecución del ejemplo sería el siguiente:
X58847731|Pedro| Martinez de la Rosa| X58847732|Juan|Sebastina veron| 988377456|Ramiro|Sanchez ordoñez|
Descargar algunas columnas con un delimitador de campos ;.
<xsql-script name='table_unload_sample2'> <body> <table name='persones'> <column name='dni' type='char' size='9' /> <column name='nom' type='varchar' size='20' /> <column name='cognom' type='varchar' size='25' /> </table> <insert table='persones'> <column name='dni'>X58847731</column> <column name='nom'>Pedro</column> <column name='cognom'> Martinez de la Rosa</column> </insert> <insert table='persones'> <column name='dni'>X58847732</column> <column name='nom'>Juan</column> <column name='cognom'>Sebastina veron</column> </insert> <insert table='persones'> <column name='dni'>988377456</column> <column name='nom'>Ramiro</column> <column name='cognom'>Sanchez ordoñez</column> </insert> <table.unload table='persones' columns='dni,nom' delimiter=';'> <file name='export.unl' /> </table.unload> <file.in.open id='in1'> <file name='export.unl' /> </file.in.open> <println> <file.in.readAll id='in1' /> </println> <drop table='persones' /> </body> </xsql-script>
The result of the example execution would be as follows::
X58847731;Pedro; X58847732;Juan; 988377456;Ramiro;
The delimiter that should be used to obtain a tab-separated content is:
delimiter='	'
Download some columns from a DB with UTF-8 encoding to an SO with another encoding and that the field delimiter is tabulation.
<xsql-script name='table_unload_sample3'> <body> <table name='persones'> <column name='dni' type='char' size='9' /> <column name='nom' type='varchar' size='20' /> <column name='cognom' type='varchar' size='25' /> </table> <insert table='persones'> <column name='dni'>X58847731</column> <column name='nom'>Pedro</column> <column name='cognom'> Martinez de la Rosa</column> </insert> <insert table='persones'> <column name='dni'>X58847732</column> <column name='nom'>Juan</column> <column name='cognom'>Sebastina veron</column> </insert> <table.unload table='persones' columns='dni,nom' encoding='utf-8' elimiter='	'> <file name='export.unl' /> </table.unload> <drop table='persones' /> </body>
El resultado de la ejecución del ejemplo sería el siguiente:
X58847731 Pedro X58847732 Juan