plsql - How to write and call an Oracle function in SQL -


i have 2 oracle tables similar structure:

enter image description here

i'd write function in oracle sum values each id , returns pair (id,text) text='alert' if sum greater 100, 'ok' otherwise:

enter image description here

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

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

c# - Populating Gridview inside Listview ItemTemplate On Web User Control from Code Behind -