| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.server -> Invalid cursor state
Hi!
I created this stored procedure with sql *plus and compiled it:
CREATE OR REPLACE PROCEDURE LondonWorkers(fName IN OUT VARCHAR2,lName
IN OUT VARCHAR2,adr IN OUT VARCHAR2)
AS
CURSOR workers_cursor IS
SELECT
firstname, familyname, address
FROM customers
WHERE address = 'London';
BEGIN
FOR customers IN workers_cursor LOOP
fName := customers.firstname;
lName := customers.familyname;
adr := customers.address;
EXIT WHEN workers_cursor%NOTFOUND;
END LOOP;
lstrcpy( (char *) pSqlStmt, "{CALL LondonWorkers(?,?,?)}");
rc = SQLExecDirect(hStmt, pSqlStmt, lstrlen((char *)
pSqlStmt));
if (rc != SQL_SUCCESS){
DisplayError(SQL_HANDLE_STMT, hStmt, (SQLCHAR *)"SQLExecDirect");
}
//it was okay till here.
//now display data
while ( rc == SQL_SUCCESS ){
rc = SQLFetch( hStmt );//it gives an error here
if ( rc == SQL_SUCCESS ){
ShowMessage(Data);
}
else{
if (rc != SQL_NO_DATA){
DisplayError(SQL_HANDLE_STMT,hStmt,(SQLCHAR *)"SQLFetch");
}
}
If I try to display, I get "invalid cursor state". I tried to do the
following:
string result;
while ( rc == SQL_SUCCESS ){
string result = result + "\t" + firstname;
result = result + "\t" + familyname;
result = result + "\t" + address;
ShowMessage(result);
rc = SQLFetch( hStmt );
if ( rc == SQL_SUCCESS ){
ShowMessage(Data);
}
else{
if (rc != SQL_NO_DATA){
DisplayError(SQL_HANDLE_STMT,hStmt,(SQLCHAR *)"SQLFetch");
}
}
![]() |
![]() |