Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error while trying to alter table in an sql block

I create a test.sql file and inside I put:

begin alter table table1 enable row movement; alter table table1 shrink space; end; / 

Is this not allowed? Because I get error:

Encountered the symbol "ALTER" when expecting one of the following:     begin case declare exit for goto if loop mod null pragma    raise return select update while with <an identifier>    <a double-quoted delimited-identifier> <a bind variable> <<    close current delete fetch lock insert open rollback    savepoint set sql execute commit forall merge pipe 
like image 343
Victor Avatar asked Sep 27 '11 21:09

Victor


People also ask

How do you alter a table with conditions?

The basic syntax of an ALTER TABLE command to add a NOT NULL constraint to a column in a table is as follows. ALTER TABLE table_name MODIFY column_name datatype NOT NULL; The basic syntax of ALTER TABLE to ADD UNIQUE CONSTRAINT to a table is as follows.

How to rename a column in PL SQL?

ALTER TABLE table_name RENAME TO new_table_name; Columns can be also be given new name with the use of ALTER TABLE. QUERY: Change the name of column NAME to FIRST_NAME in table Student.

How to rename a column name in Oracle?

Use the RENAME COLUMN statement to rename a column in a table. The RENAME COLUMN statement allows you to rename an existing column in an existing table in any schema (except the schema SYS). To rename a column, you must either be the database owner or the table owner.


1 Answers

You cannot issue DDL as static SQL in a PL/SQL block. If you want to put those commands in a PL/SQL block, you'd need to use dynamic SQL, i.e.

BEGIN   EXECUTE IMMEDIATE 'alter table table1 enable row movement';   EXECUTE IMMEDIATE 'alter table table1 shrink space cascade'; END; / 

It may be easier, however, to just issue consecutive SQL statements rather than issuing a single PL/SQL block.

like image 160
Justin Cave Avatar answered Sep 30 '22 02:09

Justin Cave