2016-11-09 113 views
-3

1.查询关于NVL和case语句

select case 
     when id is null then name='muthu' 
     end 
from muthu; 

执行这个查询后,我得到ORA-00905:缺少关键字

  • 00000 - “缺少关键字“错误。
  • 2.

    select nvl(id,"not found") name from muthu; 
    

    ORA-00904: “未找到”:无效的标识符

    (Oracle 10g中分贝和SQL显影剂4.1) 请任何人都让我知道最新版本的SQL开发人员

    +0

    的问题是关于SQL开发人员的错误或最新版本?另外,Oracle [文档](https://docs.oracle.com/apps/search/search.jsp?category=database&q=&product=)有什么问题? – Aleksej

    +0

    请向我们展示示例数据以及您想要实现的目标,因为目前尚不清楚。 –

    +0

    我有两列id和名称的表。我想编写一个查询来检查id列的空值,并将相应的名称更新为'n/a'。 –

    回答

    0

    Y我们的第一个查询失败,因为布尔表达式不是的值。我认为你想要:

    select (case when id is null then 'muthu' 
         end) as name 
    from muthu; 
    

    第二次失败,因为字符串应该括在单引号中,而不是双引号。所以这应该是:

    select nvl(id, 'not found') as name 
    from muthu; 
    

    虽然我更喜欢ANSI标准coalesce()到数据库特定NVL()

    如果id不是一个字符串,那么你必须将它转换为字符串:

    select nvl(cast(id as varchar2(255)), 'not found') as name 
    from muthu; 
    
    +0

    从muthu中选择nvl(id,'not found')作为姓名; ORA-01722:无效号码 01722。00000 - “无效号码” *原因:指定的号码无效。 *操作:指定一个有效的号码。 –

    +0

    从muthu中选择nvl(id,null); 选择案例 当id为null时17 else id end from muthu;两个查询现在都能正常工作。感谢所有 –

    0

    不知道是什么问题,我认为为什么?

    第一个查询 - 我想你想给这个专栏命名name?如果是这样,在计算或结束无论对列来命名:

    select case when id is null then 'muthu' 
        end as name 
    from muthu; 
    

    第二个 - 字符串应该用单引号包裹,双引号是列名:

    select nvl(id,'not found') as name 
    from muthu; 
    
    +0

    为第一个查询我想验证id列为null,你可以让我知道该怎么做。我面临同样的错误。 –

    +0

    和第二个查询,即使我删除唉的名字得到相同的错误 –

    +0

    从muthu选择nvl(id,null); 选择案例 当id为null时17 else id end from muthu;两个查询现在都能正常工作。谢谢大家。 –