请解决Oracle存储过程错误

时间:2011-12-28 05:22:32

标签: oracle stored-procedures oracle11g

我正在学习甲骨文,我是初学者。请解决我的以下错误。

create or replace
PROCEDURE SP_SALE_SELECT
( para1 OUT NVARCHAR2
, para2 OUT NVARCHAR2
, action IN NVARCHAR2
) AS
BEGIN
  IF action = 1 then
    Select * From VI_Sale;
  Else if action = 2 then
    Select * From VI_Sale
    WHERE SaleID = para1;
  Else if action = 3 then
    Select * From VI_Sale
    Where CustomerID = para1;
  Else if action = 4 then
    Select * From VI_Sale
    where SaleID = para1 and CustomerID = para2;
 End if;
END SP_SALE_SELECT;
  

错误(20,5):PLS-00103:遇到符号“SP_SALE_SELECT”时   期待以下之一:if

2 个答案:

答案 0 :(得分:2)

将每个Else if更改为ELSIF。此外,您不能只从PL / SQL块中的表中选择*,您需要选择一个变量。如,

create or replace
PROCEDURE SP_SALE_SELECT
( para1 OUT NVARCHAR2
, para2 OUT NVARCHAR2
, action IN NVARCHAR2
) AS
v_col1 VI_Sale.col1%type;
BEGIN
  IF action = 1 then
    Select col1 into v_col1 From VI_Sale;
  Elsif action = 2 then
    Select col1 into v_col1 From VI_Sale
    WHERE SaleID = para1;
  Elsif action = 3 then
    Select col1 into v_col1 From VI_Sale
    Where CustomerID = para1;
  Elsif action = 4 then
    Select col1 into v_col1 From VI_Sale
    where SaleID = para1 and CustomerID = para2;
 End if;
END SP_SALE_SELECT;

答案 1 :(得分:1)

您使用ELSE IF代替ELSEFIF(无空格),因此您要创建应关闭的其他ifs。

create or replace
PROCEDURE SP_SALE_SELECT
( para1 OUT NVARCHAR2
, para2 OUT NVARCHAR2
, action IN NVARCHAR2
) AS
BEGIN
  IF action = 1 THEN
    Select * From VI_Sale;
  ElSEIF action = 2 THEN
    Select * From VI_Sale
    WHERE SaleID = para1;
  ElSEIF action = 3 THEN
    Select * From VI_Sale
    Where CustomerID = para1;
  ELSEIF action = 4 then
    Select * From VI_Sale
    where SaleID = para1 and CustomerID = para2;
 End if;
END;