views:

952

answers:

3

how will you take only stored procedure backup in oracle 10g?

A: 

Tools like TOAD offer a feature to export the source code of stored procedures, functions, packages, triggers etc.

If you don't mind exporting table structure (without content) as well,

exp user/password file=emptybackup.dmp owner=myschema rows=n

should do the trick.

ammoQ
+2  A: 

ammoQ's answer is correct.

To take it a bit further, if you want just the stored procs without the table structure, you will need to connect to the database and use SQL (i.e. with sqlplus or something). Then, using a list of the stored procs you are interested in, call the dbms_metadata function. You can use sqlplus to do something like this:

SELECT dbms_metadata.get_ddl('PROCEDURE','PROC1') FROM dual;

which will give you the source of procedure PROC1.

Also there is a view called USER_SOURCE, which you can use something like this:

select * from user_source where type in ('PROCEDURE', 'PACKAGE', 'PACKAGE_BODY', 'FUNCTION', 'TRIGGER');

which gives you the source for everything owned by the user you are logged in as.

Colin Pickard
+1  A: 

If you're not taking care of configuration management, i.e. not keeping your stored procedures in a proper source control application (e.g. CVS, Subversion, MSS) you're simply not doing the right thing. Even a one-man team should use a version control system, for any non-trivial work.

Read up on Revision control

Andrew from NZSG
This is true, but it's not nessecarily relevant - what if the asker is not creating the source? he might want to dump the source for auditing, for backup, or even just to read on a long winter evening
Colin Pickard
btw, the upvote was mine, not the downvote. I think maybe it should be a comment not a answer but it didn't deserve -1, since you can't stress too much the importance of source control.
Colin Pickard
Maybe it's just miscommunication... "Backup" and "export"/ have very different connotations to me. Exporting is just a generic term, but backup by definition implies saving something to cope with system failures. You wouldn't do a "backup" to perform auditing or for casual reading, you would "export"/"dump"/"extract"...
Andrew from NZSG
yeah, submitter's wording doesn't look like native english. Also just could you say backup, you might be trying to simplfy what you are really after.... best to genericise everything i find. And use source control :)
Colin Pickard