5

I was wondering what is the appropriate way to call the REPLACE function described here, since I've created the statement below to test it but I'm getting an error:

DECLARE
 templateMessage3 VARCHAR2(50);
BEGIN
 templateMessage3 := 'Dear Mr./Madam FNAME';
  replace(templateMessage3, 'FNAME', 'Lilly');
  DBMS_OUTPUT.PUT_LINE(templateMessage3);
END;
/

Error:

PLS-00221: 'REPLACE' is not a procedure or is undefined

I am using Oracle 11g web interface.

2 Answers 2

13

REPLACE is a function, not a procedure, so use the following syntax:

templateMessage3 := replace(templateMessage3, 'FNAME', 'Lilly');
Sign up to request clarification or add additional context in comments.

Comments

0

REPLACE is a sql function

So you'd need something like:

SELECT replace(:templateMessage3, 'FNAME', 'Lilly')
INTO templateMessage3
FROM dual;

(I don't have an Oracle install, so can't double check the syntax, but should be enough to get you started)

5 Comments

@PeterLang: works fine for me, although I'll agree that my SQLFiddle is slightly different - but not in ways that I think make much difference. YMMV. Share and enjoy.
@FionaT and anyone else who needs an Oracle instance for one-shot playing around - you might want to get familiar with SQLFiddle. When you first bring it up you'll be in MySQL - but if you click on the database name above the schema panel you can change the database to on of a myriad different types - just select Oracle 11g R2 and you'll be in business. There are some limitations, such as not being able to use DBMS_OUTPUT - but there are ways to work around that. It's a handy tool to have around. Share and enjoy.
@BobJarvis: Sorry if my comment was unclear. This solution works, but the slower (tried it) and more complex switch to SQL is not necessary.
@PeterLang: agreed that the switch to SQL is not needed. Not sure why people do this - perhaps required by older version of Oracle? But certainly not since 9i.
Agree with PeterLang that if there's no need for SQL then it's overcomplicating things to use it. Answered the question from memory (haven't used Oracle for a couple of years) as it was Sunday evening and I thought the OP might not get much response!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.