nick_rinaldi
nick_rinaldi

Reputation: 707

Why am I receiving this error: 'ORA-00923: FROM keyword not found where expected'

So I have this table, each column 'A, B, C' representing the side of a triangle respectively.

A | B | C
20 | 20 | 23
20 | 20 | 20
20 | 21 | 22
13 | 14 | 30

I want to check whether the value A = B, and if so, display "Isosceles" to the screen.

I cannot for the life of me trouble shoot this issue. Here is my simple query:

SELECT * AS 'Isosceles'
FROM TRIANGLES
WHERE TRIANGLES.A = TRIANGLES.B;

This seems like the syntax is okay and the alias is wrapped in single quotes. Could anyone take a look and tell me what's wrong?

Upvotes: 0

Views: 799

Answers (3)

Ashish sinha
Ashish sinha

Reputation: 148

A decode can also help.

select a, b, c, decode(a, b, 'Isosceles', 'not isosceles') IS_ISOSCELES from triangles;

A   B   C   IS_ISOSCELES
20  20  23  Isosceles
20  20  20  Isosceles
20  21  22  not isosceles
13  14  30  not isosceles

Upvotes: 0

Andrew Sayer
Andrew Sayer

Reputation: 2336

This seems like the syntax is okay and the alias is wrapped in single quotes. Could anyone take a look and tell me what's wrong?

The single quotes is exactly what's wrong. When you alias something you need to use the same rules you use when naming objects and columns, no quotes to let Oracle treat it as the default upper case or use double quotes to allow you to decide for yourself. Making anything case sensitive should always be carefully considered, it's a lot of effort and it so often gets forgotten about. You don't want to waste hours scratching your head saying 'It ought to be here'.

select object_id as 'a' from all_objects where 1=0;
ERROR at line 1:
ORA-00923: FROM keyword not found where expected

select object_id as a from all_objects where 1=0;
no rows selected (success)

select object_id as "a" from all_objects where 1=0;
no rows selected (success)

Edit- After reconsidering what you might really be after: Additionally, you can't just alias every column as one thing, that's weird. What you might have meant is to have an additional string like

select triangles.*, 'Isosceles' triangle_type
from triangles
WHERE TRIANGLES.A = TRIANGLES.B;

Upvotes: 2

Littlefoot
Littlefoot

Reputation: 142705

Huh, not really; if I understood you correctly, you'd utilize CASE (lines #1 - 6 represent sample data; you already have that so query you need begins at line #7):

SQL> with test (a, b, c) as
  2    (select 20, 20, 23 from dual union all
  3     select 20, 20, 20 from dual union all
  4     select 20, 21, 22 from dual union all
  5     select 13, 14, 30 from dual
  6    )
  7  select a, b, c,
  8         case when a = b then 'Isosceles'
  9         else 'not isosceles'
 10         end result
 11  from test;

         A          B          C RESULT
---------- ---------- ---------- -------------
        20         20         23 Isosceles
        20         20         20 Isosceles
        20         21         22 not isosceles
        13         14         30 not isosceles

SQL>

Upvotes: 2

Related Questions