如果我必须比较两个游标并回溯独特的val,我该怎么做
示例 CURSOR c_stock_option IS 选择empid,name,ssn,isenrolled 来自员工 其中isenrolled = 1
CURSOR c_espp_option IS 选择empid,name,ssn,isenrolled 来自员工 其中isenrolled = 2
现在我要拒绝光标1选择中的第二个游标中的所有rec,我该怎么做
答案 0 :(得分:0)
嗯......根据定义,isenrolled = 2的所有行都不与isenrolled = 1的行重叠。但我认为你问的是一个更普遍的问题,即如何排除另一个结果集中的行。
如果是这种情况,您可以采取一些不同的方法:
1)
CURSOR c_stock_option IS
Select empid, name, ssn, isenrolled from employee where isenrolled=1
MINUS
Select empid, name, ssn, isenrolled from employee where isenrolled=2
2)
CURSOR c_stock_option IS
Select empid, name, ssn, isenrolled from employee
where isenrolled=1
and empid not in (
Select empid, name, ssn, isenrolled from employee where isenrolled=2)
3)
CURSOR c_stock_option IS
Select empid, name, ssn, isenrolled from employee e
where isenrolled=1
and not exists(
Select 1 from employee where e.empid = employee.empid and isenrolled=2)
您选择的取决于您的情况,数据模型,索引等。