plsql - Function does not return expected value, when max value returns NULL -


i have created function return max number data set, works fine, if data set exists ie., if max returns value.

if there no matching data set need return value of 0, no matter try retrieval either equals no value or no data found.

have tried when when no data found, when others , null values below cant function return 0 if max value not found ie., if max value returns null.

create or replace function opc_op.sitezone_msm     (in_site_id aw_active_alarms.site_id%type     ,in_zone_id aw_active_alarms.zone_id%type     ,in_mod aw_active_alarms.module%type)  return number  v_msm number; null_values exception;  begin     select max(aw_active_alarms.weight)     v_msm     aw_active_alarms      aw_active_alarms.site_id = in_site_id     , aw_active_alarms.zone_id = in_zone_id     , aw_active_alarms.module in_mod||'%';   return (v_msm);  exception     when null_values         return 0;  end sitezone_msm; 

have spent age playing cant desired results , suggestions appreciated

try nvl function used handling null values  create or replace function opc_op.sitezone_msm     (in_site_id aw_active_alarms.site_id%type     ,in_zone_id aw_active_alarms.zone_id%type     ,in_mod aw_active_alarms.module%type)  return number  v_msm number; --null_values exception; -- not required  begin     select nvl(max(aw_active_alarms.weight),0)     v_msm     aw_active_alarms      aw_active_alarms.site_id = in_site_id     , aw_active_alarms.zone_id = in_zone_id     , aw_active_alarms.module in_mod||'%';   return (v_msm);  exception       when others         return 0;  end sitezone_msm; 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -