I have one table, gender, in which only two entries are there, 'male' and 'female' number of rows with these two entries only. Now I want to write a procedure which replaces these two values and the output should be as below,
Input Output
sex sex
------------------------
male female
female male
female male
male female
I am creating a procedure, which gives me an error. I am using a cursor to fetch more than one row. I know that we can do it by using only one update statement, but I want to try like this.
declare
v_gen gender%rowtype;
cursor cur_gender is
select * from gender;
begin
open cur_gender;
loop
fetch cur_gender into v_gen;
select * from gender;
if v_gen='male'
then
update gender set sex='female';
else
update gender set sex='male';
end if;
exit when v_gen%notfound;
end loop;
close cur_gender;
end;
update Table1 set "col" = (case "col" when 'male' then 'female'
else 'male' end);
fiddle
ID Username Email Gender
1 sanjay [email protected] Male
2 nikky [email protected] Male
11 raj [email protected] Female
12 Rahul [email protected] Female
update users set gender = (case when gender = 'Male' then 'Female' else 'Male' end);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With