SQLAnywhere: How to write result of a query into a file with non-interactive session
-
12-12-2020 - |
题
I'm looking for a way to write resultset of a query to a file maybe analog of queryout
of MS SQL or the COPY
from PostgreSQL
When using something like
select count(*) from "table" OUTPUT TO 'results.txt' FORMAT TEXT
I'm getting
Could not execute statement. Syntax error near 'TO' on line 1 SQLCODE=-131, ODBC 3 State="42000" Line 1, column 1
When running it, as discribed in documentation like this:
select count(*) from "table";
OUTPUT TO 'results.txt' FORMAT TEXT
e.g. inside a procedure, I'm getting an error telling me that there is no result for being outputted.
解决方案 2
I found a solution for at least my problem. It's possible to put results into a temporary table and unload the temp table. So something like:
SELECT * INTO #tmpresultset FROM myTable
UNLOAD TABLE #tmpresultset to '/some/file'
其他提示
You can specify the OUTPUT
to a file in your SQL directly:
dbisql -c "connection-string" SELECT * FROM table; OUTPUT TO 'results.txt' FORMAT TEXT
As per the Sybase documentation.