Home » RDBMS Server » Server Administration » create table using Stored Procedure
create table using Stored Procedure [message #141620] Tue, 11 October 2005 06:02 Go to next message
motlagh20
Messages: 1
Registered: October 2005
Junior Member

Hi
is it possible to create a Stored Procedure to create any table with any number of columns ?
i need an stored procedure which i can use it like this:

Exec MyProc tablename var1 prop. var2 prop. var3 prop.

the above Procedure mut create a table with 3 column next time i want to use the same procedure to create a table with different number of columns.
i neeed this so fast i will ba so thankfull for your help
Re: create table using Stored Procedure [message #141641 is a reply to message #141620] Tue, 11 October 2005 07:19 Go to previous messageGo to next message
sunil_v_mishra
Messages: 506
Registered: March 2005
Senior Member
hi,

It is not possible to create table by procedure using simple sql into it ... we have to use dynamic sql to create table through procedure.

Regards
Always Friend Sunilkumar
Re: create table using Stored Procedure [message #141645 is a reply to message #141620] Tue, 11 October 2005 07:42 Go to previous message
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;
Previous Topic: ORA-00600: in 9i
Next Topic: Trying to uninstall version 8i client on my machine
Goto Forum:
  


Current Time: Fri Jan 10 10:36:50 CST 2025