0

I am tring to run a simple dynamic query but obtain:

DECLARE 
  stm varchar2(20000) ; 
BEGIN
  stm :=  'SELECT 12 X FROM DUAL ;';
  EXECUTE IMMEDIATE stm ;
END;

but obtain the error :

ORA-00911: invalid character ORA-06512: at line 5 00911. 00000 - "invalid character" *Cause: identifiers may not start with any ASCII character other than letters and numbers. $#_ are also allowed after the first character. Identifiers enclosed by doublequotes may contain any character other than a doublequote. Alternative quotes (q'#...#') cannot use spaces, tabs, or carriage returns as delimiters. For all other contexts, consult the SQL Language Reference Manual.

user3752281
  • 1,915
  • 1
  • 13
  • 16
  • 4
    Maybe you have to remove the first semicolon `;';` here – Jens Feb 13 '15 at 12:16
  • You also probably want the query result to go somewhere; if so you need another variable and an `into` clause, [as shown here](http://stackoverflow.com/a/24260667/266304). And obviously this query doesn't need to be dynamic, but I assume you're experimenting *8-) – Alex Poole Feb 13 '15 at 12:42
  • yes it is not actually dynamical query but just a sample; it I reduced the query so that to be minimal, but the stm string can be easily built to get the query dynamic. ta – user3752281 Feb 13 '15 at 14:01
  • yes , it was the semicolon in the smt string, now it works. ta – user3752281 Feb 13 '15 at 14:04
  • again yes, I see the answer to the "run query as strings in oracle" , I agree my question is duplicate; not sure how to merge the questions or what to do next. I searched for this error for dynamic query and missed this answer. thanks a lot Paul – user3752281 Feb 13 '15 at 14:09
  • @user3752281 - you don't need to do anything, this question is [marked as a duplicate now](http://stackoverflow.com/help/duplicates) and will stay here as a signpost - someone else might find your question more easily than the other one, and will be directed there for the answer. Glad it helped. – Alex Poole Feb 13 '15 at 14:32

0 Answers0