PLSQL代码错误条件语句

时间:2015-03-31 03:48:53

标签: oracle plsql

请使用以下代码帮助识别错误。

这是我收到的错误

ERROR at line 7:
ORA-06550: line 7, column 9:
PLS-00103: Encountered the symbol "MYBIRTHDAY" when expecting one of 

the
following:
    := . ( @ % ;
    ORA-06550: line 9, column 33:
    PLS-00103: Encountered the symbol "THEN" when expecting one of the following:
    := . ( % ;
    ORA-06550: line 15, column 4:
    PLS-00103: Encountered the symbol ";" when expecting one of the following:
if

这是代码

DECLARE 
    myBirthday VARCHAR2(20):= TO_CHAR(TO_DATE ('21-jul-1994', 'DD-MM-YYYY'), 'DAY');
    birthday VARCHAR2(20);
BEGIN
    IF myBirthday = 'FRIDAY' THEN
        birthday := 'Your Birthday is on a FRIDAY';
    ELSEIF (myBirthday = 'SATURDAY') THEN
        birthday := 'Your Birthday is on a SATURDAY';
    ELSEIF (myBirthday = 'SUNDAY') THEN
        birthday := 'Your Birthday is on a SUNDAY';
    ELSE
        birthday := 'Your Birthday is on a Weekday';
    END IF;
    DBMS_OUTPUT.PUT_LINE(birthday);
END;

2 个答案:

答案 0 :(得分:1)

而不是ELSEIF使用ELSIF

您还需要声明birthday,以便它足够大以容纳您尝试放入的内容。

答案 1 :(得分:0)

您的错误是因为您定义了:

birthday VARCHAR2(20);

你正试图用超过20个字符填充它

birthday := 'Your Birthday is on a FRIDAY';
           --1                          27

因此,将变量大小增加到大约30 0r 35 char,如:

 birthday VARCHAR2(35);

应该有效

编辑:正如@WW所说。你应该使用ELSIF