Monday, July 19, 2021

Generate Table, Index or tablespace DDLs in oracle

When migrating database from one server to another you need Tablespace creation DDL. Also it is very useful when copying specific table or index or exp/imp from one database to databases.

Here are few ways to generate the tablespace script from source database.

SQL>SET ECHO OFF;
SQL>SET HEADING OFF;
SQL>SET LINESIZE 1000;
SQL> SET LONG 60000;
SQL> SET FEEDBACK OFF;
SQL>SPOOL TBS_DDL.SQL
SQL>SELECT DBMS_METADATA.GET_DDL('TABLESPACE',DBA_TABLESPACES.TABLESPACE_NAME) FROM DBA_TABLESPACES;
SQL>SPOOL OFF

You can see below command if you want the TABLESPACE creation script specific to one Table space.

SQL> SELECT DBMS_METADATA.GET_DDL('TABLESPACE','&TABLESPACE_NAME') FROM dual;

You can use below command to generate specific TABLE, INDEX Script from a user

Syntax:-
select dbms_metadata.get_ddl('TABLE','<TABEL NAME>','<SCHEMA>') from dual;
select dbms_metadata.get_ddl('INDEX','<INDEX NAME>','<SCHEMA>') from dual;


Ex:-
select dbms_metadata.get_ddl('TABLE','EMP_SAL','EMP') from dual;
select dbms_metadata.get_ddl('INDEX','EMPNO_IDX','EMP') from dual;


You can use below command to all TABLE, INDEX Script from a user. First, connect to user

SQL>SET ECHO OFF;
SQL>SET HEADING OFF;
SQL>SET LINESIZE 1000;
SQL> SET LONG 60000;
SQL> SET FEEDBACK OFF;
SQL> SELECT DBMS_METADATA.GET_DDL('TABLE',U.TABLE_NAME)
FROM USER_TABLES U;
SQL> SELECT DBMS_METADATA.GET_DDL('INDEX',U.INDEX_NAME)
FROM USER_INDEXES U;  

In case if you need a View DDL, you can run below command;
SQL>select DBMS_METADATA.GET_DDL('VIEW',<View_Name>’) from dual;
or
SQL>select DBMS_METADATA.GET_DDL('VIEW','<view_name>','<schema_name>') from DUAL;

You can run below command to generate the DDL statements of a SCHEMA
set pages 30000
set linesize 1000
set lines 500
SQL> SELECT DBMS_METADATA.GET_DDL('USER','<schema_name>') FROM dual;

You can run below command to generate DDL statements for more than one schema

SQL> SELECT DBMS_METADATA.GET_DDL('USER',U.USERNAME) FROM DBA_USERS U WHERE USERNAME IN ('USER1','USER2');

You can run below command to generate DDL statement of the System Grant/ role granted/object granted to a schema owner

SQL> SELECT DBMS_METADATA.GET_GRANTED_DDL('SYSTEM_GRANT','<schema_name>') from dual;
SQL> SELECT DBMS_METADATA.GET_GRANTED_DDL('ROLE_GRANT','<schema_name>') from dual;
SQL> SELECT DBMS_METADATA.GET_GRANTED_DDL('OBJECT_GRANT',<Schema_Name>’) from dual;

You can run below command to generate DDL statement of the role
SQL> SELECT DBMS_METADATA.GET_DDL('ROLE','RESOURCE') from dual;

You can also use SQL Developer to get the DDL script for a specific object.

You can refer oracle documentation for more details on DBMS_METADATA

Thanks & Regards
http://oracleracexpert.com






12 comments:

  1. Adobe Premiere Rush Crack With this all-in-one app for creating and sharing videos online, you can provide your channels with a steady stream of cool content – quickly and easily.
    Little Alterboy Crack
    IK Multimedia Sampletank Mac Crack
    Pro Evolution Soccer 2021 PC Game Download

    ReplyDelete
  2. I enjoyed your blog Thanks for sharing such an informative post. We are also providing the best services click on below links to visit our website.
    Oracle Fusion HCM Training
    Workday Training
    Okta Training
    Palo Alto Training
    Adobe Analytics Training

    ReplyDelete
  3. Infycle Technologies offers couples for care and technology in addition to Python Training in Chennai, 100% of the internship class will be prepared. After completing the training, the participants will be sent to the upper MNCs interviews. Call 750633333 to get more information and get a free display.

    ReplyDelete
  4. I’m glad you got value from the post!
    Reference: https://v8web.com/

    ReplyDelete
  5. Love to read it, waiting for More New Update and I Already Read your Recent Post it's Great. Thank you for sharing useful information. If you like to Know Azerbaijan Medical Journal Visit our website for More Medical Science Information.

    ReplyDelete
  6. Within this webpage, you'll see the page, you need to understand this data. 토토커뮤니티

    ReplyDelete
  7. Great site and a great topic as well i really get amazed to read this. Its really good. business

    ReplyDelete
  8. Thanks for your article. One other thing is that if you are disposing your property by yourself, one of the difficulties you need to be conscious of upfront is how to deal with household inspection reviews. As a FSBO vendor, the key concerning successfully moving your property plus saving money about real estate agent commissions is understanding. The more you recognize, the better your property sales effort will be. One area in which this is particularly essential is inspection reports. 토토커뮤니티

    ReplyDelete
  9. Profit primarily prime quality items -- you can understand them all within: 먹튀검증사이트

    ReplyDelete
  10. It is somewhat fantastic, and yet check out the advice at this treat. 먹튀검증사이트

    ReplyDelete
  11. I read this article. I think You put a great deal of exertion to make this article. I like your work. 토토커뮤니티

    ReplyDelete