You will need a function, however, a function can only return a single value. So routine(col3) can only return a single int, varchar, date and any other data type.
an object? in sql? neat trick if you can pull that off
or maybe you meant in php?
i agree, i would do the routine in the application layer, if possible, i.e. if the result depends on the value of col3 alone and not some other fields/rows/tables