Please enable JavaScript to view this site.

R:BASE 11 Beginners Tutorial

Navigation: Lesson 10 - Maintaining a Database

More on the UNLOAD Command

Scroll Prev Top Next More

The UNLOAD command also has the "AS ASCII" or "AS CSV" options for creating a file of data only, with no R:BASE commands, which will even unload the data from computed columns or expressions.

 

The AS ASCII/CSV options create a delimited ASCII file of data with no R:BASE commands. There are no SET commands or LOAD tblname command. The file is delimited with commas (or the current DELIMIT setting) separating the fields, and text data enclosed in single quotes (or the current QUOTE setting). The options are used to create a file to transfer data to another program, or to a different table. A file created using UNLOAD DATA...AS ASCII/CSV is put back into a database using the LOAD command. Only one table can be unloading to a file using the AS ASCII/CSV options. There are no R:BASE commands separating the data from different tables.

 

The UNLOAD command assumes that the data is returning to an R:BASE database. UNLOAD includes R:BASE commands that set the database environment and identify the table to load the data into. Since the data is loaded back into an R:BASE table, data for computed columns is not unloaded. It is re-computed as the data is loaded. The AS ASCII/CSV options include no R:BASE commands and is just data. As such, UNLOAD DATA...AS ASCII/CSV includes the data from computed columns in the output file. In addition, the AS ASCII/CSV options allow the use of expressions in the USING collist parameter.

 

For example, the code below creates the file that follows it:

 

UNLOAD DATA FOR Employee USING +

EmployeeID, (EmployeeFirstName & EmployeeLastName) , EmployeeAddress, + (EmployeeCity + ',' & EmployeeState & EmployeeZip) AS ASCII

 

102, 'June Wilson', '3278 Summit Drive', 'Seattle, WA 98115'

129, 'Ernest Hernandez', '12390 Windermere Dr.', 'Seattle, WA 98115'

131, 'John Smith', '3050 N.E. 41st', 'Seattle, WA 98105'

133, 'Peter Coffin', '4105 29th Ave N.E.', 'Duvall, WA 98004'

160, 'Mary Simpson', '101 West Mercer', 'Redmond, WA 98052'

165, 'Darnell Williams', '8806 88th Street', 'Seattle, WA 98103'

166, 'John Chou', '5001 Main Street', 'Woodinville, WA 98072'

167, 'Sandi Watson', '1002 S. Front Ave.', 'Redmond, WA 98052'

 

The full name and the city, state and zip code are considered single fields. This option makes it easy to format the data for transfer to other software programs. A WHERE clause and an ORDER BY clause can also be used when a single table is unloaded.

 

The UNLOAD DATA FROM <tablename> AS ASCII/CSV command specification will not work with columns where LOB data exists. If you have the requirement to unload table data in an ASCII or CSV format from a table that uses LOB data, you must add the USING collist parameter to the command in order to capture the text data.