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

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -