Oracle - How to generate script from sql developer

后端 未结 10 492
臣服心动
臣服心动 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'.

    0 讨论(0)
  • 2020-12-07 21:17

    Oracle SQL Developer > View > DBA > Select your connection > Expand > Security > Users > Right click your user > Create like > Fill in fields > Copy SQL script > Close

    If your user has object privileges, do this also

    Oracle SQL Developer > View > DBA > Select your connection > Expand > Security > Users > Double click your user > Object Privs > Select all data > Right click > Export > Export as text file

    Edit that text file to grant object privileges to your user.

    0 讨论(0)
  • 2020-12-07 21:18

    SQL Developer -> Tools -> Database Export...

    0 讨论(0)
  • 2020-12-07 21:20

    I did not know about DMBS_METADATA, but your answers prompted me to create a utility to script all objects owned by an Oracle user.

    0 讨论(0)
提交回复
热议问题