I want to call create table/ alter table command from a procedure. Is it possible?
My requirement is to change the datatype of a column in all tables. So, I am just getting the column name from user_tab_cols. Now I want to create a temp table which requires create statement .. but i am unable to use that within a proc.
Can anyone please help me out?
I presume from the reference to
USER_TAB_COLUMNSthat this is Oracle.ALTERandCREATEstatements are DDL, which we cannot execute directly in PL/SQL. However, there are a couple of ways around this restriction:EXECUTE IMMEDIATEandDBMS_UTILITY.EXEC_DDL(). I will useEXECUTE IMMEDIATEin the following example.Note that the usual restrictions apply: the new datatype has to be compatible with the existing datatype (unless the column is empty), and things are trickier with some specilaized datatypes like CLOBs.
edit
I haven’t addressed the CREATE TABLE statement. The principle is the same, it is just longer to type out. Besides, I am not entirely clear how it applies to your prior requirement to change the datatype of those columns.