Updated 6 May 2022
You’re using ORDS.
You’ve written some web services AKA REST APIs.
Now you need to control the underlying PL/SQL source.
How do I get the code out?
There’s a few ways.
0. Use SQL Developer Web
Proceed to the REST Workshop and your list of Modules.
It’ll include required roles and privileges…
You can then copy that to the clipboard or download it as a file.
1. Use SQL Developer
On the Module, mouse right click.
2. Use SQLcl
The REST command will get what you want.
If you want this in a file, just use the SPOOL command.
3. Get it Yourself with SQL
The ORDS_METADATA schema comes with some PL/SQL packages for managing your web services. One of those is named ‘ORDS_EXPORT’ – one guess what this does 🙂
set long 5000 set pagesize 1000 select ORDS_METADATA.ords_export.export_module(p_module_name=>'ora_magazine') from dual;
Which comes out looking pretty familiar…
If you look at the package.function, you’ll notice it’s overloaded – you can also pass a couple of BOOLEANs to determine if you want the code to ENABLE the schema or if you want the associated PRIVILEGES included.
You see these same options when using the GUI and saying export to file.
There’s another function available in this schema – EXPORT_SCHEMA. You can also guess what this does. It also has two booleans, for saying if you want the schema enablement and privs included in the output.
SELECT ords_metadata.ords_export.export_schema() FROM dual;
If you’re looking for a package call to export ALL of the RESTful Services in your entire database, then we’re looking to update our ORDS_ADMIN package to allow that. Stay tune!
4. Via REST Development
If you use this panel, you can export all of your MODULES to an archive (ZIP) of XML files that which can then be uploaded to another ORDS server if you want. I wouldn’t recommend using this method unless you only have REST access to ORDS, or in other words, no DATABASE access where the REST services are defined.