I writing an application using Oracle 10g.
I am currently facing this problem. I take in "filename" as parameter of type varchar2.
A sample value that filename may contain is: 'TEST || to_char(sysdate, 'DDD')'.
In the procedure, I want to get the value of this file name as in TEST147. When i write:
select filename
into ffilename
from dual;
I get the value ffilename = TEST || to_char(sysdate, 'DDD') whick makes sense. But how can I get around this issue and invoke the function in the string value?
Help appreciated. Thanks.
It's easy enough to dynamically execute a string ...
The problem arises where your string contains literals, with the dreaded quotes ...
So we have to escape the apostrophes, all of them, including the ones you haven't included in your posted string:
EDIT
Just for the sake of fairness I feel I should point out that Tony's solution works just as well:
In fact, by avoiding the SELECT on DUAL it is probably better.
The string value in your example is an invalid expression; it should be: 'TEST' || to_char(sysdate, 'DDD')
To evaluate that you could do this:
v_string will then contain 'TEST147'.