2016-06-25 69 views
0

這個神祕錯誤是什麼意思?odbc加載命令「無效遊標狀態」錯誤

> 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); 
+0

我遇到的問題是經常,所以我決定創建爲後人一個很好的googleable答案。 –

回答

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"); 
相關問題