Saturday, August 05, 2006

Execute DDL statement from file

I was thinking the other day that I have written so many little utilities that I imagine many PL/SQL developers would appreciate. So I am going to post them occasionally on this blog, in the hopes that that code I wrote will be more widely used.

The exec_ddl_from_file program will execute the contents of your file as a DDL statement. This means that you may not use any bind variables, nor may you return information from the statement that is executed dynamically. But you can use this program to read in a file (using UTL_FILE) that contains, say, the CREATE OR REPLACE PACKAGE definition of a package, and create that package. Hopefully you will find such a utility handy, but I wrote it mostly to demonstrate how you can use DBMS_SQL.PARSE to execute arbitrarily large dynamic SQL strings. EXECUTE IMMEDIATE of Native Dynamic SQL fame is limited to 32K characters. Not so with DBMS_SQL. So here are the files in the download:

exec_ddl_from_file.sql - creates a procedure that executes the contents of a file. You will need to have UTL_FILE configured to get this program to run properly.

exec_ddl_from_file2.sql - creates a procedure that executes the contents of a file and includes the logic required to verify that you are indeed running under invoker rights.You will need to have UTL_FILE configured to get this program to run properly.

invdefinv.sql - a script that demonstrates how when a definer rights program calls an invoker rights program, the current user for that invoker rights program is set to the owner of the definer rights program. It also shows the usefulness of the DBMS_UTILITY.FORMAT_CALL_STACK, which reveals the PL/SQL call stack.

1 comment:

CleverIdea said...

I always hating using utl_file. So I developed a different method for doing the a similar task.

Download CleverIdeasForOracle ( http://sourceforge.net/projects/plcodebrew ) and see the method: cio_clob.execute_plsql

You feed it with a clob, but you can easily convert any url into a clob via the built-in type HttpUriType

In this way the whole Internet is your file system (or just your itty bitty intranet) and you can skip the utl_file mumbo jumbo.

Check it out if you get the chance.