database - Return the sum of the count of two seperate tables PL/SQL -


i'm trying search through 2 separate tables count of particular value , return function.

  function check_parts     (p_partno         in  varchar2)     return number       out_exists  number;     sub_exists  number;   begin      select count(*) out_exists     outline_pn op     op.outline_pn = p_partno     union     select count(*)     sub_pn sp     sp.sub_assy_pn = p_partno; --      select (select count(*) out_exists --              outline_pn op --              op.outline_pn = p_partno) out_exists, --              (select count(*) sub_exists --              sub_pn sp --              sp.sub_assy_pn = p_partno) sub_exists         return (out_exists + sub_exists);   end check_parts; 

at first naively thought 2 individual count(*) queries work...it didn't.

how sum values of 2 separate count queries , return result?

any appreciated.

if still want have in 1 query, here option

  create function check_parts     (p_partno         in  varchar2)     return number       sum_exists  number;   begin    select count(1) sum_exists (     select outline_pn     outline_pn op     op.outline_pn = p_partno     union     select sub_assy_pn     sub_pn sp     sp.sub_assy_pn = p_partno);         return (sum_exists);   end check_parts; 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -