Removes, from a table, the row indicated by the current cursor position for an open cursor.
exec sql [at connection_name] delete [from] table_name where current of cursor_name end-exec
The name of the table from which the row will be deleted.
Causes Adaptive Server to delete the row of the table indicated by the current cursor position for the cursor cursor_name.
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.
This reference page mainly describes aspects of the Transact-SQL delete statement that differ when used with Embedded SQL. See the Adaptive Server Enterprise Reference Manual for more information about the delete statement.
This form of the delete statement must execute on the connection where the cursor cursor_name was opened. If the delete statement includes the atconnection_name clause, the clause must match the atconnection_nameclause of the open cursor statement that opened cursor_name.
The delete statement fails if the cursor was declared for read only, or if the select statement included an order by clause.
close, declare cursor, fetch, open, update