I have to create some scripts to create a new and empty DB ready for a new install of our apps on a new server.
I am easily getting the tables, views etc info from SQL Developers Export facility (without the data of course), but I have a problem where I need to define the userid and the TableSpace.
I realise these are quite straight forward, but what I would like to know is how the original ones are defined on our current DB, as the original scripts (and info) are no longer available, and I need to make sure I create them correctly with the new scripts.
So how do I display all the required info for a userid and for a TableSpace so that I can use this info in the create commands in the scripts ?
It may be helpful for you to know this is my first attempt at scripting and only my 2nd attempt at and interfacing with Oracle, so I have limited knowledge in this field, hence the simple request. 🙂
Any help or advice would be most appreciated.
Cheers, George.
Best Answer
Have a look at the
DBMS_METADATA
package. First setlong
to some big number so the output isn't truncated, and set the SQL terminator so you can see how statements are separated:To get the tablespace (substitute your own for
USERS
of course):You'll probably need to modify the datafile path for the new server. To get the user:
Then you need the grants the user has. Depending on your actual user some of these may not return anything:
You can use the same functions to get your table and view scripts if you prefer - I believe SQL Developer's export uses them under the hood anyway - and to get role definitions and grants.