oracle - PL/SQL cursor select unique record and print in flat file -


i have set of values in cursor. example:

cursor c_stock_option select empid, '1' isenrolled employee emp union select empid, '2' isenrolled employee emp; 

now want check if empid appears both in first select (where isenrolled =1) , second select (where isenrolled =2). want grab value first select where enroll=1 , reject 1 where enroll=2. want print records qualifies criteria.

for v_stock_option_record in c_stock_option loop     if v_esppstock_recs  in (v_stock_option_record.empid)      end if;     -- participant file.     v_member_string_1 := v_stock_option_record.empid || g_delimiter || --1. participant id     v_stock_option_record.last_name || g_delimiter || --4. last name     v_stock_option_record.first_name || g_delimiter || --5. first name end loop; 

in first part of query selecting employees have purchased stocks (that give set of employees have purchased stocks, other part of query gives active employees in company, employee in first part of select in second part of select, employee in second part of select not in 1st part. in scenario when employee appears in both parts need select employee has isenrolled=1). below sql differentiate

select     empid,     '1' isenrolled     employee emp,     hrempusf usf     emp.employee = usf.employee           , usf.field_key = 76 ---- 76 determines employee has purchased stocks union     select      empid,     '2' isenrolled      employee emp; 

you don't need complicated pl/sql this, need left outer join. return employee records, regardless of whether matches hrempusf record.

select      empid      , nvl2(usf.field_key ,'1', '2') isenrolled   employee emp      left outer join hrempusf usf           on ( usf.employee = emp.employee               , usf.field_key = 76 ) 

the nvl2() returns second value if first argument not null , third argument if null.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -