在循环中的交互式SQL中卸载



我不想做以下事情:导出一个大表到文件系统,从db得到一些响应。

对于这个,我尝试在块中卸载表(见下面的代码)

我尝试了Sybase Central - Interactive SQL中的语句,它一直抱怨在卸载行(odbc sstatus 42000)有语法错误

如果我只执行注释行,它会执行我想要的前1000行。所以语法本身似乎是正确的。我错过了什么(或者有一个更简单的方法从一个很长时间运行的db命令获得反馈?)

CREATE VARIABLE  @max_id INT;
CREATE VARIABLE  @min_id INT;
CREATE VARIABLE  @start_id INT;
CREATE VARIABLE  @end_id INT;
SELECT  @min_id = min(id) , @max_id = max(id) FROM testtable;
SELECT  @start_id = @min_id , @end_id   = @min_id + 1000 ;
//UNLOAD (SELECT * FROM testtable WHERE id BETWEEN @start_id AND @end_id) TO 'c:temptest.dat' ENCODING 'UTF8' APPEND ON;
WHILE    @end_id <= @max_id 
BEGIN
    UNLOAD (SELECT * FROM testtable WHERE id BETWEEN @start_id AND @end_id) TO 'c:temptest.dat' ENCODING 'UTF8' APPEND ON;
    SELECT  @start_id = @end_id + 1 ;
    SELECT  @end_id   = @end_id + 1000 ;
    MESSAGE convert(varchar, @start_id);
END;

编辑:

WHILE    @end_id <= @max_id LOOP
...
END LOOP;

似乎在交互式sql中做了我想要的,但我是第一部分的错误是什么?对于循环,它不能从外部命令(例如调用BeginExecuteNonQuery)

CREATE VARIABLE  @max_id INT;
CREATE VARIABLE  @min_id INT;
CREATE VARIABLE  @start_id INT;
CREATE VARIABLE  @end_id INT;
SELECT  @min_id = min(id) , @max_id = max(id) FROM testtable;
SELECT  @start_id = @min_id , @end_id   = @min_id + 1000 ;
//UNLOAD (SELECT * FROM testtable WHERE id BETWEEN @start_id AND @end_id) TO 'c:temptest.dat' ENCODING 'UTF8' APPEND ON;
WHILE    @end_id <= @max_id Loop
    UNLOAD (SELECT * FROM testtable WHERE id BETWEEN @start_id AND @end_id) TO 'c:temptest.dat' ENCODING 'UTF8' APPEND ON;
    SET @start_id = @end_id + 1 ;
    SET @end_id   = @end_id + 1000 ;
END Loop;

请查收更正后的代码。只是出于好奇,在块中卸载有什么特殊的原因吗?

相关内容

  • 没有找到相关文章

最新更新