Suppose we are running a restaurant, and now we have rebuilt an ordering system. It is necessary to update the food codes and names of the original ordering system into the new system. Unfortunately, the two systems need to be parallelized for a period of time, and the databases used are also different. However, you can obtain these values by requesting the server-side interface. The following is an example of an Oracle version of update/insert:
CREATE OR REPLACE PROCEDURE upsert_food
(
IN_FOOD_CODE IN varchar2,
IN_FOOD_NAME IN varchar2
) AS
food_id number(16);
cnt number(5);
BEGIN
select count(*) into cnt from myfood where food_code=IN_FOOD_CODE ;
if cnt = 0 then
select FOOD_SEQ.nextval into food_id from dual;
INSERT INTO myfood
VALUES (food_id ,IN_FOOD_CODE ,IN_FOOD_NAME );
else
UPDATE myfood f
SET f.food_name = IN_FOOD_NAME
WHERE f.food_code = IN_FOOD_CODE ;
end if;
END upsert_food;