Solved

How to generate DDL ...

Posted on 2000-05-10
5
1,427 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
ID: 2798280
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
ID: 2798346
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
ID: 2798779
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
ID: 2806085
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
ID: 2806442
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

832 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