2017-04-06 96 views
1

的问题是要求匿名的PL/SQL块:
         宣布,在计算Products表
         所有产品的变量有一个如果 -执行匿名PL/SQL块

:这取决于计数是否> =或

我尝试到目前为止else语句个

SET SERVEROUTPUT ON; DECLARE number_of_products NUMBER; BEGIN SELECT SUM(product_id) INTO number_of_products FROM products IF number_of_products >= 7 THEN --Syntax error on this line, not sure why DBMS_OUTPUT.PUT_LINE('The number of products is greater than or equal to 7'); ELSE DBMS_OUTPUT.PUT_LINE('The number of products is less than 7'); END IF; EXCEPTION WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE('An error occurred'); END; 

错误消息:
PL/SQL:ORA-00933:SQL命令未正确结束
ORA-06550:行4,列3:
PL/SQL:SQL语句忽略
ORA -06550:第9行第3列:
PLS-00103:在期待以下某项时遇到符号“ELSE”: (开始case如果循环mod声明结束异常退出 null pragma raise return select update with ORA-06550:第12行,colu MN 1:
PLS-00103:出现符号 “EXCEPTION”
06550. 00000 - “行%S,列%S:\ n%S”

我缺少什么?

+0

你会得到什么错误? – Zeus

+0

我刚刚将错误消息添加到原始帖子。 – SummerBoy

+1

分号在sql查询结束? – Zeus

回答

1
SET SERVEROUTPUT ON; 
DECLARE 
    number_of_products NUMBER; 
BEGIN 
    SELECT SUM(product_id) 
    INTO number_of_products 
    FROM products; 
    IF number_of_products >= 7 THEN --Syntax error on this line, not sure why 
    DBMS_OUTPUT.PUT_LINE('The number of products is greater than or equal to 7'); 
    ELSE 
    DBMS_OUTPUT.PUT_LINE('The number of products is less than 7'); 
    END IF; 
EXCEPTION 
    WHEN OTHERS THEN 
    DBMS_OUTPUT.PUT_LINE('An error occurred'); 
END; 
+0

嗯,它的功能就像一个魅力,但我看不出你改变了哪一部分? – SummerBoy

+0

@SummerBoy'FROM products;'在select查询中。 – Zeus