I have following query which inserts (name & values) to the table and it works fine but I also need to check whether the data already exist or not in the table before inserting. If exist, no need of inserting again , just update or skip the loop but I am not able to make the logic in below query for this checking part. I appreciate your help on this. I am aware of Merge Into but I need to check multiple fields, in my case (name & values)
set serveroutput on
DECLARE
str VARCHAR2(100) := '1,2';
BEGIN
FOR i IN
(SELECT trim(regexp_substr(str, '[^,]+', 1, LEVEL)) l
FROM dual
CONNECT BY LEVEL <= regexp_count(str, ',')+1
)
LOOP
insert into TBL_TEST_CUSTOMER (NAME,VALUES)
SELECT
regexp_substr('Name:check values,Name:bv,Name:cv', '(Name:)?(.*?)(,Name:|$)', 1, level, NULL,
2) AS "CatName",i.l
FROM
dual
CONNECT BY
level <= regexp_count('Name:check values,Name:bv,Name:cv', 'Name:');
END LOOP;
END;