Tymek T. Tymek T. - 2 years ago 89
SQL Question

IF function in Oracle to insert data into tables

I want to make function which inserts 'F' in a field, when field "NAME" ends by '%a' and 'M' if not. How can I make this happen?

Answer Source

If the table is called t, and the column names are col_name and col_sex, and the string you enter for col_name is string_value, then what you want is:

insert into t (col_came, col_sex) values (string_value, 
                                case when string_value like '%a' then 'F' else 'M' end);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download