plsql - How to write and call an Oracle function in SQL -
i have 2 oracle tables similar structure:
i'd write function in oracle sum values each id , returns pair (id,text) text='alert' if sum greater 100, 'ok' otherwise:
then, i'd execute query each table, example that:
select my_fun() table_1 select my_fun() table_2 is right approach? how write function?
thanks
generally considered bad practice call function in sql executes sql. creates kinds of problems.
here 1 solution:
create or replace function my_fun ( p_sum in number) return varchar2 begin if p_sum > 100 return 'alert'; else return 'ok'; end if; end; / run this:
select id, my_fun(sum(val)) state your_table group id; 

Comments
Post a Comment