delete (positioned cursor)

Description

Removes, from a table, the row indicated by the current cursor position for an open cursor.

Syntax

exec sql [at connection_name] delete 
 [from] table_name 
 where current of cursor_name end-exec

Parameters

table_name

The name of the table from which the row will be deleted.

where current of cursor_name

Causes Adaptive Server to delete the row of the table indicated by the current cursor position for the cursor cursor_name.

Examples

Example 1

     EXEC SQL BEGIN DECLARE SECTION END-EXEC.
           01      PUB-NAME    PIC X(40).
                 01      PUB-ID      PIC X(4).
                 01      PUB-CTY     PIC X(15).
                 01      PUB-ST      PIC X(2).
                 01      ANSWER      PIC X(1).
      EXEC SQL END DECLARE SECTION END-EXEC.
 
 
           ....
           ....

 
      EXEC SQL DECLARE delcursor CURSOR FOR
           SELECT * FROM publishers END-EXEC.
 
      EXEC SQL OPEN delcursor END-EXEC.
      PERFORM FETCH-LOOP UNTIL SQLCODE = 100.
      EXEC SQL CLOSE delcursor END-EXEC.
      EXEC SQL DEALLOCATE CURSOR delcursor END-EXEC.
      EXEC SQL COMMIT WORK END-EXEC.
      
           ...
 
 
      FETCH-LOOP.
           EXEC SQL FETCH delcursor INTO 
                :PUB-ID, :PUB-NAME,
                :PUB-CTY, PUB-ST END-EXEC.
           DISPLAY "PUB ID    :", PUB-ID
           DISPLAY "PUB NAME  :", PUB-NAME
           DISPLAY "PUB CITY  :", PUB-CTY
           DISPLAY "PUB STATE :", PUB-ST
 
           IF SQLCODE = 100
                DISPLAY "NO MORE RECORDS TO FETCH. END OF PROGRAM RUN."
           ELSE
                DISPLAY "DELETE THIS RECORD ?(Y/N) "
                ACCEPT ANSWER
                IF ANSWER = "Y"
                EXEC SQL DELETE publishers WHERE CURRENT OF 
                      delcursor  END-EXEC
           END-IF.

Usage

See also

close, declare cursor, fetch, open, update