当我按如下所示运行查询时,它运行良好。
Select USER_ID, case
when AGECD >= 10 and AGECD <= 19 then 1
when AGECD >= 20 and AGECD <= 24 then 2
when AGECD >= 25 and AGECD <= 29 then 2.5
when AGECD >= 30 and AGECD <= 34 then 3
when AGECD >= 35 and AGECD <= 39 then 3.5
when AGECD >= 40 and AGECD <= 44 then 4
when AGECD >= 45 and AGECD <= 49 then 4.5
when AGECD >= 50 and AGECD <= 54 then 5
when AGECD >= 55 and AGECD <= 59 then 5.5
when AGECD >= 60 and AGECD <= 69 then 6
when AGECD >= 70 and AGECD <= 100 then 7
else 0
END as AGETYPE
from table_name;
我想用上述结果创建一个新表。
所以我键入了以下查询:
create table AGETYPE as
Select USER_ID, case
when AGECD >= 10 and AGECD <= 19 then 1
when AGECD >= 20 and AGECD <= 24 then 2
when AGECD >= 25 and AGECD <= 29 then 2.5
when AGECD >= 30 and AGECD <= 34 then 3
when AGECD >= 35 and AGECD <= 39 then 3.5
when AGECD >= 40 and AGECD <= 44 then 4
when AGECD >= 45 and AGECD <= 49 then 4.5
when AGECD >= 50 and AGECD <= 54 then 5
when AGECD >= 55 and AGECD <= 59 then 5.5
when AGECD >= 60 and AGECD <= 69 then 6
when AGECD >= 70 and AGECD <= 100 then 7
else 0
END as AGETYPE
from table_name;
但是,出现错误,并指出原因是“指定的号码无效”。
我正在使用oracle sql developer,并且我认为我必须在代码中使用一些适当的“选项卡”以使其正常运行。我该如何解决?
答案 0 :(得分:0)
您不发布表结构。我的猜测是,您没有在说些什么而引起了一些问题。无论如何,我假设了一些表结构并在本地尝试过。
它就像一种魅力!在这里:
create table table_name (
user_id number(6),
agecd number(6)
);
insert into table_name (user_id, agecd) values (1, 15);
insert into table_name (user_id, agecd) values (2, 16);
insert into table_name (user_id, agecd) values (3, 35);
create table agetype as
Select USER_ID, case
when AGECD >= 10 and AGECD <= 19 then 1
when AGECD >= 20 and AGECD <= 24 then 2
when AGECD >= 25 and AGECD <= 29 then 2.5
when AGECD >= 30 and AGECD <= 34 then 3
when AGECD >= 35 and AGECD <= 39 then 3.5
when AGECD >= 40 and AGECD <= 44 then 4
when AGECD >= 45 and AGECD <= 49 then 4.5
when AGECD >= 50 and AGECD <= 54 then 5
when AGECD >= 55 and AGECD <= 59 then 5.5
when AGECD >= 60 and AGECD <= 69 then 6
when AGECD >= 70 and AGECD <= 100 then 7
else 0
END as AGETYPE
from table_name;
那么,您的案子有什么区别?
答案 1 :(得分:-1)
创建表<> 作为选择COMCSNO, <>然后<>的情况,否则为NULL-在这里或使用'NULL' 如果要从表名中将字符串文字END存储为AGETYPE