Home » SQL & PL/SQL » SQL & PL/SQL » Compilation error with simple ELSIF (10g)
Compilation error with simple ELSIF [message #447268] Fri, 12 March 2010 16:37 Go to next message
dbmeany
Messages: 11
Registered: January 2010
Junior Member
what I don't get is what is wrong with my ELSIF statement?

-- Majic program that will guess how much you are worth
 
ACCEPT s_first PROMPT 'Enter your random letter'
DECLARE
random_letter  VARCHAR(20);
personal_worth   VARCHAR(20);
BEGIN 
IF random_letter >= 'A' AND <= 'D' THEN
personal_worth = '$100,000';
ELSIF random_letter >= 'E' AND <= 'K' THEN
personal_worth = '$10,000';
ELSIF random_letter >= 'L' AND <= 'N' THEN
personal_worth = '$1,000';
ELSIF random_letter >= 'O' AND <= 'P' THEN
personal_worth = '$100';
ELSIF random_letter >= 'Q' AND <= 'T' THEN
personal_worth = '$10';
ELSE random_letter >= 'U' AND <= 'Z' THEN
personal_worth = '$1';
dbms_output.put_line('The letter you entered was ' || random_letter || ' and your personal worth is ' || personal_worth);
END;
Re: Compilation error with simple ELSIF [message #447275 is a reply to message #447268] Fri, 12 March 2010 17:01 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>what I don't get is what is wrong with my ELSIF statement?
NOTHING is wrong with ELSEIF.

Error occurs before it.

It would be helpful if you followed Posting Guidelines - http://www.orafaq.com/forum/t/88153/0/


using sqlplus CUT & PASTE query & results
Re: Compilation error with simple ELSIF [message #447290 is a reply to message #447268] Sat, 13 March 2010 00:47 Go to previous messageGo to next message
Michel Cadot
Messages: 68737
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
'The letter you entered was ' || random_letter || ' and your personal worth is ' || personal_worth

Where is random_letter set?

Regards
Michel
Re: Compilation error with simple ELSIF [message #447294 is a reply to message #447268] Sat, 13 March 2010 03:07 Go to previous messageGo to next message
Yasir Hashmi
Messages: 304
Registered: April 2006
Senior Member

personal_worth = '$100,000';


It should be
personal_worth := '$100,000';


wherever personal_worth is assigned a vlue.
Re: Compilation error with simple ELSIF [message #447347 is a reply to message #447294] Sat, 13 March 2010 15:49 Go to previous messageGo to next message
Littlefoot
Messages: 21823
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Furthermore, this
IF random_letter >= 'A' AND <= 'D' THEN
is invalid. Should be
IF random_letter >= 'A' AND random_letter <= 'D' THEN
Re: Compilation error with simple ELSIF [message #447846 is a reply to message #447268] Thu, 18 March 2010 04:01 Go to previous messageGo to next message
s4.ora
Messages: 71
Registered: March 2010
Member
There is a missing END IF statement in the Block. The condition is also incorrect.

Try this out, i have used a BETWEEN operator instead.

set serverout on
DECLARE
random_letter VARCHAR(20):='E';
personal_worth VARCHAR(20);
BEGIN
IF random_letter between 'A' AND 'D' THEN
personal_worth:='$100,000';
ELSIF random_letter between 'E' AND 'K' THEN
personal_worth:='$10,000';
ELSIF random_letter between 'L' AND 'N' THEN
personal_worth:='$1,000';
ELSIF random_letter between 'O' AND 'P' THEN
personal_worth:='$100';
ELSIF random_letter between 'Q' AND 'T' THEN
personal_worth:='$10';
ELSIF random_letter between 'U' AND 'Z' THEN
personal_worth:='$1';
END IF;
dbms_output.put_line('The letter you entered was ' || random_letter || ' and your personal worth is ' || personal_worth);
END;
/
Re: Compilation error with simple ELSIF [message #447857 is a reply to message #447846] Thu, 18 March 2010 04:38 Go to previous message
Michel Cadot
Messages: 68737
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Thanks to participate to this forum but could you please read and follow OraFAQ Forum Guide, especially "How to format your post?" section.

Regards
Michel

[Updated on: Thu, 18 March 2010 04:39]

Report message to a moderator

Previous Topic: Optimization - reuse of a set
Next Topic: Case in sql statement doesn't run in PLSql block
Goto Forum:
  


Current Time: Mon Feb 17 21:39:34 CST 2025