ORA-01735: invalid ALTER TABLE option ORA-06512: (merged 2) [message #507020] |
Thu, 12 May 2011 04:45  |
artisteprasanna
Messages: 15 Registered: July 2010
|
Junior Member |
|
|
Hi All,
Can any one of you please help me ? I ran the following PL/SQL Code & I am getting the following Error:
Drop table MODIFIEDTABLE
/
Commit
/
create table MODIFIEDTABLE(TABNAMES varchar2(100))
/
DECLARE
tabname varchar2(50);
type rf is ref cursor;
cur_tab rf;
begin
Open cur_tab for SELECT TABLE_NAME FROM USER_TAB_COLUMNS WHERE COLUMN_NAME = 'MODIFIEDBY' AND
DATA_LENGTH <> 100 AND UPPER(DATA_TYPE) <> 'NVARCHAR2';
LOOP
FETCH cur_tab into tabname;
IF cur_tab%FOUND then
EXECUTE IMMEDIATE 'ALTER TABLE '||TABNAME||' MODIFY MODIFIEDBY VARCHAR2(100)';
INSERT INTO MODIFIEDTABLE(TABNAMES) VALUES(TABNAME);
END IF;
Exit When cur_tab%NOTFOUND;
END LOOP;
close cur_tab;
end;
RESULT:
Table dropped.
Commit complete.
Table created.
DECLARE
*
ERROR at line 1:
ORA-01735: invalid ALTER TABLE option
ORA-06512: at line 12
THANK YOU ALL IN ADVANCE....
|
|
|
|
Re: ORA-01735: invalid ALTER TABLE option ORA-06512: [message #507025 is a reply to message #507020] |
Thu, 12 May 2011 04:53  |
 |
Michel Cadot
Messages: 68757 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
SQL> DECLARE
2 tabname varchar2(50);
3 type rf is ref cursor;
4 cur_tab rf;
5 begin
6 Open cur_tab for
7 SELECT TABLE_NAME
8 FROM USER_TAB_COLUMNS
9 WHERE COLUMN_NAME = 'MODIFIEDBY'
10 AND DATA_LENGTH <> 100
11 AND UPPER(DATA_TYPE) <> 'NVARCHAR2';
12 LOOP
13 FETCH cur_tab into tabname;
14 IF cur_tab%FOUND then
15 EXECUTE IMMEDIATE 'ALTER TABLE '||TABNAME||' MODIFY MODIFIEDBY VARCHAR2(100)';
16 INSERT INTO MODIFIEDTABLE(TABNAMES) VALUES(TABNAME);
17 END IF;
18 Exit When cur_tab%NOTFOUND;
19 END LOOP;
20 close cur_tab;
21 end;
22 /
PL/SQL procedure successfully completed.
Works for me with what you posted.
Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" button to verify.
Also always post your Oracle version, with 4 decimals.
The standard way to debug a dynamic statement is to display is using dbms_output.put_line.
So do it for your ALTER TABLE one and try to manually execute it and you will see the error.
Regards
Michel
|
|
|