Oracle - How to generate script from sql developer

后端 未结 10 534
臣服心动
臣服心动 2020-12-07 20:13

How to take script for schema of the tables, stored procedures of Oracle through SQL Developer tool (SQLPLUS command line interface)?

10条回答
  •  隐瞒了意图╮
    2020-12-07 21:12

    The basic answer appears to be 'use the dbms_metadata package'. The axuilliary question is:

    But what if I want to generate a script for all the tables at a time?

    And the answer, presumably, is to interrogate the system catalog for the names and owners of all the tables:

    SELECT dbms_metadata.get_ddl('TABLE', s.tabname, s.tabowner)
      FROM system_catalog_describing_tables AS s
     WHERE ...any conditions that are needed...
    

    I'm not sufficiently familiar with Oracle to know the system catalog. In Informix, which I do know, assuming that there was a procedure dbms_metadata.get_ddl, the query would be:

    SELECT dbms_metadata.get_ddl('TABLE', s.tabname, s.owner)
      FROM "informix".systables AS s
     WHERE tabid >= 100 AND tabtype = 'T';
    

    In Informix, tabids less than 100 are reserved for the system catalog, and non-tables (views, synonyms, sequences and a few other esoteric things) are excluded by requiring the right 'tabtype'.

提交回复
热议问题