Was this helpful?
REPLACE Examples
The following examples provide details.
Example 1:
The following example replaces the name and salary of the employee whose ID number is specified by the variable "numvar":
## range of e is employee
## replace e (empname = namevar, 
    salary = salvar:indvar)
## where e.empnum = numvar
Example 2:
A param version of the above. This version uses a dynamically created where clause, specified in a host string variable:
addresses(1) = address_of(namevar)
addresses(2) = address_of(salvar)
addresses(3) = address_of(indvar)
target_list = "empname = %c, salary = %f4:%i2"
## replace e (param (target_list, addresses)) 
##  where wherevar
Example 3:
The following example gives all employees who work for Smith a 10% raise:
range of e is employee, m is employee, d is dept 
replace e(salary=1.1*e.salary) where e.dept=d.dno and
    d.mgr=m.eno  and m.ename="*smith*"
Example 4:
The following example replaces Jones' salary with null:
range of e is employee 
replace e (salary=null) where e.ename="jones"
Example 5:
Do not do this! This disjoint query changes all rows (because "e" and "employee" are separate range variables):
Wrong:
range of e is employee 
replace e (salary=3500) where employee.ename="jones"
Last modified date: 06/10/2024