odbc load命令出现“无效的游标状态”错误

时间:2016-06-25 01:03:57

标签: odbc stata

这个神秘错误是什么意思?

> odbc load, exec("
> CREATE VOLATILE MULTISET TABLE vol_tab AS (
>         SELECT TOP 10 user_id FROM dw_users
> )
> WITH DATA
> PRIMARY INDEX(user_id)
> ON COMMIT PRESERVE ROWS;
> ") clear dsn("mozart");
The ODBC driver reported the following diagnostics
[Teradata][ODBC Teradata Driver] Invalid cursor state.
SQLSTATE=24000
r(693);

1 个答案:

答案 0 :(得分:1)

您收到此错误是因为您告诉Stata加载某些内容,但您的代码没有SELECT子句,而该子句不是表创建的一部分。如果在底部添加SELECT子句,它将起作用。

或者,如果您只想创建表,则可以使用odbc exec("SqlStmt")语法。

以下是一个例子:

/* Works */
odbc load, exec("
CREATE VOLATILE MULTISET TABLE vol_tab AS (
    SELECT TOP 10 user_id FROM dw_users
)
WITH DATA
PRIMARY INDEX(user_id)
ON COMMIT PRESERVE ROWS;

SELECT * FROM vol_tab;
") clear dsn("mozart") lowercase multistatement;
format user_id %20.0fc;
sort user_id;
list, clean noobs;

/*Also Works */
odbc exec("
CREATE VOLATILE MULTISET TABLE vol_tab AS (
    SELECT TOP 10 user_id FROM dw_users
)
WITH DATA
PRIMARY INDEX(user_id)
ON COMMIT PRESERVE ROWS;
"), dsn("mozart");

/* Fails: Load With No Bottom Select Clause */
odbc load, exec("
CREATE VOLATILE MULTISET TABLE vol_tab AS (
    SELECT TOP 10 user_id FROM dw_users
)
WITH DATA
PRIMARY INDEX(user_id)
ON COMMIT PRESERVE ROWS;
") clear dsn("mozart");