ORA-00922 missing or invalid option [message #479596] |
Mon, 18 October 2010 08:55  |
kjrooney91
Messages: 12 Registered: October 2010
|
Junior Member |
|
|
I am creating a stored procedure to create a table during run time using 3 passed in parameters to build the table name. Oracle is giving me the ORA-00922 missing or invalid operation error message on the EXECUTE IMMEDIATE statement of my stored procedure. I am new to writing stored procedures in Oracle and would appreciate any help that can be provided. I am pasting a copy of the stored procedures. I have also changed the names of the field names to be generic so I can post the code in this forum.
CREATE OR REPLACE PROCEDURE createTable(PARAMETER1 in string, PARAMETER2 in string, PARAMETER3 in string) IS
TABLE_NAME NVARCHAR2(50);
QUERY_STRING LONG;
BEGIN
TABLE_NAME := PARAMETER1 || '_' || PARAMETER2 || '_' ||PARAMETER3;
QUERY_STRING := 'CREATE TABLE USER.' ||TABLE_NAME||
'(FIELD1 NUMBER(10) NOT NULL,
FIELD2 NUMBER(10),
FIELD3 NVARCHAR2(50) NOT NULL,
FIELD4 NUMBER(10,0) DEFAULT (0) NOT NULL,
FIELD5 NUMBER(10,0) NOT NULL,
FIELD6 NCLOB NOT NULL,
FIELD7 DATE NOT NULL,
FIELD8 NUMBER(1) DEFAULT (0) NOT NULL),
CONSTRAINT PK_'||PARAMETER1||'_'||PARAMETER2||' PRIMARY KEY (FIELD2),
CONSTRAINT CHK_'||PARAMETER1||'_'||PARAMETER2||'_PROCESSED CHECK (PROCESSED IN (0,1))';
EXECUTE IMMEDIATE QUERY_STRING;
END;
|
|
|
Re: ORA-00922 missing or invalid option [message #479598 is a reply to message #479596] |
Mon, 18 October 2010 08:58   |
cookiemonster
Messages: 13967 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Standard method of debugging dynamic sql:
Assign the dynamic sql to a variable (which you have done).
Output the variable using dbms_output or some other method.
Paste the output into sqlplus and see if it looks valid.
That said, creating tables in oracle is almost always a bad idea. I'd rethink your approach if I was you.
EDIT: typo
[Updated on: Mon, 18 October 2010 09:02] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Re: ORA-00922 missing or invalid option [message #479615 is a reply to message #479596] |
Mon, 18 October 2010 09:36   |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
Did you follow the very first cookiemonster's advice? Because, this is correct way of debugging dynamic SQL. You would get this result after replacing the parameters with some values: SQL> CREATE TABLE USER.TABLE_NAME
2 (FIELD1 NUMBER(10) NOT NULL,
3 FIELD2 NUMBER(10),
4 FIELD3 NVARCHAR2(50) NOT NULL,
5 FIELD4 NUMBER(10,0) DEFAULT (0) NOT NULL,
6 FIELD5 NUMBER(10,0) NOT NULL,
7 FIELD6 NCLOB NOT NULL,
8 FIELD7 DATE NOT NULL,
9 FIELD8 NUMBER(1) DEFAULT (0) NOT NULL),
10 CONSTRAINT PK_P1_P2 PRIMARY KEY (FIELD2),
11 CONSTRAINT CHK_P1_PARAMETER2_PROCESSED CHECK (PROCESSED IN (0,1));
FIELD8 NUMBER(1) DEFAULT (0) NOT NULL),
*
ERROR at line 9:
ORA-00922: missing or invalid option
Now change it to valid static statement, then make the same changes in the dynamic one. Next time, please, process these steps yourself.
|
|
|
|
|
|
|
|
|
|
|
Re: ORA-00922 missing or invalid option [message #479636 is a reply to message #479615] |
Mon, 18 October 2010 10:01   |
 |
Maaher
Messages: 7065 Registered: December 2001
|
Senior Member |
|
|
The key of your solution (bad approach or not) lies here:
flyboy wrote on Mon, 18 October 2010 16:36Did you follow the very first cookiemonster's advice? Because, this is correct way of debugging dynamic SQL. You would get this result after replacing the parameters with some values: SQL> CREATE TABLE USER.TABLE_NAME
2 (FIELD1 NUMBER(10) NOT NULL,
3 FIELD2 NUMBER(10),
4 FIELD3 NVARCHAR2(50) NOT NULL,
5 FIELD4 NUMBER(10,0) DEFAULT (0) NOT NULL,
6 FIELD5 NUMBER(10,0) NOT NULL,
7 FIELD6 NCLOB NOT NULL,
8 FIELD7 DATE NOT NULL,
9 FIELD8 NUMBER(1) DEFAULT (0) NOT NULL),
10 CONSTRAINT PK_P1_P2 PRIMARY KEY (FIELD2),
11 CONSTRAINT CHK_P1_PARAMETER2_PROCESSED CHECK (PROCESSED IN (0,1));
FIELD8 NUMBER(1) DEFAULT (0) NOT NULL),
*
ERROR at line 9:
ORA-00922: missing or invalid option
Now change it to valid static statement, then make the same changes in the dynamic one. Next time, please, process these steps yourself.
Your syntax is not correct. Move the right bracket to the end of the creation statement.
For the next version I suggest you really rethink your logic. This is so bad.
MHE
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: ORA-00922 missing or invalid option [message #479662 is a reply to message #479658] |
Mon, 18 October 2010 11:06  |
kjrooney91
Messages: 12 Registered: October 2010
|
Junior Member |
|
|
Got it...thanks for all your help. I learned a lot today about how Oracle works. I have been playing in SQL server and Oracle seems to work much differently so this is a learning process for me. Again thank you all for your feedback it is much appreciated...
|
|
|