Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Stored Procedures: If then else
I've made a procedure that should check if the record
already exists, if so modify the record, if not insert a new
record. The sqlplus says that the procedure is compiled
with errors. I think the error is in the line with select statement.
CREATE OR REPLACE PROCEDURE TR_CREATE_LEAVE (
NAME VARCHAR2, STATUS VARCHAR2, ID VARCHAR2
) IS
BEGIN
DECLARE
NAME_NEW TBL_LEAVE.NAME%TYPE := NAME;
STATUS_NEW TBL_LEAVE.STATUS%TYPE := STATUS;
ID_NEW TBL_LEAVE.ID%TYPE := ID;
BEGIN
IF SELECT COUNT(*) FROM tbl_leave where ID=ID_NEW > 0 THEN
UPDATE tbl_leave SET NAME=NAME_NEW WHERE ID=ID_NEW; UPDATE tbl_leave SET STATUS=STATUS_NEW WHERE ID=ID_NEW; ELSE INSERT INTO tbl_leave VALUES (ID, NAME, STATUS);END IF;