REPLACE Function or plsql function
384655Feb 17 2005 — edited Feb 18 2005Hi,
I have the following tables:
persons p
-------
id
name
surname
emails e
------
emid
subject
sender
html_body
text_body
cods c
----
id --> fk on persons(id)
emid --> fk on emails(emid)
cod1
cod2
cod3
In the fields html_body and text_body I have some parameters that should be replaced dinamically.
These fields are:
NAME
SURNAME
COD1
COD2
COD3
I should replace those fields dinamically with the fields of tables persons and cods.
I have a procedure and inside I have a cursor like:
FOR cur IN (SELECT e.sender, e.subject,
REPLACE
(REPLACE
(REPLACE
(REPLACE(e.html_body,'_NAME_',p.name)
,'_SURNAME_',p.surname)
,'_COD1_',c.cod1)
,'_COD2_',c.cod2) AS html_text,
REPLACE
(REPLACE
(REPLACE
(REPLACE(e.text_body,'_NAME_',p.name)
,'_SURNAME_',p.surname)
,'_COD1_',c.cod1)
,'_COD2_',c.cod2) AS
text_text
FROM
person p,
emails e,
cods c
WHERE p.id=c.id
AND e.emid=c.emid)
LOOP
send email here
do some inesrts....
What I want to do is replace all those "REPLACE" statements with some function.
Does this have sense or doing it like this, even if it's confusing, is more correct and performaning?
Thanks in advance
Tarek