0

Here is the section of code, I am using ' ' blah ' ' to escape single quotes but I guess its not working:

declare
my_func varchar2(20) :='test_func';

begin 
execute immediate 'insert into TABLE_TEST (OUTPUT) select ' || my_func || ' from dual where TABLE_TEST.FUNCTION_NAME like ' 'VALIDATION1_%' '  ';
end;

I am getting the following error:

PLS-00103: Encountered the symbol "VALIDATION1_%" when expecting one of the following:

   & = - + ; < / > at in is mod remainder not rem return
   returning <an exponent (**)> <> or != or ~= >= <= <> and or
   like like2 like4 likec between into using || bulk member
   submultiset
The symbol "* was inserted before "VALIDATION1_%" to continue.

2 Answers2

3

It looks like you are trying to escape the single quote with another single quote (which is good), but there is an extra space in between the two. That has to go.

Change

' from dual where TABLE_TEST.FUNCTION_NAME like ' 'VALIDATION1_%' '  '

to

' from dual where TABLE_TEST.FUNCTION_NAME like ''VALIDATION1_%''  '
Community
  • 1
  • 1
Thilo
  • 257,207
  • 101
  • 511
  • 656
1

In cases like this it's much simpler to use the new q syntax for literal strings, e.g.:

execute immediate 'insert into TABLE_TEST (OUTPUT) select ' || my_func ||
  q[' from dual where TABLE_TEST.FUNCTION_NAME like 'VALIDATION1_%' ]';
Jeffrey Kemp
  • 59,135
  • 14
  • 106
  • 158