Forum Stats

  • 3,759,068 Users
  • 2,251,495 Discussions
  • 7,870,480 Comments

Discussions

I am getting missing keyword error while selecting the statement

Albert Chao
Albert Chao Member Posts: 63 Green Ribbon
create table Main(Main_id number, id_num number, desc varchar2(50), stage_code number);

insert into department values(1,11,'X',4);
insert into department values(2,22,'Y',10);
insert into department values(3,33,'Z',15);


create table Task(task_id number, status varchar2(50));

insert into Task values(1,'A');
insert into Task values(2,'B');
insert into Task values(3,'C');

select m.id_num, m.desc,
case
when m.stage_code between 0 to 10 then t.status
else null
end as stage_code
from Main m
join Task t on t.task_id = m.main_id;
Tagged:

Best Answer

  • Jan Gorkow
    Jan Gorkow Member Posts: 133 Gold Badge
    Accepted Answer

    Hi @Albert Chao ,

    the missing keyword exception is coused by the between clause. Between the lower and the upper bound comes an "and" not "to".

    But there are some more errors in your example:

    1. DESC is a keyword in oracle. If you really want to use this as a column name you have to write "DESC" in the select statement and also in the create table statement.
    2. You create a table main but the inserts reference table department...
    SELECT m.id_num,
        m."DESC",
        CASE WHEN m.stage_code BETWEEN 0 AND 10 THEN t.status ELSE NULL END  AS stage_code
     FROM main m JOIN task t ON t.task_id = m.main_id;
    

    Best regards,

    Jan

Answers

  • Jan Gorkow
    Jan Gorkow Member Posts: 133 Gold Badge
    Accepted Answer

    Hi @Albert Chao ,

    the missing keyword exception is coused by the between clause. Between the lower and the upper bound comes an "and" not "to".

    But there are some more errors in your example:

    1. DESC is a keyword in oracle. If you really want to use this as a column name you have to write "DESC" in the select statement and also in the create table statement.
    2. You create a table main but the inserts reference table department...
    SELECT m.id_num,
        m."DESC",
        CASE WHEN m.stage_code BETWEEN 0 AND 10 THEN t.status ELSE NULL END  AS stage_code
     FROM main m JOIN task t ON t.task_id = m.main_id;
    

    Best regards,

    Jan