【问题标题】:can i return a custom result after reviewing a stored procedures' result?查看存储过程的结果后,我可以返回自定义结果吗?
【发布时间】:2010-02-09 08:19:18
【问题描述】:

我想返回自定义值作为行的值,以防通过执行存储过程未获取任何行 - 有没有办法做到这一点?

【问题讨论】:

  • 我说得对吗:您想在 sql 级别设置某种默认返回值吗?
  • 是的,但仅当返回 null / 空值 / 时
  • 如果我的存储过程获取 0 条记录,我至少可以得到一个特定的行吗?

标签: mysql stored-procedures resultset


【解决方案1】:
if 0 = (select count(*) from tbl where conditions)
    select 'None' as s, 0 as n
else
    select s, n from tbl where conditions

如果行是从过程返回的,而不是选择,则执行到临时表中,然后执行相同的练习。像这样:

create table #tmp (s varchar(17), n integer)

insert into #tmp
    execute myproc

【讨论】:

    猜你喜欢
    • 2013-09-15
    • 2012-03-11
    • 1970-01-01
    • 2021-03-22
    • 2015-06-03
    • 2013-06-21
    • 2018-03-16
    • 1970-01-01
    相关资源
    最近更新 更多