我是oracle数据库的新手,我创建了一个包含if else语句的PL / SQL包。它包含分别用于插入,更新和删除的三个过程。这给了我错误。任何人都可以帮我解决这个问题..
create or replace
PACKAGE body USERS_tapi
IS
-- insert
PROCEDURE ins(
p_FIRSTNAME IN USERS.FIRSTNAME%type ,
p_ADDRESS IN USERS.ADDRESS%type ,
p_ROLEID IN USERS.ROLEID%type DEFAULT NULL ,
p_USERNAME IN USERS.USERNAME%type ,
p_PASSWORD IN USERS.PASSWORD%type ,
p_USERID IN USERS.USERID%type ,
p_LASTNAME IN USERS.LASTNAME%type,
O_val OUT NUMBER
)
IS
BEGIN
select count(*) as cnt from USERS where username=p_USERNAME and password=p_PASSWORD;
if cnt = 0 then
INSERT INTO USERS(
FIRSTNAME ,
ADDRESS ,
ROLEID ,
USERNAME ,
PASSWORD ,
USERID ,
LASTNAME
)
VALUES
(
p_FIRSTNAME ,
p_ADDRESS ,
p_ROLEID ,
p_USERNAME ,
p_PASSWORD ,
USERS_SEQ.nextval ,
p_LASTNAME
);
O_val:=0;
else if cnt > 0 then
O_val:=1;
else
O_val:=2;
END IF;
return O_val;
END;
-- update
PROCEDURE upd
(
p_FIRSTNAME IN USERS.FIRSTNAME%type ,
p_ADDRESS IN USERS.ADDRESS%type ,
p_ROLEID IN USERS.ROLEID%type DEFAULT NULL ,
p_USERNAME IN USERS.USERNAME%type ,
p_PASSWORD IN USERS.PASSWORD%type ,
p_USERID IN USERS.USERID%type ,
p_LASTNAME IN USERS.LASTNAME%type
)
IS
BEGIN
UPDATE USERS
SET FIRSTNAME = p_FIRSTNAME ,
ADDRESS = p_ADDRESS ,
ROLEID = p_ROLEID ,
USERNAME = p_USERNAME ,
PASSWORD = p_PASSWORD ,
LASTNAME = p_LASTNAME
WHERE USERID = p_USERID;
END;
-- del
PROCEDURE del(
p_USERID IN USERS.USERID%type )
IS
BEGIN
DELETE FROM USERS WHERE USERID = p_USERID;
END;
END USERS_tapi;
答案 0 :(得分:0)
在以下行中使用elsif
代替else if
:
else if cnt > 0 then
前者只是你的条件块中的另一个案例。 后一种语法是在第一个条件块的else部分中启动嵌套条件块。该嵌套块需要自己的END IF才能工作。
您也可以使用CASE声明:
CASE
WHEN cnt = 0 then
-- insert statement
O_val:=0;
WHEN cnt > 0 then
O_val:=1;
else
O_val:=2;
END CASE;