我一直收到此错误" ORA-01722:无效的号码"在尝试运行我的查询时。我已经多次重写了查询,试图绕过错误,但似乎无法做到。它必须是案例陈述,在我按照GPA小时数比较班级水平时将其抛弃。当然有人对我的问题有一些提示或答案!提前致谢
select distinct
initcap(stride_last_name),
stride_first_name,
substr(stride_middle,1,1),
case
when nvl(sum(gpa_hours_earned),'0') between '0' and '29.9' then 'Freshmen'
when nvl(sum(gpa_hours_earned),'0') between '30' and '59.9' then 'Sophomore'
when nvl(sum(gpa_hours_earned),'0') between '60' and '89.9' then 'Junior'
when nvl(sum(gpa_hours_earned),'0') >= '90' then 'Senior'
else 'Freshmen'
end
答案 0 :(得分:0)
假设您的gpa_hours_earned
列是数字,这是因为您要将总和与字符串进行比较,这意味着像'29.9'
这样的字符串文字被隐式转换为数字,并且您的会话设置为将逗号作为小数点分隔符,将句点作为组分隔符。您可以更改会话NLS_NUMERIC_CHARACTERS设置,或使用指定小数分隔符的显式转换。
但是你不应该使用文字文字来表示数字。删除所有这些引号:
select distinct
initcap(stride_last_name),
stride_first_name,
substr(stride_middle,1,1),
case
when nvl(sum(gpa_hours_earned),0) between 0 and 29.9 then 'Freshmen'
when nvl(sum(gpa_hours_earned),0) between 30 and 59.9 then 'Sophomore'
when nvl(sum(gpa_hours_earned),0) between 60 and 89.9 then 'Junior'
when nvl(sum(gpa_hours_earned),0) >= 90 then 'Senior'
else 'Freshmen'
end
由于您的实际查询必须具有分组子句,因此您不需要distinct
。您可以简化案例,因为它使用短路评估:
case
when nvl(sum(gpa_hours_earned),0) < 30 then 'Freshmen'
when nvl(sum(gpa_hours_earned),0) < 60 then 'Sophomore'
when nvl(sum(gpa_hours_earned),0) < 90 then 'Junior'
else 'Senior'
end