1: function user_demographics_summary (v_user_id IN integer)
2: return varchar
3: as
4: demo_row users_demographics%ROWTYPE;
5: age integer;
6: pretty_sex varchar(20);
7: begin
8: select * into demo_row from users_demographics where user_id = v_user_id;
9: age := round(months_between(sysdate,demo_row.birthdate)/12.0);
10: IF demo_row.sex = 'm' THEN
11: pretty_sex := 'man';
12: ELSIF demo_row.sex = 'f' THEN
13: pretty_sex := 'woman';
14: END IF;
15: IF pretty_sex is null and age is null THEN
16: return null;
17: ELSIF pretty_sex is not null and age is null THEN
18: return 'a ' || pretty_sex;
19: ELSIF pretty_sex is null and age is not null THEN
20: return 'a ' || age || '-year-old person of unknown sex';
21: ELSE
22: return 'a ' || age || '-year-old ' || pretty_sex;
23: END IF;
24: end user_demographics_summary;
|