Redirect Results to a File

Redirect the result of one or more SAP HANA HDBSQL commands to a file.

Prerequisites

To redirect results to a file, you must be logged on to the database.

Procedure

  1. Run the following command:
    \o <file>

    You must enter the full path of the file.

  2. Run the command whose result is being redirected to the file.
    To run multiple commands in succession, press Enter after each command.
  3. To stop redirection to a file, run the following command: \o.

Example

To export a list of all schemas and all entries in the table HOTEL.CUSTOMER to an external file, perform the following steps.

  1. Log onto the SAP HANA database as user MONA with the password RED by running the following command:

    hdbsql -n localhost -i 1 -u MONA, RED
  2. Create the file c:\tmp\redirected.txt then redirect the command result(s) to this file by running the following command:

    \o c:\tmp\redirected.txt 
  3. Request information about all schemas by running the following command: \ds
  4. Select all rows in the table HOTEL.CUSTOMER by executing the following statement:

    SELECT * FROM HOTEL.CUSTOMER
  5. Stop redirection to the file by running \o.

The redirected.txt file now contains the following content:

| Schema | Owner name | 
| ------ | --------------- | 
| MDX_TE | SYSTEM | 
| SECURI | SECURITY1 | 
| SOP_PL | SYSTEM | 
| SYS | SYS | 
| SYSTEM | SYSTEM | 
| _SYS_B | _SYS_REPO | 
| _SYS_B | _SYS_REPO | 
| _SYS_R | _SYS_REPO | 
| _SYS_S | _SYS_STATISTICS | 
| CNO | TITLE | FIRSTNAME | NAME | ZIP | ADDRESS| 
| ------ | ------- | ---------- | ---------- | ----- | -------| 
| 3200 | Company | ? | Datasoft | 90018 | 486 Maple Str.| 
| 3400 | Mrs | Mary | Griffith | 20005 | 3401 Elder Lane| 
| 3500 | Mr | Martin | Randolph | 60615 | 340 MAIN STREET, #7| 
| 3600 | Mrs | Sally | Smith | 75243 | 250 Curtis Street| 
| 3700 | Mr | Mike | Jackson | 45211 | 133 BROADWAY APT. 1| 
| 3900 | Mr | George | Howe | 75243 | 111 B Parkway, #23| 
| 4000 | Mr | Frank | Miller | 95054 | 27 5th Str., 76| 
| 4400 | Mr | Antony | Jenkins | 20903 | 55 A Parkway, #15|