December 2010
Intermediate to advanced
451 pages
11h 16m
English
You want to replace each occurrence of a given string within a body of text.
Use the REGEXP_REPLACE function to match a pattern of text against a given body of text, and replace all matching occurrences with a new string. In the following function, the REGEXP_REPLACE function is used to replace all occurrences of the JOB_TITLE ‘Programmer’ with the new title of ‘Developer’.
DECLARE
CURSOR job_cur IS
SELECT *
FROM jobs;
job_rec job_cur%ROWTYPE;
new_job_title jobs.job_title%TYPE;
BEGIN
FOR job_rec IN job_cur LOOP
IF REGEXP_INSTR(job_rec.job_title,'Programmer') > 0 THEN
new_job_title := REGEXP_REPLACE(job_rec.job_title, 'Programmer', 'Developer'); ...Read now
Unlock full access