|
|
Re: create table using Stored Procedure [message #141645 is a reply to message #141620] |
Tue, 11 October 2005 07:42 |
|
Mahesh Rajendran
Messages: 10708 Registered: March 2002 Location: oracleDocoVille
|
Senior Member Account Moderator |
|
|
A simple method is to pass only two variables.
One for table_name and other all for all columns with their datatype seperated by commas.
Else you need to dynamicallly generate values for all columns and their datatypes. SOmething like this.
But the question is why?
DDL's like this would end up as nightmare in real time ( without proper design considerations and documenting the ddl).
For fun / developement/ education, this is ok.
scott@9i > grant create table to scott;
Grant succeeded.
scott@9i > @crt
Procedure created.
scott@9i > exec crt ('mytable','c1 number, c2 varchar2(10), c3 date');
create table mytable(c1 number, c2 varchar2(10), c3 date)
PL/SQL procedure successfully completed.
scott@9i > desc mytable
Name Null? Type
----------------------------------------------------- -------- ------------------------------------
C1 NUMBER
C2 VARCHAR2(10)
C3 DATE
scott@9i > get crt
1 create or replace procedure crt
2 (P_tablename in varchar2,
3 P_columns in varchar2)
4 as
5 Begin
6 execute immediate ('create table '||p_tablename ||'('||P_columns||')');
7 DBMS_OUTPUT.PUT_LINE ('create table '||p_tablename ||'('||P_columns||')');
8* end crt;
|
|
|