首页 文章

PLS-00103:遇到符号“DECLARE”

提问于
浏览
1

我正在尝试执行或运行以下pl / sql脚本:

SET serveroutput on;

CREATE OR REPLACE PROCEDURE findAvg
(p_category IN products.category_id% TYPE, c OUT NUMBER)
AS
BEGIN
SELECT NVL ((SELECT AVG(LIST_PRICE) FROM products
WHERE p_category = category_id), -1) into p_category
from dual;
END findAvg;
DECLARE
 cat  products.category_id%TYPE;
 Price   products.List_price%TYPE;
BEGIN
cat := &p_category;
findAvg (cat, price); 
if (price = -1) then
    dbms_output.put_line('Wrong Category ');
ELSE
    dbms_output.put_line('the average price for category' || cat || ' is ' || price);
 END IF;
END;
/
show errors

但是当我尝试运行它时,我收到此错误消息(我只能在显示错误后看到它):

PLS-00103: Encountered the symbol "DECLARE"

这个声明有什么问题?

1 回答

  • 2

    您在创建过程和运行它的匿名块的开头之间缺少“/”:

    SET serveroutput on;
    
    CREATE OR REPLACE PROCEDURE findAvg
    (p_category IN products.category_id% TYPE, c OUT NUMBER)
    AS
    BEGIN
      SELECT NVL(AVG(LIST_PRICE),-1)
      INTO c
      FROM products
      WHERE p_category = category_id;
    END findAvg;
    /
    
    show errors
    
    DECLARE
     cat  products.category_id%TYPE;
     Price   products.List_price%TYPE;
    BEGIN
    cat := &p_category;
    findAvg (cat, price); 
    if (price = -1) then
        dbms_output.put_line('Wrong Category ');
    ELSE
        dbms_output.put_line('the average price for category' || cat || ' is ' || price);
     END IF;
    END;
    /
    

    此外,“show errors”命令应该在创建过程之后运行,如上所述,INTO子句应该指定OUT参数 .

相关问题