首页 > 数据库 > Oracle > 正文

一条有用的sql文(ORACLE)

2024-08-29 13:29:32
字体:
来源:转载
供稿:网友

    昨天在试图取某个字段时,发现在现有数据的情况下,没有该字段的值,而程序又要求必须选出一个数来,也就是说,该sql文在任何情况下都必须选出一条数据来。想了一会,得到如下一条语句,自己觉得比较有用,拿来大家讨论讨论。
    select nvl(a.userrate, 1) as userrate
    from
    (
        select userrate , 1 as ttt
        from ord_month
        where addresscode = 'l'
          and lastid = 'c13006'
    ) a
    ,(select 1 as ttt from dual) b
    where 1 = 1
      and b.ttt = a.ttt(+)
    b表始终有一条数据,通过外连结就会在任何情况下都选出一条数据来。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表