Solved

How to generate DDL ...

Posted on 2000-05-10
5
1,407 Views
Last Modified: 2012-08-13
How to generate DDL (for tables only)from existing database without using export? Is there any script available?

Thanks.

0
Comment
Question by:iqbalj
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:NetoMan
Comment Utility
I suggest you use a freeware tool called TOAD. there is a site where you can find a free version :

http://www.toadsoft.com/

You can get scripts of ypur tables, procedures, functions. Also many other capabilities.

Also you can use :

  DESC tablename

to see all the table definitions and build your own scipt-making procedure.

from SELECT * FROM USER_TABLES you can get all the tables you own.

NetoMan :)
0
 

Author Comment

by:iqbalj
Comment Utility
Actually I'm looking for a script so I can reproduce the tables off site (little complicated). I'm supporting a dumb client who needs to generate the DDL and send it to us.

At this point I can't use either TOAD or export....

Thanks a lot.
0
 
LVL 4

Expert Comment

by:dda
Comment Utility
I've found this script at the http://www.dbatoolz.com/ site (category 9: Table scripts). There are a lot of usefull stuff there.

rem    
rem     File:        c_tab_rec.sql
rem     Created:     Vitaliy Mogilevskiy (vit100gain@earthlink.net)
rem     Desc:        Creates DDL script to re-create a table
rem    

set term on
set feedback on
set verify off
set pages 999
set head off
set lines 132
col col_name format a35
col table_name noprint new_value m_table_name
col type format a15
col nn_or_n format a11

break on table_name skip page
ttitle  -
         m_table_name -

accept shema_owner char prompt "Enter Shema Owner Name [Enter For All]:"
accept tab_name char prompt "Enter Table Name [Enter For All]:"

select 'create table '||cl.owner||'.'||cl.table_name||'_new ('                          table_name
,       cl.column_name                                                                  col_name
,       decode(cl.data_type,
                 'CHAR','CHAR('||cl.data_length||')',
              'VARCHAR','VARCHAR('||cl.data_length||')',
             'VARCHAR2','VARCHAR2('||cl.data_length||')',
               'NUMBER',decode(cl.data_precision,
                                  NULL,'NUMBER'
                                      ,'NUMBER('||cl.data_precision||','||cl.data_scale||')')
                       ,cl.data_type)                                                           type
,       decode(cl.nullable,
                'Y','NULL',
                'N','NOT NULL')||decode(cl.column_id,
                                        gr.mx_col,');'
                                                 ,',' )                                 nn_or_n
from dba_tab_columns          cl
,    (select max(column_id) mx_col, table_name
      from   dba_tab_columns
      group by table_name)    gr
where cl.owner = nvl(upper('&shema_owner'),cl.owner)

and   cl.table_name = nvl(upper('&tab_name'),cl.table_name)

and   cl.table_name = gr.table_name
order by cl.owner||'.'||cl.table_name
,        cl.column_id
/
0
 

Author Comment

by:iqbalj
Comment Utility
Thnaks a lot. dbatoolz is a good site. I was looking for a script to generate all tables DDL not just one. I'll modify the script.

You can collect the points if you want.
0
 
LVL 4

Accepted Solution

by:
dda earned 50 total points
Comment Utility
Many thanks to Vitaliy Mogilevskiy (www.dbatoolz.com).
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to recover a database from a user managed backup

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now