Fizz buzz SQL逻辑错误

时间:2016-04-13 22:10:09

标签: sql oracle

在SQL中

-1到100并显示'Fizz'如果数字可以被3'Buzz'整除,如果可以被5整除,'FizzBu​​zz'可以被两者整除。下面是我的代码

select 
Case when   Remainder (rownum,3)=0 then 'Fizz'
     when Remainder (rownum,5)=0 then 'Buzz'
     when (remainder (rownum,3)=0 and remainder(ROWNUM,5) = 0) then 'FizzBuzz'
     else rownum end 
from DUAL
Connect by level  <=100;

它给了我错误 - ORA-00932:数据类型不一致:预期CHAR得到NUMBER 00932. 00000 - “不一致的数据类型:预期%s获得%s” *原因:
*行动: 行错误:5列:18

2 个答案:

答案 0 :(得分:2)

这是在你的声明中。 Rownum是一个数字,而Fizz,Buzz和FizzBu​​zz是CHAR。

答案 1 :(得分:0)

SELECT ... from attr_laptop ...

select 
Case when   Remainder (rownum,3)=0 then 'Fizz'
     when Remainder (rownum,5)=0 then 'Buzz'
     when (remainder (rownum,3)=0 and remainder(ROWNUM,5) = 0) then 'FizzBuzz'
     else ''||rownum end 
from DUAL
Connect by level  <=100;