DELETE Examples
The following examples provide details.
Example 1:
The following example deletes the row in the "employee" table corresponding to the employee number specified by host variable numvar:
delete employee where employee.empnum = numvar
Example 2:
The following example deletes the row in the "employee" table whose name corresponds to the specified by host variable namevar. Notice the use of repeat, and the use of @ to flag a program variable that changes with each execution of the delete statement:
range of e is employee
repeat delete e
where e.empname = @namevar
Example 3:
The following embedded example shows the use of delete in a loop; the loop reads entries from an array of employee IDs and deletes the corresponding row from the database:
i = 1
loop until (numbers(i)=end of list)
## repeat delete employee
## where employee.empnum = @numbers(i)
## i = i + 1
end loop
Example 4:
The following embedded example shows the use of delete in conjunction with a host string variable containing search criteria:
construct search_condition
## delete employee
## where search_condition
Example 5:
In the following embedded example, employees whose salary is null are on a leave of absence. If they were hired after a certain date (supplied by the program), they are deleted.
## delete employee
## where employee.salary is null
## and employee.hire_date > base_date
Last modified date: 08/28/2024