By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE staging_tbl (id, name, age, email, remark) AS
SELECT 1, 'Alice', 42, 'alice@example.com', CAST(NULL AS VARCHAR2(200)) FROM DUAL UNION ALL
SELECT 2, 'Betty', 18, 'betty@example.com', CAST(NULL AS VARCHAR2(200)) FROM DUAL UNION ALL
SELECT 3, 'Carol', 27, 'carol@example.com', CAST(NULL AS VARCHAR2(200)) FROM DUAL UNION ALL
SELECT 4, 'Debra', 92, 'debra@example.com', CAST(NULL AS VARCHAR2(200)) FROM DUAL;
4 rows affected
-- Use PL/SQL since db<>fiddle does not support bind variables.
DECLARE
v_id STAGING_TBL.ID%TYPE := 1;
v_age STAGING_TBL.AGE%TYPE := 52;
v_email STAGING_TBL.EMAIL%TYPE := 'angie@example.com';
v_name STAGING_TBL.NAME%TYPE := 'Angie';
BEGIN
UPDATE staging_tbl
SET age = v_age,
email = v_email,
name = v_name,
remark = remark
|| CASE WHEN v_age <> age THEN ',age updated' END
|| CASE WHEN v_email <> email THEN ',email updated' END
|| CASE WHEN v_name <> name THEN ',name updated' END
WHERE id = v_id;
END;
/
1 rows affected
SELECT * FROM staging_tbl;
ID | NAME | AGE | REMARK | |
---|---|---|---|---|
1 | Angie | 52 | angie@example.com | ,age updated,email updated,name updated |
2 | Betty | 18 | betty@example.com | null |
3 | Carol | 27 | carol@example.com | null |
4 | Debra | 92 | debra@example.com | null |