Creating a table in Oracle procedure I am trying to create a table inside a procedure but getting some issues related to quote identifier or may be something else.

BEGIN EXECUTE IMMEDIATE
'Create newTable as select * from oldTable';
END;


This's working fine however I need to create my table as 

BEGIN EXECUTE IMMEDIATE
'Create newTable as select * from oldTable where col1='XXX' and col2='Y'';
END;


above statement is throwing errors.

I tried to change like this but this is also not working.

BEGIN EXECUTE IMMEDIATE
'Create newTable as select * from oldTable where col1="XXX" and col2="Y"';
END;
begin
  execute immediate 'create table t1 as select * from dba_users where username  =''BP''';
end;
/

SQL&gt; select username from t1;

USERNAME
----------
BP


Double quotes (") have a different meaning than having mutliple single quotes after each other (''). Use this:

BEGIN EXECUTE IMMEDIATE
'Create newTable as select * from oldTable where col1=''XXX'' and col2=''Y''';
END;