我的源数据
ename Age
BAL N
BAL Y
BAL Y
YUV N
YUV Y
NAR N
逻辑
if ( (ename <> Previous_Ename or Previous_AGE='N') then AGE = as is Else AGE='Y'
能否请您告诉我如何使用 Oracle funcaiton 进行编码?我尝试过,但在所有情况下它都没有显示所需的结果集。
我用了
create or replace function () RETURN
VARCHAR2
IS
previous_name VARCHAR2 (9) := 'DUMMY';
previous_age VARCHAR2 (9) := 'Z';
BEGIN
For cur_rec in (select ename, age from tablename order by ename) LOOP
if ( cur_rec.ename <> previous_ename or previous_age ='N')
then return cur_rec.age; /** it is populating the result set with only "N"***/
else return 'Y';
end if;
previous_ename :=ename; /*** not sure whether this assignment is correct- im trying to assignt current value as previous value for next row reference.****/
previous_age :=age; /*** not sure whether this assignment is correct****/
END LOOP;
END
结果我得到:-实际上结果应该与此数据场景的源相同
ename Age
BAL N
BAL N
BAL N
YUV N
YUV N
NAR N