Consider them as strings and try to concatenate them. In your last statement, the SQL you want to execute is :
SELECT 'UMESH' FROM DUMMY;
So while framing the dynamic sql, you need to frame that string like below:
execute immediate 'select '''||:var_name||''' from dummy;';
We have totally 3 parts of the string and we need to have 'UMESH' ( with quotes) also as part of the string:
'select ' -- first part of the string
'' -- (to escape the quotes to get one quote )
:var_name -- concatenating the Variable
'' -- (to escape the quotes to get one quote )
' from dummy;' -- Last part of the string
So the procedure must be like this:
create procedure USP_TEST() as begin declare var_name varchar(10) := 'UMESH'; execute immediate 'select '''||:var_name||''' from dummy;'; end
Hope this helps
Regards,
Krishna Tangudu