Sql 返回空值时如何忽略行?

Sql 返回空值时如何忽略行?,sql,oracle,plsql,Sql,Oracle,Plsql,我继承了一些代码,其中包括以下错误处理: if v_complete then if v_response_time is null then raise_application_error(-20999, 'Response Time Null'); end if; update eventlog e set e.responded = get_work(v_callback, v_response_time), complete_flag='Y' where rowid

我继承了一些代码,其中包括以下错误处理:

if v_complete then 
  if v_response_time is null then
    raise_application_error(-20999, 'Response Time Null');
  end if;

update eventlog e
set e.responded = get_work(v_callback, v_response_time),
complete_flag='Y'
where  rowid = v_min_row;

end if;

对系统的更改意味着某些情况下抛出空值,而不是引发应用程序错误,我希望它忽略这些行。如何将raise\u application\u错误更改为ignore或skip?

您可以通过添加

and (v_response_time is not null)

对于查询的where子句,可以通过添加

and (v_response_time is not null)

查询的where子句听起来像您只需要:

if v_complete then 

  update eventlog e
  set    e.responded = get_work(v_callback, v_response_time),
         complete_flag='Y'
  where  rowid = v_min_row
  and    v_response_time is not null;

end if;

听起来你只需要:

if v_complete then 

  update eventlog e
  set    e.responded = get_work(v_callback, v_response_time),
         complete_flag='Y'
  where  rowid = v_min_row
  and    v_response_time is not null;

end if;

最简单的做法是:

if v_complete AND v_response_time IS NOT NULL then
  update eventlog e
    set e.responded = get_work(v_callback, v_response_time),
        complete_flag='Y'
    where  rowid = v_min_row;
end if;
这可能满足您的要求,也可能不满足您的要求-我不确定我是否理解您正在尝试做什么-但请看一看,看看这是否符合您的要求


祝你好运。

最简单的方法是:

if v_complete AND v_response_time IS NOT NULL then
  update eventlog e
    set e.responded = get_work(v_callback, v_response_time),
        complete_flag='Y'
    where  rowid = v_min_row;
end if;
这可能满足您的要求,也可能不满足您的要求-我不确定我是否理解您正在尝试做什么-但请看一看,看看这是否符合您的要求


祝您好运。

如果您想更新事件日志,即使响应时间为NULL,也可以在NULL时为v_response_time提供一个默认值。我通常使用“1900-01-01 00:00:00.000”。这可能很有用

if v_complete then 
  --if v_response_time is null then
    --raise_application_error(-20999, 'Response Time Null');
 --end if;

 update eventlog e
set e.responded = get_work(v_callback, COALESCE(v_response_time,'1900-01-01 00:00:00.000')),
complete_flag='Y'
where  rowid = v_min_row;

end if;

如果您想更新事件日志,即使响应时间为NULL,那么可以在NULL时为v_response_time指定一个默认值。我通常使用“1900-01-01 00:00:00.000”。这可能很有用

if v_complete then 
  --if v_response_time is null then
    --raise_application_error(-20999, 'Response Time Null');
 --end if;

 update eventlog e
set e.responded = get_work(v_callback, COALESCE(v_response_time,'1900-01-01 00:00:00.000')),
complete_flag='Y'
where  rowid = v_min_row;

end if;

你不能只注释掉那部分代码吗?不,当我厌倦了它时,这个包编译时出现了错误。我认为你缺少了一个“end if:”查看一下“end if:”出现在另一个使用的代码块之后,如果传递空值,该代码块将不起作用,似乎按照@Jasko的建议在下面添加一行可能是最好的选择,如果您不需要这些行来运行程序,然后消除它们就可以解决问题了。你能不能只注释掉那部分代码?不,当我累了的时候,这个包编译错误了。我认为你缺少了一个“end if:”看看“end if:”出现在另一个代码块之后,如果传递空值,它将不起作用,似乎按照下面的@Jasko建议添加一行可能是最好的选择,如果您不需要这些行来运行程序,那么消除它们将解决问题。