How to replace Cursor in SQL Server?

Pl sql problem cursor and functions?

  • how can you make a function or a procedure call a cursor? does this have to do with the ref cursors? can anyone help me with the whole syntax eg. (sorry, i'll be using some shortcuts on the code) create or replace function/procedure call_cursor BEGIN ** calls the cursor END // cursor DECLARE cursor; BEGIN open da cursor FETCH the info display the info close end thank you very much!

  • Answer:

    Not quite - think of the cursor as a temporary table. The DECLARE defines it, the OPEN populates it with data, the FETCH retrieves the next row of data and the CLOSE deletes the rows (may or may not need to follow with a DEALLOCATE or something similar to free-up storage). The normal process is: DECLARE cursorName AS SELECT whatever is required OPEN cursorName FETCH cursorName INTO host variable list WHILE (cursor not at EOF) (don't recall offhand what this variable called in PL/SQL) DO whatever processing required for one row of data FETCH cursorName INTO host variable list ENDDO CLOSE cursorName DEALLOCATE cursorName (if needed)

christian e at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.