Can anybody please tell how to declare a cursor name dynamically (fixed name + unique name) in SQL Server?
This is to prevent the error
02-25-2018 10:12:01 ERROR (AdHocReportserviceImpl.java:882) : org.springframework.jdbc.UncategorizedSQLException: CallableStatementCallback; uncategorized SQLException for SQL [{call usp_AdHocReport(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}];
SQL state [34000]; error code [16916]; [FMWGEN][SQLServer JDBC Driver][SQLServer]A cursor with the name 'FetchRegion' does not exist.; nested exception is java.sql.SQLException: [FMWGEN][SQLServer JDBC Driver][SQLServer]A cursor with the name 'FetchRegion' does not exist
while accessing it from multi threaded java application. I've tried adding LOCAL
after CURSOR
declaration but it doesn't work.
DECLARE FetchRegion CURSOR READ_ONLY FOR
SELECT ......
OPEN FetchRegion
FETCH NEXT FROM FetchRegion INTO @RGN
WHILE @@ROWCOUNT <> 0
BEGIN
.....
FETCH NEXT FROM FetchRegion INTO @RGN
END
CLOSE FetchRegion
DEALLOCATE FetchRegion