sql错误ora 00905在oracle sql开发人员的case语句中缺少关键字 [英] sql error ora 00905 missing keyword in case statement in oracle sql developer

查看:538
本文介绍了sql错误ora 00905在oracle sql开发人员的case语句中缺少关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





 使用 Sqltmp 
< span class =code-keyword> as

选择计数(*) as cnt 来自员工其中​​ age null rownum< = 2

选择
案例
何时 cnt> 0 然后
假脱机 Filepath
员工 Empid >其中 rownum< = 10;
假脱机 off ;
否则
假脱机 filepath
员工 Empid >其中 rownum< = 10;
假脱机 off ;
结束
Sqltmp





我在罢工部分收到错误如



sql error ora 00905缺少关键字



i无法解决此错误。

请注意以上声明中的错误是什么?



谢谢

解决方案

你不能在CASE语句中做到这一切。它不是像C#这样的编程语言。



参见http://docs.oracle.com/cd/B19306_01/server.102/b14200/expressions004.htm [ ^ ]


我不确定你是什么重新尝试查询但是如果你想要查询结果只是在你的查询之前启动假脱机并最终停止它,比如

假脱机  Filepath 
使用 Sqltmp
as

选择计数(*) as cnt 来自员工其中 age null rownum< = 2

选择
< span class =code-keyword> case

cnt> 0 然后
员工中选择 Empid 其中 rownum< = 10;
其他
选择 Empid 来自员工其中 rownum< = 10;
结束
来自 Sqltmp
后台打印 off ;



但是,由于你有单独的语句,所以不能正常运行,所以也许你打算做一个标量查询。类似

假脱机 文件路径 
使用 Sqltmp
as

选择计数(*)作为 cnt 来自 employee < span class =code-keyword>其中 age null rownum< = 2

选择
case
cnt< 0 然后
(< span class =code-keyword>从员工中选择 Empid 其中 rownum< = 10 )
否则
选择 Empid 来自员工其中 rownum< = 10)
结束
来自 Sqltmp
假脱机 off ;





但是我仍然不明白为什么两个案例分支中的select都相同,以及为什么在WITH子句中只选择2行...


Hi,

With Sqltmp 
as
(
  Select Count(*) as cnt from employee where age is null and rownum<=2
)
Select 
  case 
    When cnt>0 Then 
      Spool "Filepath"
      Select Empid from employee where rownum<=10;
      Spool off;
    Else
     Spool "filepath"
     Select Empid from employee where rownum<=10;
     Spool off;
  End
From Sqltmp



I'm getting error in strike part like

sql error ora 00905 missing keyword

i cannot able to troubleshoot this error.
Please suggest what is the error in above statement?

Thanks

解决方案

You can't do all that in a CASE statement. It is not a programming language like C#.

See http://docs.oracle.com/cd/B19306_01/server.102/b14200/expressions004.htm[^]


I'm not sure what you're trying to query but if you want to spool the result just start spool before your query and stop it in the end, like

Spool "Filepath"
With Sqltmp
as
(
  Select Count(*) as cnt from employee where age is null and rownum<=2
)
Select
  case
    When cnt>0 Then
      Select Empid from employee where rownum<=10;
    Else
     Select Empid from employee where rownum<=10;
  End
From Sqltmp
Spool off;


However, what wont run properly since you have separate statements in case so perhaps you meant to do a scalar query. SOmething like

Spool "Filepath"
With Sqltmp
as
(
  Select Count(*) as cnt from employee where age is null and rownum<=2
)
Select
  case
    When cnt<0 Then 
       (Select Empid from employee where rownum<=10)
    Else 
       (Select Empid from employee where rownum<=10)
  End
From Sqltmp
Spool off;



However I still don't understand why the select is the same in both case branches and why you select only 2 rows in the WITH clause...


这篇关于sql错误ora 00905在oracle sql开发人员的case语句中缺少关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆