This is one of those situations where you get an unhelpful error message back from Oracle.
My situation is as follows: I'm dynamically creating a view in PL/SQL. I build a string and use EXECUTE IMMEDIATE to create the view. The string is so long that I use a CLOB to store it.
When I run the code below in TOAD I get the unhelpful
ORA-00907: missing right parenthesis error.
Manually creating the view in TOAD (without the EXECUTE IMMEDIATE) gives no problems. My feeling is that the length of the string is a factor here as I've successfully created views with shorter strings (and also by using to_char() instead of dbms_lob.substr(), however to_char() only works with smaller clobs).
The total string length is 13775. (Obviously I've edited the line below where I build the string.) This is an Oracle 10g database on Linux.
declare
lv_sql CLOB;
begin
lv_sql := ' CREATE OR REPLACE FORCE VIEW my_view.....';
EXECUTE IMMEDIATE dbms_lob.substr(lv_sql, 14765, 1 );
end;
As Klas has said, you should be able to use VARCHAR2(32767) for your variable declaration but if you find that this is not quite enough, you could just use more than one VARCHAR2 variable to hold the various parts of the view statement and then issue them to the EXECUTE IMMEDIATE statement.
An AskTom answer here demonstrates:
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:6161200355268
Says:
Tom Kyte responds:
Though this was on an Oracle 8i database instance I would be very surprised if the ability to daisy-chain the VARCHAR2 variables had been dropped in later revisions. Unfortunately I can't test it as I don't have a 10g instance available to hand at the moment.