问题
I need to make some changes to an old Oracle stored procedure on an obsolete box that is being kept around to run an old legacy process. The only tool I can connect to the db with is SQLPlus. How do I load a stored proc into memory for editing in SQLPlus?
The tutorials I've found on-line don't exlain how that's done. :-(
回答1:
It would be a lot easier to download the trial version of TOAD
scratch that previous suggestion, I just tried out the Oracle SQL Developer link suggested and it works peachy fine for editing procs.
for SQLPlus you pretty much need to display the contents of the stored proc, and spool it to a file (as suggested by DCookie :-)) :
sqlplus> spool myprocname.sql;
sqlplus> select text from all_source where name = 'MYPROCNAME' and type = 'PROCEDURE' order by line;
sqlplus> quit;
then edit the local SQL file in a decent editor.
Then use SQLPlus to run the SQL file to re-build the proc for testing.
>sqlplus username/password@tnsnamesentry @myproc.sql
In short, a massive pain in the keester. :-)
回答2:
You can use dbms_metadata.get_ddl
function to retrieve code, it is much better then all_sources.
spool /tmp/my_proc.txt
set long 100000
select dbms_metadata.get_ddl('PROCEDURE','NAME','OWNER') from dual;
spool off
回答3:
If you can connect to the db using SQL*Plus, you should be able to connect using a SQL IDE. That said, you cannot open a proc for edit in SQL*Plus, but you can compile one. You can copy your updated proc into the command prompt (line by line if necessary) and compile it.
If you need to access the current source in the manual fashion, you can query the USER_SOURCE table.
I strongly suggest, however, looking into connecting to the DB with an IDE.
回答4:
The box is HPUX with no TNS listener running which pretty much wipes out the entire fleet of dev tools. However, the DBA was able to connect using an admin tool called OEM and make the necissary changes. Thanks all for your suggestions.
回答5:
Can you not download and install Oracle SQL Developer? It's free.
For Unix, there's TOra, (open source)
来源:https://stackoverflow.com/questions/1065575/how-do-i-open-a-stored-procedure-and-edit-it-in-sqlplus